Fix numerous class/function casing
[lhc/web/wiklou.git] / tests / phpunit / skins / SideBarTest.php
index 7d33a59..0945b8f 100644 (file)
@@ -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/
@@ -122,24 +129,24 @@ class SideBarTest extends MediaWikiLangTestCase {
         */
        public function testTrickyPipe() {
                $this->assertSidebar(
-                       array( 'Title' => array(
+                       [ '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,7 +162,7 @@ class SideBarTest extends MediaWikiLangTestCase {
                $text = '* Title
 ** http://www.mediawiki.org/| Home';
 
-               $bar = array();
+               $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' ],
+               ];
        }
 }