X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fskins%2FSideBarTest.php;h=af03fe6325eb9dc80958e1be9e94e4f32e330842;hb=294db5759d49606cd8b0939922b4ffb6b60b9a74;hp=7d33a59202e394100b487102822931adf23ccf26;hpb=57d3f41876599497fcb9c672b88ebad7239353dc;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/skins/SideBarTest.php b/tests/phpunit/skins/SideBarTest.php index 7d33a59202..af03fe6325 100644 --- a/tests/phpunit/skins/SideBarTest.php +++ b/tests/phpunit/skins/SideBarTest.php @@ -15,20 +15,27 @@ class SideBarTest extends MediaWikiLangTestCase { /** Build $this->messages array */ private function initMessagesHref() { - # List of default messages for the sidebar: - $URL_messages = array( + # List of default messages for the sidebar. The sidebar doesn't care at + # all whether they are full URLs, interwiki links or local titles. + $URL_messages = [ 'mainpage', 'portal-url', 'currentevents-url', 'recentchanges-url', 'randompage-url', 'helppage', - ); + ]; + # We're assuming that isValidURI works as advertised: it's also + # tested separately, in tests/phpunit/includes/HttpTest.php. foreach ( $URL_messages as $m ) { $titleName = MessageCache::singleton()->get( $m ); - $title = Title::newFromText( $titleName ); - $this->messages[$m]['href'] = $title->getLocalURL(); + if ( Http::isValidURI( $titleName ) ) { + $this->messages[$m]['href'] = $titleName; + } else { + $title = Title::newFromText( $titleName ); + $this->messages[$m]['href'] = $title->getLocalURL(); + } } } @@ -41,13 +48,13 @@ class SideBarTest extends MediaWikiLangTestCase { /** * Internal helper to test the sidebar - * @param $expected - * @param $text - * @param $message (Default: '') + * @param array $expected + * @param string $text + * @param string $message (Default: '') * @todo this assert method to should be converted to a test using a dataprovider.. */ private function assertSideBar( $expected, $text, $message = '' ) { - $bar = array(); + $bar = []; $this->skin->addToSidebarPlain( $bar, $text ); $this->assertEquals( $expected, $bar, $message ); } @@ -57,10 +64,10 @@ class SideBarTest extends MediaWikiLangTestCase { */ public function testSidebarWithOnlyTwoTitles() { $this->assertSideBar( - array( - 'Title1' => array(), - 'Title2' => array(), - ), + [ + 'Title1' => [], + 'Title2' => [], + ], '* Title1 * Title2 ' @@ -71,15 +78,15 @@ class SideBarTest extends MediaWikiLangTestCase { * @covers SkinTemplate::addToSidebarPlain */ public function testExpandMessages() { - $this->assertSidebar( - array( 'Title' => array( - array( + $this->assertSideBar( + [ 'Title' => [ + [ 'text' => 'Help', 'href' => $this->messages['helppage']['href'], 'id' => 'n-help', 'active' => null - ) - ) ), + ] + ] ], '* Title ** helppage|help ' @@ -90,24 +97,24 @@ class SideBarTest extends MediaWikiLangTestCase { * @covers SkinTemplate::addToSidebarPlain */ public function testExternalUrlsRequireADescription() { - $this->setMwGlobals( array( + $this->setMwGlobals( [ 'wgNoFollowLinks' => true, - 'wgNoFollowDomainExceptions' => array(), - 'wgNoFollowNsExceptions' => array(), - ) ); - $this->assertSidebar( - array( 'Title' => array( + 'wgNoFollowDomainExceptions' => [], + 'wgNoFollowNsExceptions' => [], + ] ); + $this->assertSideBar( + [ 'Title' => [ # ** http://www.mediawiki.org/| Home - array( + [ 'text' => 'Home', 'href' => 'http://www.mediawiki.org/', 'id' => 'n-Home', 'active' => null, 'rel' => 'nofollow', - ), + ], # ** http://valid.no.desc.org/ # ... skipped since it is missing a pipe with a description - ) ), + ] ], '* Title ** http://www.mediawiki.org/| Home ** http://valid.no.desc.org/ @@ -116,30 +123,30 @@ class SideBarTest extends MediaWikiLangTestCase { } /** - * bug 33321 - Make sure there's a | after transforming. + * T35321 - Make sure there's a | after transforming. * @group Database * @covers SkinTemplate::addToSidebarPlain */ public function testTrickyPipe() { - $this->assertSidebar( - array( 'Title' => array( + $this->assertSideBar( + [ 'Title' => [ # The first 2 are skipped # Doesn't really test the url properly # because it will vary with $wgArticlePath et al. # ** Baz|Fred - array( + [ 'text' => 'Fred', 'href' => Title::newFromText( 'Baz' )->getLocalURL(), 'id' => 'n-Fred', 'active' => null, - ), - array( + ], + [ 'text' => 'title-to-display', 'href' => Title::newFromText( 'page-to-go-to' )->getLocalURL(), 'id' => 'n-title-to-display', 'active' => null, - ), - ) ), + ], + ] ], '* Title ** {{PAGENAME|Foo}} ** Bar @@ -155,8 +162,8 @@ class SideBarTest extends MediaWikiLangTestCase { $text = '* Title ** http://www.mediawiki.org/| Home'; - $bar = array(); - $this->skin->addToSideBarPlain( $bar, $text ); + $bar = []; + $this->skin->addToSidebarPlain( $bar, $text ); return $bar['Title'][0]; } @@ -165,12 +172,12 @@ class SideBarTest extends MediaWikiLangTestCase { * Simple test to verify our helper assertAttribs() is functional */ public function testTestAttributesAssertionHelper() { - $this->setMwGlobals( array( + $this->setMwGlobals( [ 'wgNoFollowLinks' => true, - 'wgNoFollowDomainExceptions' => array(), - 'wgNoFollowNsExceptions' => array(), + 'wgNoFollowDomainExceptions' => [], + 'wgNoFollowNsExceptions' => [], 'wgExternalLinkTarget' => false, - ) ); + ] ); $attribs = $this->getAttribs(); $this->assertArrayHasKey( 'rel', $attribs ); @@ -204,9 +211,9 @@ class SideBarTest extends MediaWikiLangTestCase { } public static function dataRespectExternallinktarget() { - return array( - array( '_blank' ), - array( '_self' ), - ); + return [ + [ '_blank' ], + [ '_self' ], + ]; } }