X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FTitleTest.php;h=d12e4b864380272b6c84da1e3c427ac96bbc363e;hp=c06a2e4f1c9879ec11edbf73a8b0e8740f2f87ad;hb=0c77841534d9139b0042696fe015a15d3e349ef5;hpb=7471e1db1b613d035f981f489f8683a177acff7e diff --git a/tests/phpunit/includes/TitleTest.php b/tests/phpunit/includes/TitleTest.php index c06a2e4f1c..d12e4b8643 100644 --- a/tests/phpunit/includes/TitleTest.php +++ b/tests/phpunit/includes/TitleTest.php @@ -282,7 +282,6 @@ class TitleTest extends MediaWikiTestCase { /** * Auth-less test of Title::isValidMoveOperation * - * @group Database * @param string $source * @param string $target * @param array|string|bool $expected Required error @@ -553,6 +552,7 @@ class TitleTest extends MediaWikiTestCase { } /** + * @covers Title::newFromTitleValue * @dataProvider provideNewFromTitleValue */ public function testNewFromTitleValue( TitleValue $value ) { @@ -573,6 +573,7 @@ class TitleTest extends MediaWikiTestCase { } /** + * @covers Title::getTitleValue * @dataProvider provideGetTitleValue */ public function testGetTitleValue( $text ) { @@ -604,6 +605,7 @@ class TitleTest extends MediaWikiTestCase { } /** + * @covers Title::getFragment * @dataProvider provideGetFragment * * @param string $full @@ -637,6 +639,28 @@ class TitleTest extends MediaWikiTestCase { ]; } + /** + * @covers Title::isValid + * @dataProvider provideIsValid + * @param Title $title + * @param bool $isValid + */ + public function testIsValid( Title $title, $isValid ) { + $this->assertEquals( $isValid, $title->isValid(), $title->getPrefixedText() ); + } + + public static function provideIsValid() { + return [ + [ Title::makeTitle( NS_MAIN, '' ), false ], + [ Title::makeTitle( NS_MAIN, '<>' ), false ], + [ Title::makeTitle( NS_MAIN, '|' ), false ], + [ Title::makeTitle( NS_MAIN, '#' ), false ], + [ Title::makeTitle( NS_MAIN, 'Test' ), true ], + [ Title::makeTitle( -33, 'Test' ), false ], + [ Title::makeTitle( 77663399, 'Test' ), false ], + ]; + } + /** * @covers Title::isAlwaysKnown */ @@ -716,6 +740,58 @@ class TitleTest extends MediaWikiTestCase { $this->assertSame( $expected, $actual, $title->getPrefixedDBkey() ); } + public static function provideGetTalkPage_good() { + return [ + [ Title::makeTitle( NS_MAIN, 'Test' ), Title::makeTitle( NS_TALK, 'Test' ) ], + [ Title::makeTitle( NS_TALK, 'Test' ), Title::makeTitle( NS_TALK, 'Test' ) ], + ]; + } + + /** + * @dataProvider provideGetTalkPage_good + * @covers Title::getTalkPage + */ + public function testGetTalkPage_good( Title $title, Title $expected ) { + $talk = $title->getTalkPage(); + $this->assertSame( + $expected->getPrefixedDBKey(), + $talk->getPrefixedDBKey(), + $title->getPrefixedDBKey() + ); + } + + /** + * @dataProvider provideGetTalkPage_good + * @covers Title::getTalkPageIfDefined + */ + public function testGetTalkPageIfDefined_good( Title $title ) { + $talk = $title->getTalkPageIfDefined(); + $this->assertInstanceOf( + Title::class, + $talk, + $title->getPrefixedDBKey() + ); + } + + public static function provideGetTalkPage_bad() { + return [ + [ Title::makeTitle( NS_SPECIAL, 'Test' ) ], + [ Title::makeTitle( NS_MEDIA, 'Test' ) ], + ]; + } + + /** + * @dataProvider provideGetTalkPage_bad + * @covers Title::getTalkPageIfDefined + */ + public function testGetTalkPageIfDefined_bad( Title $title ) { + $talk = $title->getTalkPageIfDefined(); + $this->assertNull( + $talk, + $title->getPrefixedDBKey() + ); + } + public function provideCreateFragmentTitle() { return [ [ Title::makeTitle( NS_MAIN, 'Test' ), 'foo' ], @@ -838,4 +914,55 @@ class TitleTest extends MediaWikiTestCase { public function testGetPrefixedDBKey( Title $title, $expected ) { $this->assertEquals( $expected, $title->getPrefixedDBkey() ); } + + /** + * @covers Title::getFragmentForURL + * @dataProvider provideGetFragmentForURL + * + * @param string $titleStr + * @param string $expected + */ + public function testGetFragmentForURL( $titleStr, $expected ) { + $this->setMwGlobals( [ + 'wgFragmentMode' => [ 'html5' ], + 'wgExternalInterwikiFragmentMode' => 'legacy', + ] ); + $dbw = wfGetDB( DB_MASTER ); + $dbw->insert( 'interwiki', + [ + [ + 'iw_prefix' => 'de', + 'iw_url' => 'http://de.wikipedia.org/wiki/', + 'iw_api' => 'http://de.wikipedia.org/w/api.php', + 'iw_wikiid' => 'dewiki', + 'iw_local' => 1, + 'iw_trans' => 0, + ], + [ + 'iw_prefix' => 'zz', + 'iw_url' => 'http://zzwiki.org/wiki/', + 'iw_api' => 'http://zzwiki.org/w/api.php', + 'iw_wikiid' => 'zzwiki', + 'iw_local' => 0, + 'iw_trans' => 0, + ], + ], + __METHOD__, + [ 'IGNORE' ] + ); + + $title = Title::newFromText( $titleStr ); + self::assertEquals( $expected, $title->getFragmentForURL() ); + + $dbw->delete( 'interwiki', '*', __METHOD__ ); + } + + public function provideGetFragmentForURL() { + return [ + [ 'Foo', '' ], + [ 'Foo#ümlåût', '#ümlåût' ], + [ 'de:Foo#Bå®', '#Bå®' ], + [ 'zz:Foo#тест', '#.D1.82.D0.B5.D1.81.D1.82' ], + ]; + } }