Daniel Werner has uploaded a new change for review.

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


Change subject: Added JavaScript wikibase.getSiteGroups()
......................................................................

Added JavaScript wikibase.getSiteGroups()

Change-Id: I4bf38430f12277cacc8c1cead7c4caf53e523d18
---
M lib/resources/wikibase.js
M lib/tests/qunit/wikibase.tests.js
2 files changed, 69 insertions(+), 4 deletions(-)


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

diff --git a/lib/resources/wikibase.js b/lib/resources/wikibase.js
index 4ef042d..5533eec 100644
--- a/lib/resources/wikibase.js
+++ b/lib/resources/wikibase.js
@@ -144,6 +144,28 @@
        };
 
        /**
+        * Returns an array with all known site groups.
+        *
+        * @since 0.4
+        *
+        * @return string[]
+        */
+       this.getSiteGroups = function() {
+               var groups = [],
+                       sites = this.getSites();
+
+               for( var siteId in sites ) {
+                       var site = sites[ siteId ],
+                               group = site.getGroup();
+
+                       if( $.inArray( group, groups ) === -1 ) {
+                               groups.push( group );
+                       }
+               }
+               return groups;
+       };
+
+       /**
         * Returns whether the Wikibase installation knows a site with a 
certain ID.
         *
         * @return bool
diff --git a/lib/tests/qunit/wikibase.tests.js 
b/lib/tests/qunit/wikibase.tests.js
index 6871011..a906ed8 100644
--- a/lib/tests/qunit/wikibase.tests.js
+++ b/lib/tests/qunit/wikibase.tests.js
@@ -19,22 +19,42 @@
         */
        wb.tests = {};
 
-       var sitesDefinition = {
+       /**
+        * All site groups used in site definitions in TEST_SITE_DEFINITIONS.
+        * @type String[]
+        */
+       var TEST_SITE_GROUPS = [ 'wikipedia', 'foo bar group' ];
+
+       /**
+        * Site definition loaded to mw.config var "wbSiteDetails" before each 
test.
+        * @type Object
+        */
+       var TEST_SITE_DEFINITIONS = {
                nn: {
                        apiUrl: '//nn.wikipedia.org/w/api.php',
                        globalSiteId: 'nnwiki',
-                       group: 'wikipedia',
+                       group: TEST_SITE_GROUPS[0],
                        id: 'nn',
                        languageCode: 'nn',
                        name: null,
                        pageUrl: '//nn.wikipedia.org/wiki/$1',
                        shortName: 'norsk nynorsk'
+               },
+               foo: {
+                       apiUrl: '//foo.site.bar/api.php',
+                       globalSiteId: 'foo-site',
+                       group: TEST_SITE_GROUPS[1],
+                       id: 'foo',
+                       languageCode: 'foo',
+                       name: null,
+                       pageUrl: '//foo.site.bar/pages/$1',
+                       shortName: 'foo site'
                }
        };
 
        QUnit.module( 'wikibase', QUnit.newWbEnvironment( {
                config: {
-                       wbSiteDetails: sitesDefinition
+                       wbSiteDetails: TEST_SITE_DEFINITIONS
                }
        } ) );
 
@@ -55,7 +75,7 @@
 
                assert.strictEqual(
                        sites.length,
-                       sitesDefinition.length,
+                       TEST_SITE_DEFINITIONS.length,
                        'getSites() returns expected number of sites'
                );
 
@@ -97,6 +117,29 @@
                );
        } );
 
+       QUnit.test( 'wikibase.getSiteGroups()', 2 + TEST_SITE_GROUPS.length, 
function( assert ) {
+               var siteGroups = wb.getSiteGroups();
+
+               assert.strictEqual(
+                       $.isArray( siteGroups ),
+                       true,
+                       'getSiteGroups() returns Array'
+               );
+
+               assert.strictEqual(
+                       siteGroups.length,
+                       TEST_SITE_GROUPS.length,
+                       'Number of expected groups is accurate'
+               );
+
+               $.each( TEST_SITE_GROUPS, function( i, group ) {
+                       assert.ok(
+                               $.inArray( group, siteGroups ) !== -1,
+                               'site group "' + group + '" is part of returned 
site groups'
+                       );
+               } );
+       } );
+
        QUnit.test( 'wikibase.getLanguages()', 1, function( assert ) {
                assert.ok(
                        $.isPlainObject( wb.getLanguages() ),

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4bf38430f12277cacc8c1cead7c4caf53e523d18
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Werner <[email protected]>

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

Reply via email to