jenkins-bot has submitted this change and it was merged.

Change subject: Use MockSiteStore for testing
......................................................................


Use MockSiteStore for testing

Change-Id: I783bd952759d001767f795178ab19c33872d7e17
---
M client/tests/phpunit/includes/LangLinkHandlerTest.php
M lib/WikibaseLib.classes.php
A lib/tests/phpunit/MockSiteStore.php
3 files changed, 143 insertions(+), 6 deletions(-)

Approvals:
  Hoo man: Looks good to me, approved
  Daniel Kinzler: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/client/tests/phpunit/includes/LangLinkHandlerTest.php 
b/client/tests/phpunit/includes/LangLinkHandlerTest.php
index f52c4ef..ed07fd2 100644
--- a/client/tests/phpunit/includes/LangLinkHandlerTest.php
+++ b/client/tests/phpunit/includes/LangLinkHandlerTest.php
@@ -30,8 +30,7 @@
  *
  * @group WikibaseClient
  * @group Database
- *        ^--- uses DB indirectly; may be removed if Sites is mocked out
- *             and Title is made not to use the database.
+ *        ^--- uses DB indirectly; removed when Title is made not to use the 
database.
  *
  * @licence GNU GPL v2+
  * @author Daniel Kinzler
@@ -72,8 +71,6 @@
 
                if ( !$hasSites ) {
                        $hasSites = true;
-                       //TODO: use mock SiteList instead!
-                       \TestSites::insertIntoDb();
                }
 
                $this->mockRepo = new MockRepository();
@@ -83,12 +80,12 @@
                        $this->mockRepo->putEntity( $item );
                }
 
-               $this->langLinkHandler = new \Wikibase\LangLinkHandler(
+               $this->langLinkHandler = new LangLinkHandler(
                        'srwiki',
                        array(),
                        array( NS_TALK ),
                        $this->mockRepo,
-                       \SiteSQLStore::newInstance()
+                       MockSiteStore::newFromTestSites()
                );
        }
 
diff --git a/lib/WikibaseLib.classes.php b/lib/WikibaseLib.classes.php
index b5f2b4f..d409c31 100644
--- a/lib/WikibaseLib.classes.php
+++ b/lib/WikibaseLib.classes.php
@@ -182,6 +182,7 @@
                'Wikibase\Test\MockChunkAccess' => 
'tests/phpunit/store/MockChunkAccess.php',
                'Wikibase\Test\TermIndexTest' => 
'tests/phpunit/store/TermIndexTest.php',
                'Wikibase\Test\MockPropertyInfoStore' => 
'tests/phpunit/store/MockPropertyInfoStore.php',
+               'Wikibase\Test\MockSiteStore' => 
'tests/phpunit/MockSiteStore.php',
 
                'Wikibase\Test\PropertyInfoStoreTestHelper' => 
'tests/phpunit/store/PropertyInfoStoreTestHelper.php',
        );
diff --git a/lib/tests/phpunit/MockSiteStore.php 
b/lib/tests/phpunit/MockSiteStore.php
new file mode 100644
index 0000000..c5c0d01
--- /dev/null
+++ b/lib/tests/phpunit/MockSiteStore.php
@@ -0,0 +1,139 @@
+<?php
+namespace Wikibase\Test;
+
+use Site;
+use SiteList;
+use SiteStore;
+use \TestSites;
+/**
+ *
+ * Copyright © 2013-07-02 by the authors listed below.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @license GPL 2+
+ * @file
+ *
+ * @author Daniel Kinzler
+ */
+
+/**
+ * Class MockSiteStore
+ * @package Wikibase\Test
+ */
+class MockSiteStore implements SiteStore {
+
+       /**
+        * @var Site[]
+        */
+       private $sites;
+
+       /**
+        * Returns a SiteStore object that contains TestSites::getSites().
+        * The SiteStore is not not be backed by an actual database.
+        *
+        * @return SiteStore
+        */
+       public static function newFromTestSites() {
+               $testSites = TestSites::getSites();
+
+               $sites = array();
+               foreach( $testSites as $site ) {
+                       $sites[$site->getGlobalId()] = $site;
+               }
+
+               $store = new MockSiteStore( $sites );
+               return $store;
+       }
+
+       /**
+        * @param array $sites
+        */
+       public function __construct( $sites = array() ) {
+               $this->sites = $sites;
+       }
+
+       /**
+        * Saves the provided site.
+        *
+        * @since 1.21
+        *
+        * @param Site $site
+        *
+        * @return boolean Success indicator
+        */
+       public function saveSite( Site $site ) {
+               $this->sites[$site->getGlobalId()] = $site;
+       }
+
+       /**
+        * Saves the provided sites.
+        *
+        * @since 1.21
+        *
+        * @param Site[] $sites
+        *
+        * @return boolean Success indicator
+        */
+       public function saveSites( array $sites ) {
+               foreach ( $sites as $site ) {
+                       $this->saveSite( $site );
+               }
+       }
+
+       /**
+        * Returns the site with provided global id, or null if there is no 
such site.
+        *
+        * @since 1.21
+        *
+        * @param string $globalId
+        * @param string $source either 'cache' or 'recache'.
+        *                       If 'cache', the values are allowed (but not 
obliged) to come from a cache.
+        *
+        * @return Site|null
+        */
+       public function getSite( $globalId, $source = 'cache' ) {
+               if ( isset( $this->sites[$globalId] ) ) {
+                       return $this->sites[$globalId];
+               } else {
+                       return null;
+               }
+       }
+
+       /**
+        * Returns a list of all sites. By default this site is
+        * fetched from the cache, which can be changed to loading
+        * the list from the database using the $useCache parameter.
+        *
+        * @since 1.21
+        *
+        * @param string $source either 'cache' or 'recache'.
+        *                       If 'cache', the values are allowed (but not 
obliged) to come from a cache.
+        *
+        * @return SiteList
+        */
+       public function getSites( $source = 'cache' ) {
+               return new SiteList( $this->sites );
+       }
+
+       /**
+        * Deletes all sites from the database. After calling clear(), 
getSites() will return an empty
+        * list and getSite() will return null until saveSite() or saveSites() 
is called.
+        */
+       public function clear() {
+               $this->sites = array();
+       }
+}

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I783bd952759d001767f795178ab19c33872d7e17
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to