Merge "Added release notes for 'ContentHandler::runLegacyHooks' removal"
[mediawiki.git] / tests / phpunit / includes / title / TitleValueTest.php
blob4dbda74ae0f827b67ca95e6142a8507244620df4
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
18 * @file
19 * @author Daniel Kinzler
22 /**
23 * @covers TitleValue
25 * @group Title
27 class TitleValueTest extends MediaWikiTestCase {
29 public function goodConstructorProvider() {
30 return [
31 [ NS_USER, 'TestThis', 'stuff', '', true, false ],
32 [ NS_USER, 'TestThis', '', 'baz', false, true ],
36 /**
37 * @dataProvider goodConstructorProvider
39 public function testConstruction( $ns, $text, $fragment, $interwiki, $hasFragment,
40 $hasInterwiki
41 ) {
42 $title = new TitleValue( $ns, $text, $fragment, $interwiki );
44 $this->assertEquals( $ns, $title->getNamespace() );
45 $this->assertTrue( $title->inNamespace( $ns ) );
46 $this->assertEquals( $text, $title->getText() );
47 $this->assertEquals( $fragment, $title->getFragment() );
48 $this->assertEquals( $hasFragment, $title->hasFragment() );
49 $this->assertEquals( $interwiki, $title->getInterwiki() );
50 $this->assertEquals( $hasInterwiki, $title->isExternal() );
53 public function badConstructorProvider() {
54 return [
55 [ 'foo', 'title', 'fragment', '' ],
56 [ null, 'title', 'fragment', '' ],
57 [ 2.3, 'title', 'fragment', '' ],
59 [ NS_MAIN, 5, 'fragment', '' ],
60 [ NS_MAIN, null, 'fragment', '' ],
61 [ NS_MAIN, '', 'fragment', '' ],
62 [ NS_MAIN, 'foo bar', '', '' ],
63 [ NS_MAIN, 'bar_', '', '' ],
64 [ NS_MAIN, '_foo', '', '' ],
65 [ NS_MAIN, ' eek ', '', '' ],
67 [ NS_MAIN, 'title', 5, '' ],
68 [ NS_MAIN, 'title', null, '' ],
69 [ NS_MAIN, 'title', [], '' ],
71 [ NS_MAIN, 'title', '', 5 ],
72 [ NS_MAIN, 'title', null, 5 ],
73 [ NS_MAIN, 'title', [], 5 ],
77 /**
78 * @dataProvider badConstructorProvider
80 public function testConstructionErrors( $ns, $text, $fragment, $interwiki ) {
81 $this->setExpectedException( 'InvalidArgumentException' );
82 new TitleValue( $ns, $text, $fragment, $interwiki );
85 public function fragmentTitleProvider() {
86 return [
87 [ new TitleValue( NS_MAIN, 'Test' ), 'foo' ],
88 [ new TitleValue( NS_TALK, 'Test', 'foo' ), '' ],
89 [ new TitleValue( NS_CATEGORY, 'Test', 'foo' ), 'bar' ],
93 /**
94 * @dataProvider fragmentTitleProvider
96 public function testCreateFragmentTitle( TitleValue $title, $fragment ) {
97 $fragmentTitle = $title->createFragmentTarget( $fragment );
99 $this->assertEquals( $title->getNamespace(), $fragmentTitle->getNamespace() );
100 $this->assertEquals( $title->getText(), $fragmentTitle->getText() );
101 $this->assertEquals( $fragment, $fragmentTitle->getFragment() );
104 public function getTextProvider() {
105 return [
106 [ 'Foo', 'Foo' ],
107 [ 'Foo_Bar', 'Foo Bar' ],
112 * @dataProvider getTextProvider
114 public function testGetText( $dbkey, $text ) {
115 $title = new TitleValue( NS_MAIN, $dbkey );
117 $this->assertEquals( $text, $title->getText() );