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 MediaWikiTestCase
{
29 public function goodConstructorProvider() {
31 [ NS_USER
, 'TestThis', 'stuff', true ],
32 [ NS_USER
, 'TestThis', '', false ],
37 * @dataProvider goodConstructorProvider
39 public function testConstruction( $ns, $text, $fragment, $hasFragment ) {
40 $title = new TitleValue( $ns, $text, $fragment );
42 $this->assertEquals( $ns, $title->getNamespace() );
43 $this->assertEquals( $text, $title->getText() );
44 $this->assertEquals( $fragment, $title->getFragment() );
45 $this->assertEquals( $hasFragment, $title->hasFragment() );
48 public function badConstructorProvider() {
50 [ 'foo', 'title', 'fragment' ],
51 [ null, 'title', 'fragment' ],
52 [ 2.3, 'title', 'fragment' ],
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 ', '' ],
62 [ NS_MAIN
, 'title', 5 ],
63 [ NS_MAIN
, 'title', null ],
64 [ NS_MAIN
, 'title', [] ],
69 * @dataProvider badConstructorProvider
71 public function testConstructionErrors( $ns, $text, $fragment ) {
72 $this->setExpectedException( 'InvalidArgumentException' );
73 new TitleValue( $ns, $text, $fragment );
76 public function fragmentTitleProvider() {
78 [ new TitleValue( NS_MAIN
, 'Test' ), 'foo' ],
79 [ new TitleValue( NS_TALK
, 'Test', 'foo' ), '' ],
80 [ new TitleValue( NS_CATEGORY
, 'Test', 'foo' ), 'bar' ],
85 * @dataProvider fragmentTitleProvider
87 public function testCreateFragmentTitle( TitleValue
$title, $fragment ) {
88 $fragmentTitle = $title->createFragmentTarget( $fragment );
90 $this->assertEquals( $title->getNamespace(), $fragmentTitle->getNamespace() );
91 $this->assertEquals( $title->getText(), $fragmentTitle->getText() );
92 $this->assertEquals( $fragment, $fragmentTitle->getFragment() );
95 public function getTextProvider() {
98 [ 'Foo_Bar', 'Foo Bar' ],
103 * @dataProvider getTextProvider
105 public function testGetText( $dbkey, $text ) {
106 $title = new TitleValue( NS_MAIN
, $dbkey );
108 $this->assertEquals( $text, $title->getText() );