Hoo man has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/190693

Change subject: Sort links in the other projects sidebar by group id
......................................................................

Sort links in the other projects sidebar by group id

Bug: T86328
Change-Id: I0b7041272a545476a71b41c8fb13264c53130475
---
M client/includes/Hooks/OtherProjectsSidebarGenerator.php
M client/tests/phpunit/includes/Hooks/OtherProjectsSidebarGeneratorTest.php
2 files changed, 76 insertions(+), 25 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/93/190693/1

diff --git a/client/includes/Hooks/OtherProjectsSidebarGenerator.php 
b/client/includes/Hooks/OtherProjectsSidebarGenerator.php
index 32ff5a3..93cf331 100644
--- a/client/includes/Hooks/OtherProjectsSidebarGenerator.php
+++ b/client/includes/Hooks/OtherProjectsSidebarGenerator.php
@@ -56,7 +56,7 @@
        /**
         * @param Title $title
         *
-        * @return array[]
+        * @return array[] Sorted by site group id
         */
        public function buildProjectLinkSidebar( Title $title ) {
                return $this->buildSidebarFromSiteLinks( $this->getSiteLinks( 
$title ) );
@@ -65,7 +65,7 @@
        /**
         * @param SiteLink[] $siteLinks
         *
-        * @return array[]
+        * @return array[] Sorted by site group id
         */
        private function buildSidebarFromSiteLinks( array $siteLinks ) {
                $result = array();
@@ -79,10 +79,12 @@
                                continue;
                        }
 
-                       $result[] = $this->buildSidebarLink( $siteLink, $site );
+                       // Index by site group and global id (just to make sure 
this will for multiple sites in the same group)
+                       $result[$site->getGroup() . $site->getGlobalId()] = 
$this->buildSidebarLink( $siteLink, $site );
                }
 
-               return $result;
+               ksort( $result );
+               return array_values( $result );
        }
 
        /**
diff --git 
a/client/tests/phpunit/includes/Hooks/OtherProjectsSidebarGeneratorTest.php 
b/client/tests/phpunit/includes/Hooks/OtherProjectsSidebarGeneratorTest.php
index 1299a03..4835054 100644
--- a/client/tests/phpunit/includes/Hooks/OtherProjectsSidebarGeneratorTest.php
+++ b/client/tests/phpunit/includes/Hooks/OtherProjectsSidebarGeneratorTest.php
@@ -3,10 +3,12 @@
 namespace Wikibase\Client\Tests\Hooks;
 
 use Title;
+use SiteStore;
+use MediaWikiSite;
 use Wikibase\Client\Hooks\OtherProjectsSidebarGenerator;
-use Wikibase\DataModel\Entity\Item;
+use Wikibase\DataModel\Entity\ItemId;
 use Wikibase\DataModel\SiteLink;
-use Wikibase\Test\MockRepository;
+use Wikibase\Lib\Store\SiteLinkLookup;
 use Wikibase\Test\MockSiteStore;
 
 /**
@@ -19,6 +21,7 @@
  *
  * @licence GNU GPL v2+
  * @author Thomas Pellissier Tanon
+ * @author Marius Hoch < [email protected] >
  */
 class OtherProjectsSidebarGeneratorTest extends \MediaWikiTestCase {
 
@@ -26,19 +29,10 @@
         * @dataProvider projectLinkSidebarProvider
         */
        public function testBuildProjectLinkSidebar( array $siteIdsToOutput, 
array $result ) {
-               $item = new Item();
-               $item->addSiteLink( new SiteLink( 'enwiki', 'Nyan Cat' ) );
-               $item->addSiteLink( new SiteLink( 'enwiktionary', 'Nyan Cat' ) 
);
-
-               $mockRepo = new MockRepository();
-               $mockRepo->putEntity( $item );
-
-               $siteStore = MockSiteStore::newFromTestSites();
-
                $otherProjectSidebarGenerator = new 
OtherProjectsSidebarGenerator(
                        'enwiki',
-                       $mockRepo,
-                       $siteStore,
+                       $this->getSiteLinkLookup(),
+                       $this->getSiteStore(),
                        $siteIdsToOutput
                );
 
@@ -49,6 +43,25 @@
        }
 
        public function projectLinkSidebarProvider() {
+               $wiktionaryLink = array(
+                       'msg' => 'wikibase-otherprojects-wiktionary',
+                       'class' => 'wb-otherproject-link 
wb-otherproject-wiktionary',
+                       'href' => 'https://en.wiktionary.org/wiki/Nyan_Cat',
+                       'hreflang' => 'en'
+               );
+               $wikiquoteLink = array(
+                       'msg' => 'wikibase-otherprojects-wikiquote',
+                       'class' => 'wb-otherproject-link 
wb-otherproject-wikiquote',
+                       'href' => 'https://en.wikiquote.org/wiki/Nyan_Cat',
+                       'hreflang' => 'en'
+               );
+               $wikipediaLink = array(
+                       'msg' => 'wikibase-otherprojects-wikipedia',
+                       'class' => 'wb-otherproject-link 
wb-otherproject-wikipedia',
+                       'href' => 'https://en.wikipedia.org/wiki/Nyan_Cat',
+                       'hreflang' => 'en'
+               );
+
                return array(
                        array(
                                array(),
@@ -60,16 +73,52 @@
                        ),
                        array(
                                array( 'enwiktionary' ),
-                               array(
-                                       array(
-                                               'msg' => 
'wikibase-otherprojects-wiktionary',
-                                               'class' => 
'wb-otherproject-link wb-otherproject-wiktionary',
-                                               'href' => 
'https://en.wiktionary.org/wiki/Nyan_Cat',
-                                               'hreflang' => 'en'
-                                       )
-                               )
+                               array( $wiktionaryLink )
+                       ),
+                       array(
+                               // Make sure results are sorted alphabetically 
by their group names
+                               array( 'enwiktionary', 'enwiki', 'enwikiquote' 
),
+                               array( $wikipediaLink, $wikiquoteLink, 
$wiktionaryLink )
                        )
                );
        }
 
+       /**
+        * @return SiteStore
+        */
+       private function getSiteStore() {
+               $siteStore = MockSiteStore::newFromTestSites();
+
+               $site = new MediaWikiSite();
+               $site->setGlobalId( 'enwikiquote' );
+               $site->setGroup( 'wikiquote' );
+               $site->setLanguageCode( 'en' );
+               $site->setPath( MediaWikiSite::PATH_PAGE, 
"https://en.wikiquote.org/wiki/$1"; );
+               $siteStore->saveSite( $site );
+
+               return $siteStore;
+       }
+
+       /**
+        * @return SiteLinkLookup
+        */
+       private function getSiteLinkLookup( ) {
+               $Q123 = new ItemId( 'Q123' );
+
+               $lookup = $this->getMock( 'Wikibase\Lib\Store\SiteLinkLookup' );
+               $lookup->expects( $this->any() )
+                               ->method( 'getEntityIdForSiteLink' )
+                               ->will( $this->returnValue( $Q123 ) );
+
+               $lookup->expects( $this->any() )
+                       ->method( 'getSiteLinksForItem' )
+                       ->with( $Q123 )
+                       ->will( $this->returnValue( array(
+                               new SiteLink( 'enwikiquote', 'Nyan Cat' ),
+                               new SiteLink( 'enwiki', 'Nyan Cat' ),
+                               new SiteLink( 'enwiktionary', 'Nyan Cat' )
+                       ) ) );
+
+               return $lookup;
+       }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/190693
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0b7041272a545476a71b41c8fb13264c53130475
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Hoo man <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to