MediaWiki  REL1_24
TitleValueTest.php
Go to the documentation of this file.
00001 <?php
00028 class TitleValueTest extends MediaWikiTestCase {
00029 
00030     public function testConstruction() {
00031         $title = new TitleValue( NS_USER, 'TestThis', 'stuff' );
00032 
00033         $this->assertEquals( NS_USER, $title->getNamespace() );
00034         $this->assertEquals( 'TestThis', $title->getText() );
00035         $this->assertEquals( 'stuff', $title->getFragment() );
00036     }
00037 
00038     public function badConstructorProvider() {
00039         return array(
00040             array( 'foo', 'title', 'fragment' ),
00041             array( null, 'title', 'fragment' ),
00042             array( 2.3, 'title', 'fragment' ),
00043 
00044             array( NS_MAIN, 5, 'fragment' ),
00045             array( NS_MAIN, null, 'fragment' ),
00046             array( NS_MAIN, '', 'fragment' ),
00047             array( NS_MAIN, 'foo bar', '' ),
00048             array( NS_MAIN, 'bar_', '' ),
00049             array( NS_MAIN, '_foo', '' ),
00050             array( NS_MAIN, ' eek ', '' ),
00051 
00052             array( NS_MAIN, 'title', 5 ),
00053             array( NS_MAIN, 'title', null ),
00054             array( NS_MAIN, 'title', array() ),
00055         );
00056     }
00057 
00061     public function testConstructionErrors( $ns, $text, $fragment ) {
00062         $this->setExpectedException( 'InvalidArgumentException' );
00063         new TitleValue( $ns, $text, $fragment );
00064     }
00065 
00066     public function fragmentTitleProvider() {
00067         return array(
00068             array( new TitleValue( NS_MAIN, 'Test' ), 'foo' ),
00069             array( new TitleValue( NS_TALK, 'Test', 'foo' ), '' ),
00070             array( new TitleValue( NS_CATEGORY, 'Test', 'foo' ), 'bar' ),
00071         );
00072     }
00073 
00077     public function testCreateFragmentTitle( TitleValue $title, $fragment ) {
00078         $fragmentTitle = $title->createFragmentTitle( $fragment );
00079 
00080         $this->assertEquals( $title->getNamespace(), $fragmentTitle->getNamespace() );
00081         $this->assertEquals( $title->getText(), $fragmentTitle->getText() );
00082         $this->assertEquals( $fragment, $fragmentTitle->getFragment() );
00083     }
00084 
00085     public function getTextProvider() {
00086         return array(
00087             array( 'Foo', 'Foo' ),
00088             array( 'Foo_Bar', 'Foo Bar' ),
00089         );
00090     }
00091 
00095     public function testGetText( $dbkey, $text ) {
00096         $title = new TitleValue( NS_MAIN, $dbkey );
00097 
00098         $this->assertEquals( $text, $title->getText() );
00099     }
00100 }