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
19 * @author Daniel Kinzler
27 class TitleValueTest
extends \MediaWikiUnitTestCase
{
29 public function goodConstructorProvider() {
31 [ NS_MAIN
, '', 'fragment', '', true, false ],
32 [ NS_MAIN
, '', '', 'interwiki', false, true ],
33 [ NS_MAIN
, '', 'fragment', 'interwiki', true, true ],
34 [ NS_USER
, 'TestThis', 'stuff', '', true, false ],
35 [ NS_USER
, 'TestThis', '', 'baz', false, true ],
36 [ NS_MAIN
, 'foo bar', '', '', false, false ],
37 [ NS_MAIN
, 'foo_bar', '', '', false, false ],
42 * @dataProvider goodConstructorProvider
44 public function testConstruction( $ns, $text, $fragment, $interwiki, $hasFragment,
47 $title = new TitleValue( $ns, $text, $fragment, $interwiki );
49 $this->assertEquals( $ns, $title->getNamespace() );
50 $this->assertTrue( $title->inNamespace( $ns ) );
51 $this->assertEquals( strtr( $text, ' ', '_' ), $title->getDbKey() );
52 $this->assertEquals( strtr( $text, '_', ' ' ), $title->getText() );
53 $this->assertEquals( $fragment, $title->getFragment() );
54 $this->assertEquals( $hasFragment, $title->hasFragment() );
55 $this->assertEquals( $interwiki, $title->getInterwiki() );
56 $this->assertEquals( $hasInterwiki, $title->isExternal() );
59 public function badConstructorProvider() {
61 [ 'foo', 'title', 'fragment', '' ],
62 [ null, 'title', 'fragment', '' ],
63 [ 2.3, 'title', 'fragment', '' ],
65 [ NS_MAIN
, 5, 'fragment', '' ],
66 [ NS_MAIN
, null, 'fragment', '' ],
67 [ NS_USER
, '', 'fragment', '' ],
68 [ NS_USER
, '', '', 'interwiki' ],
69 [ NS_MAIN
, 'bar_', '', '' ],
70 [ NS_MAIN
, '_foo', '', '' ],
71 [ NS_MAIN
, ' eek ', '', '' ],
73 [ NS_MAIN
, 'title', 5, '' ],
74 [ NS_MAIN
, 'title', null, '' ],
75 [ NS_MAIN
, 'title', [], '' ],
77 [ NS_MAIN
, 'title', '', 5 ],
78 [ NS_MAIN
, 'title', null, 5 ],
79 [ NS_MAIN
, 'title', [], 5 ],
84 * @dataProvider badConstructorProvider
86 public function testConstructionErrors( $ns, $text, $fragment, $interwiki ) {
87 $this->setExpectedException( InvalidArgumentException
::class );
88 new TitleValue( $ns, $text, $fragment, $interwiki );
91 public function fragmentTitleProvider() {
93 [ new TitleValue( NS_MAIN
, 'Test' ), 'foo' ],
94 [ new TitleValue( NS_TALK
, 'Test', 'foo' ), '' ],
95 [ new TitleValue( NS_CATEGORY
, 'Test', 'foo' ), 'bar' ],
100 * @dataProvider fragmentTitleProvider
102 public function testCreateFragmentTitle( TitleValue
$title, $fragment ) {
103 $fragmentTitle = $title->createFragmentTarget( $fragment );
105 $this->assertEquals( $title->getNamespace(), $fragmentTitle->getNamespace() );
106 $this->assertEquals( $title->getText(), $fragmentTitle->getText() );
107 $this->assertEquals( $fragment, $fragmentTitle->getFragment() );
110 public function getTextProvider() {
113 [ 'Foo_Bar', 'Foo Bar' ],
118 * @dataProvider getTextProvider
120 public function testGetText( $dbkey, $text ) {
121 $title = new TitleValue( NS_MAIN
, $dbkey );
123 $this->assertEquals( $text, $title->getText() );
126 public function provideTestToString() {
128 new TitleValue( 0, 'Foo' ),
132 new TitleValue( 1, 'Bar_Baz' ),
136 new TitleValue( 9, 'JoJo', 'Frag' ),
140 new TitleValue( 200, 'tea', 'Fragment', 'wikicode' ),
141 'wikicode:200:tea#Fragment'
146 * @dataProvider provideTestToString
148 public function testToString( TitleValue
$value, $expected ) {