Merge "Update default hash storage settings"
[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, false ],
32 [ NS_USER, 'TestThis', '', 'baz', false, true ],
33 ];
34 }
35
36 /**
37 * @dataProvider goodConstructorProvider
38 */
39 public function testConstruction( $ns, $text, $fragment, $interwiki, $hasFragment,
40 $hasInterwiki
41 ) {
42 $title = new TitleValue( $ns, $text, $fragment, $interwiki );
43
44 $this->assertEquals( $ns, $title->getNamespace() );
45 $this->assertEquals( $text, $title->getText() );
46 $this->assertEquals( $fragment, $title->getFragment() );
47 $this->assertEquals( $hasFragment, $title->hasFragment() );
48 $this->assertEquals( $interwiki, $title->getInterwiki() );
49 $this->assertEquals( $hasInterwiki, $title->isExternal() );
50 }
51
52 public function badConstructorProvider() {
53 return [
54 [ 'foo', 'title', 'fragment', '' ],
55 [ null, 'title', 'fragment', '' ],
56 [ 2.3, 'title', 'fragment', '' ],
57
58 [ NS_MAIN, 5, 'fragment', '' ],
59 [ NS_MAIN, null, 'fragment', '' ],
60 [ NS_MAIN, '', 'fragment', '' ],
61 [ NS_MAIN, 'foo bar', '', '' ],
62 [ NS_MAIN, 'bar_', '', '' ],
63 [ NS_MAIN, '_foo', '', '' ],
64 [ NS_MAIN, ' eek ', '', '' ],
65
66 [ NS_MAIN, 'title', 5, '' ],
67 [ NS_MAIN, 'title', null, '' ],
68 [ NS_MAIN, 'title', [], '' ],
69
70 [ NS_MAIN, 'title', '', 5 ],
71 [ NS_MAIN, 'title', null, 5 ],
72 [ NS_MAIN, 'title', [], 5 ],
73 ];
74 }
75
76 /**
77 * @dataProvider badConstructorProvider
78 */
79 public function testConstructionErrors( $ns, $text, $fragment, $interwiki ) {
80 $this->setExpectedException( 'InvalidArgumentException' );
81 new TitleValue( $ns, $text, $fragment, $interwiki );
82 }
83
84 public function fragmentTitleProvider() {
85 return [
86 [ new TitleValue( NS_MAIN, 'Test' ), 'foo' ],
87 [ new TitleValue( NS_TALK, 'Test', 'foo' ), '' ],
88 [ new TitleValue( NS_CATEGORY, 'Test', 'foo' ), 'bar' ],
89 ];
90 }
91
92 /**
93 * @dataProvider fragmentTitleProvider
94 */
95 public function testCreateFragmentTitle( TitleValue $title, $fragment ) {
96 $fragmentTitle = $title->createFragmentTarget( $fragment );
97
98 $this->assertEquals( $title->getNamespace(), $fragmentTitle->getNamespace() );
99 $this->assertEquals( $title->getText(), $fragmentTitle->getText() );
100 $this->assertEquals( $fragment, $fragmentTitle->getFragment() );
101 }
102
103 public function getTextProvider() {
104 return [
105 [ 'Foo', 'Foo' ],
106 [ 'Foo_Bar', 'Foo Bar' ],
107 ];
108 }
109
110 /**
111 * @dataProvider getTextProvider
112 */
113 public function testGetText( $dbkey, $text ) {
114 $title = new TitleValue( NS_MAIN, $dbkey );
115
116 $this->assertEquals( $text, $title->getText() );
117 }
118 }