MediaWiki
REL1_19
|
00001 <?php 00002 00003 class TitleMethodsTest extends MediaWikiTestCase { 00004 00005 public function dataEquals() { 00006 return array( 00007 array( 'Main Page', 'Main Page', true ), 00008 array( 'Main Page', 'Not The Main Page', false ), 00009 array( 'Main Page', 'Project:Main Page', false ), 00010 array( 'File:Example.png', 'Image:Example.png', true ), 00011 array( 'Special:Version', 'Special:Version', true ), 00012 array( 'Special:Version', 'Special:Recentchanges', false ), 00013 array( 'Special:Version', 'Main Page', false ), 00014 ); 00015 } 00016 00020 public function testEquals( $titleA, $titleB, $expectedBool ) { 00021 $titleA = Title::newFromText( $titleA ); 00022 $titleB = Title::newFromText( $titleB ); 00023 00024 $this->assertEquals( $titleA->equals( $titleB ), $expectedBool ); 00025 $this->assertEquals( $titleB->equals( $titleA ), $expectedBool ); 00026 } 00027 00028 public function dataInNamespace() { 00029 return array( 00030 array( 'Main Page', NS_MAIN, true ), 00031 array( 'Main Page', NS_TALK, false ), 00032 array( 'Main Page', NS_USER, false ), 00033 array( 'User:Foo', NS_USER, true ), 00034 array( 'User:Foo', NS_USER_TALK, false ), 00035 array( 'User:Foo', NS_TEMPLATE, false ), 00036 array( 'User_talk:Foo', NS_USER_TALK, true ), 00037 array( 'User_talk:Foo', NS_USER, false ), 00038 ); 00039 } 00040 00044 public function testInNamespace( $title, $ns, $expectedBool ) { 00045 $title = Title::newFromText( $title ); 00046 $this->assertEquals( $title->inNamespace( $ns ), $expectedBool ); 00047 } 00048 00049 public function testInNamespaces() { 00050 $mainpage = Title::newFromText( 'Main Page' ); 00051 $this->assertTrue( $mainpage->inNamespaces( NS_MAIN, NS_USER ) ); 00052 $this->assertTrue( $mainpage->inNamespaces( array( NS_MAIN, NS_USER ) ) ); 00053 $this->assertTrue( $mainpage->inNamespaces( array( NS_USER, NS_MAIN ) ) ); 00054 $this->assertFalse( $mainpage->inNamespaces( array( NS_PROJECT, NS_TEMPLATE ) ) ); 00055 } 00056 00057 public function dataHasSubjectNamespace() { 00058 return array( 00059 array( 'Main Page', NS_MAIN, true ), 00060 array( 'Main Page', NS_TALK, true ), 00061 array( 'Main Page', NS_USER, false ), 00062 array( 'User:Foo', NS_USER, true ), 00063 array( 'User:Foo', NS_USER_TALK, true ), 00064 array( 'User:Foo', NS_TEMPLATE, false ), 00065 array( 'User_talk:Foo', NS_USER_TALK, true ), 00066 array( 'User_talk:Foo', NS_USER, true ), 00067 ); 00068 } 00069 00073 public function testHasSubjectNamespace( $title, $ns, $expectedBool ) { 00074 $title = Title::newFromText( $title ); 00075 $this->assertEquals( $title->hasSubjectNamespace( $ns ), $expectedBool ); 00076 } 00077 00078 }