Merge "Revert "Deprecating: Consolidating `progressive` & `constructive` buttons""
[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 testConstruction() {
30 $title = new TitleValue( NS_USER, 'TestThis', 'stuff' );
31
32 $this->assertEquals( NS_USER, $title->getNamespace() );
33 $this->assertEquals( 'TestThis', $title->getText() );
34 $this->assertEquals( 'stuff', $title->getFragment() );
35 }
36
37 public function badConstructorProvider() {
38 return [
39 [ 'foo', 'title', 'fragment' ],
40 [ null, 'title', 'fragment' ],
41 [ 2.3, 'title', 'fragment' ],
42
43 [ NS_MAIN, 5, 'fragment' ],
44 [ NS_MAIN, null, 'fragment' ],
45 [ NS_MAIN, '', 'fragment' ],
46 [ NS_MAIN, 'foo bar', '' ],
47 [ NS_MAIN, 'bar_', '' ],
48 [ NS_MAIN, '_foo', '' ],
49 [ NS_MAIN, ' eek ', '' ],
50
51 [ NS_MAIN, 'title', 5 ],
52 [ NS_MAIN, 'title', null ],
53 [ NS_MAIN, 'title', [] ],
54 ];
55 }
56
57 /**
58 * @dataProvider badConstructorProvider
59 */
60 public function testConstructionErrors( $ns, $text, $fragment ) {
61 $this->setExpectedException( 'InvalidArgumentException' );
62 new TitleValue( $ns, $text, $fragment );
63 }
64
65 public function fragmentTitleProvider() {
66 return [
67 [ new TitleValue( NS_MAIN, 'Test' ), 'foo' ],
68 [ new TitleValue( NS_TALK, 'Test', 'foo' ), '' ],
69 [ new TitleValue( NS_CATEGORY, 'Test', 'foo' ), 'bar' ],
70 ];
71 }
72
73 /**
74 * @dataProvider fragmentTitleProvider
75 */
76 public function testCreateFragmentTitle( TitleValue $title, $fragment ) {
77 $fragmentTitle = $title->createFragmentTitle( $fragment );
78
79 $this->assertEquals( $title->getNamespace(), $fragmentTitle->getNamespace() );
80 $this->assertEquals( $title->getText(), $fragmentTitle->getText() );
81 $this->assertEquals( $fragment, $fragmentTitle->getFragment() );
82 }
83
84 public function getTextProvider() {
85 return [
86 [ 'Foo', 'Foo' ],
87 [ 'Foo_Bar', 'Foo Bar' ],
88 ];
89 }
90
91 /**
92 * @dataProvider getTextProvider
93 */
94 public function testGetText( $dbkey, $text ) {
95 $title = new TitleValue( NS_MAIN, $dbkey );
96
97 $this->assertEquals( $text, $title->getText() );
98 }
99 }