Merge "TableDiffFormatter: Don't repeatedly call array_shift()"
[lhc/web/wiklou.git] / tests / phpunit / includes / title / TitleValueTest.php
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.
7 *
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.
12 *
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
17 *
18 * @file
19 * @author Daniel Kinzler
20 */
21
22 /**
23 * @covers TitleValue
24 *
25 * @group Title
26 */
27 class TitleValueTest extends MediaWikiTestCase {
28
29 public function goodConstructorProvider() {
30 return [
31 [ NS_USER, 'TestThis', 'stuff', true ],
32 [ NS_USER, 'TestThis', '', false ],
33 ];
34 }
35
36 /**
37 * @dataProvider goodConstructorProvider
38 */
39 public function testConstruction( $ns, $text, $fragment, $hasFragment ) {
40 $title = new TitleValue( $ns, $text, $fragment );
41
42 $this->assertEquals( $ns, $title->getNamespace() );
43 $this->assertEquals( $text, $title->getText() );
44 $this->assertEquals( $fragment, $title->getFragment() );
45 $this->assertEquals( $hasFragment, $title->hasFragment() );
46 }
47
48 public function badConstructorProvider() {
49 return [
50 [ 'foo', 'title', 'fragment' ],
51 [ null, 'title', 'fragment' ],
52 [ 2.3, 'title', 'fragment' ],
53
54 [ NS_MAIN, 5, 'fragment' ],
55 [ NS_MAIN, null, 'fragment' ],
56 [ NS_MAIN, '', 'fragment' ],
57 [ NS_MAIN, 'foo bar', '' ],
58 [ NS_MAIN, 'bar_', '' ],
59 [ NS_MAIN, '_foo', '' ],
60 [ NS_MAIN, ' eek ', '' ],
61
62 [ NS_MAIN, 'title', 5 ],
63 [ NS_MAIN, 'title', null ],
64 [ NS_MAIN, 'title', [] ],
65 ];
66 }
67
68 /**
69 * @dataProvider badConstructorProvider
70 */
71 public function testConstructionErrors( $ns, $text, $fragment ) {
72 $this->setExpectedException( 'InvalidArgumentException' );
73 new TitleValue( $ns, $text, $fragment );
74 }
75
76 public function fragmentTitleProvider() {
77 return [
78 [ new TitleValue( NS_MAIN, 'Test' ), 'foo' ],
79 [ new TitleValue( NS_TALK, 'Test', 'foo' ), '' ],
80 [ new TitleValue( NS_CATEGORY, 'Test', 'foo' ), 'bar' ],
81 ];
82 }
83
84 /**
85 * @dataProvider fragmentTitleProvider
86 */
87 public function testCreateFragmentTitle( TitleValue $title, $fragment ) {
88 $fragmentTitle = $title->createFragmentTitle( $fragment );
89
90 $this->assertEquals( $title->getNamespace(), $fragmentTitle->getNamespace() );
91 $this->assertEquals( $title->getText(), $fragmentTitle->getText() );
92 $this->assertEquals( $fragment, $fragmentTitle->getFragment() );
93 }
94
95 public function getTextProvider() {
96 return [
97 [ 'Foo', 'Foo' ],
98 [ 'Foo_Bar', 'Foo Bar' ],
99 ];
100 }
101
102 /**
103 * @dataProvider getTextProvider
104 */
105 public function testGetText( $dbkey, $text ) {
106 $title = new TitleValue( NS_MAIN, $dbkey );
107
108 $this->assertEquals( $text, $title->getText() );
109 }
110 }