Introducing TitleValue
[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 * @license GPL 2+
20 * @author Daniel Kinzler
21 */
22
23 /**
24 * @covers TitleValue
25 *
26 * @group Title
27 */
28 class TitleValueTest extends MediaWikiTestCase {
29
30 public function testConstruction() {
31 $title = new TitleValue( NS_USER, 'TestThis', 'stuff' );
32
33 $this->assertEquals( NS_USER, $title->getNamespace() );
34 $this->assertEquals( 'TestThis', $title->getText() );
35 $this->assertEquals( 'stuff', $title->getFragment() );
36 }
37
38 public function badConstructorProvider() {
39 return array(
40 array( 'foo', 'title', 'fragment' ),
41 array( null, 'title', 'fragment' ),
42 array( 2.3, 'title', 'fragment' ),
43
44 array( NS_MAIN, 5, 'fragment' ),
45 array( NS_MAIN, null, 'fragment' ),
46 array( NS_MAIN, '', 'fragment' ),
47 array( NS_MAIN, 'foo bar', '' ),
48 array( NS_MAIN, 'bar_', '' ),
49 array( NS_MAIN, '_foo', '' ),
50 array( NS_MAIN, ' eek ', '' ),
51
52 array( NS_MAIN, 'title', 5 ),
53 array( NS_MAIN, 'title', null ),
54 array( NS_MAIN, 'title', array() ),
55 );
56 }
57
58 /**
59 * @dataProvider badConstructorProvider
60 */
61 public function testConstructionErrors( $ns, $text, $fragment ) {
62 $this->setExpectedException( 'InvalidArgumentException' );
63 new TitleValue( $ns, $text, $fragment );
64 }
65
66 public function fragmentTitleProvider() {
67 return array(
68 array( new TitleValue( NS_MAIN, 'Test' ), 'foo' ),
69 array( new TitleValue( NS_TALK, 'Test', 'foo' ), '' ),
70 array( new TitleValue( NS_CATEGORY, 'Test', 'foo' ), 'bar' ),
71 );
72 }
73
74 /**
75 * @dataProvider fragmentTitleProvider
76 */
77 public function testCreateFragmentTitle( TitleValue $title, $fragment ) {
78 $fragmentTitle = $title->createFragmentTitle( $fragment );
79
80 $this->assertEquals( $title->getNamespace(), $fragmentTitle->getNamespace() );
81 $this->assertEquals( $title->getText(), $fragmentTitle->getText() );
82 $this->assertEquals( $fragment, $fragmentTitle->getFragment() );
83 }
84
85 public function getTextProvider() {
86 return array(
87 array( 'Foo', 'Foo' ),
88 array( 'Foo_Bar', 'Foo Bar' ),
89 );
90 }
91
92 /**
93 * @dataProvider getTextProvider
94 */
95 public function testGetText( $dbkey, $text ) {
96 $title = new TitleValue( NS_MAIN, $dbkey );
97
98 $this->assertEquals( $text, $title->getText() );
99 }
100 }