Addshore has uploaded a new change for review.

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


Change subject: Remove copied code in system tests
......................................................................

Remove copied code in system tests

Change-Id: I3c67f8fc776cf15564239aebf6318bd9c3db8ed6
---
A Tests/System/Api/ApiTestSetup.php
M Tests/System/Api/EntitiesByPropertyValueApiTest.php
M Tests/System/Api/PermissionsTest.php
M Tests/System/Specials/SimpleQueryTest.php
4 files changed, 112 insertions(+), 137 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseQuery 
refs/changes/61/96261/1

diff --git a/Tests/System/Api/ApiTestSetup.php 
b/Tests/System/Api/ApiTestSetup.php
new file mode 100644
index 0000000..53b321e
--- /dev/null
+++ b/Tests/System/Api/ApiTestSetup.php
@@ -0,0 +1,89 @@
+<?php
+
+namespace Tests\System\Wikibase\Query\Api;
+
+use DataValues\StringValue;
+use Wikibase\DataModel\Entity\ItemId;
+use Wikibase\DataModel\Entity\PropertyId;
+use Wikibase\Item;
+use Wikibase\ItemContent;
+use Wikibase\Property;
+use Wikibase\PropertyContent;
+use Wikibase\PropertyValueSnak;
+use Wikibase\Query\DIC\ExtensionAccess;
+use Wikibase\Statement;
+
+/**
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroended...@gmail.com >
+ * @author Adam Shorland
+ */
+class ApiTestSetup {
+
+       protected $propertyId;
+       protected $itemId;
+
+       function __construct( $itemId, $propertyId ) {
+               $this->itemId = $itemId;
+               $this->propertyId = $propertyId;
+       }
+
+       public function setUp() {
+               $this->itemId = new ItemId( $this->itemId );
+               $this->propertyId = new PropertyId( $this->propertyId );
+
+               $this->getQueryStore()->newInstaller()->install();
+
+               $this->createNewProperty();
+               $this->insertNewItem();
+       }
+
+       public function tearDown() {
+               $this->getQueryStore()->newUninstaller()->uninstall();
+       }
+
+       protected function getQueryStore() {
+               return 
ExtensionAccess::getWikibaseQuery()->getQueryStoreWithDependencies();
+       }
+
+       protected function createNewProperty() {
+               $property = Property::newEmpty();
+               $property->setId( $this->propertyId );
+               $property->setDataTypeId( 'string' );
+
+               $propertyContent = PropertyContent::newFromProperty( $property 
);
+
+               $propertyContent->save();
+       }
+
+       protected function insertNewItem() {
+               $item = $this->newMockItem();
+
+               $itemContent = ItemContent::newFromItem( $item );
+               $itemContent->save();
+       }
+
+       protected function newMockItem() {
+               $item = Item::newEmpty();
+
+               $item->setId( $this->itemId );
+
+               $claim = new Statement(
+                       new PropertyValueSnak(
+                               $this->propertyId,
+                               $this->newMockValue()
+                       )
+               );
+
+               $claim->setGuid( 'foo' );
+
+               $item->addClaim( $claim );
+
+               return $item;
+       }
+
+       protected function newMockValue() {
+               return new StringValue( 'API tests really suck' );
+       }
+
+} 
\ No newline at end of file
diff --git a/Tests/System/Api/EntitiesByPropertyValueApiTest.php 
b/Tests/System/Api/EntitiesByPropertyValueApiTest.php
index 98ba0c5..a5b2eaa 100644
--- a/Tests/System/Api/EntitiesByPropertyValueApiTest.php
+++ b/Tests/System/Api/EntitiesByPropertyValueApiTest.php
@@ -1,17 +1,9 @@
 <?php
 
-namespace Tests\Integration\Wikibase\Query\Api;
+namespace Tests\System\Wikibase\Query\Api;
 
-use DataValues\StringValue;
-use Wikibase\DataModel\Entity\ItemId;
-use Wikibase\DataModel\Entity\PropertyId;
-use Wikibase\Item;
-use Wikibase\ItemContent;
-use Wikibase\Property;
-use Wikibase\PropertyContent;
-use Wikibase\PropertyValueSnak;
-use Wikibase\Query\DIC\ExtensionAccess;
-use Wikibase\Statement;
+//TODO FIXME where to put this?
+require_once( __DIR__ . '/ApiTestSetup.php' );
 
 /**
  * @group WikibaseQuery
@@ -29,68 +21,20 @@
        const PROPERTY_ID_STRING = 'P31337';
        const ITEM_ID_STRING = 'Q42';
 
-       protected $itemId;
-       protected $propertyId;
-
-       protected function getQueryStore() {
-               return 
ExtensionAccess::getWikibaseQuery()->getQueryStoreWithDependencies();
-       }
+       /**
+        * @var ApiTestSetup
+        */
+       protected $apiTestSetup;
 
        public function setUp() {
                parent::setUp();
-
-               $this->itemId = new ItemId( self::ITEM_ID_STRING );
-               $this->propertyId = new PropertyId( self::PROPERTY_ID_STRING );
-
-               $this->getQueryStore()->newInstaller()->install();
-
-               $this->createNewProperty();
-               $this->insertNewItem();
+               $this->apiTestSetup = new ApiTestSetup( self::ITEM_ID_STRING, 
self::PROPERTY_ID_STRING );
+               $this->apiTestSetup->setUp();
        }
 
        public function tearDown() {
-               $this->getQueryStore()->newUninstaller()->uninstall();
                parent::tearDown();
-       }
-
-       protected function createNewProperty() {
-               $property = Property::newEmpty();
-               $property->setId( $this->propertyId );
-               $property->setDataTypeId( 'string' );
-
-               $propertyContent = PropertyContent::newFromProperty( $property 
);
-
-               $propertyContent->save();
-       }
-
-       protected function insertNewItem() {
-               $item = $this->newMockItem();
-
-               $itemContent = ItemContent::newFromItem( $item );
-               $itemContent->save();
-       }
-
-       protected function newMockItem() {
-               $item = Item::newEmpty();
-
-               $item->setId( $this->itemId );
-
-               $claim = new Statement(
-                       new PropertyValueSnak(
-                               $this->propertyId,
-                               $this->newMockValue()
-                       )
-               );
-
-               $claim->setGuid( 'foo' );
-
-               $item->addClaim( $claim );
-
-               return $item;
-       }
-
-       protected function newMockValue() {
-               return new StringValue( 'API tests really suck' );
+               $this->apiTestSetup->tearDown();
        }
 
        protected function newMockValueString() {
diff --git a/Tests/System/Api/PermissionsTest.php 
b/Tests/System/Api/PermissionsTest.php
index 4f752f8..b24251d 100644
--- a/Tests/System/Api/PermissionsTest.php
+++ b/Tests/System/Api/PermissionsTest.php
@@ -1,17 +1,11 @@
 <?php
 
-namespace Tests\Integration\Wikibase\Query\Api;
+namespace Tests\System\Wikibase\Query\Api;
 
-use DataValues\StringValue;
-use Wikibase\DataModel\Entity\ItemId;
-use Wikibase\DataModel\Entity\PropertyId;
-use Wikibase\Item;
-use Wikibase\Property;
-use Wikibase\PropertyContent;
-use Wikibase\PropertyValueSnak;
-use Wikibase\Query\DIC\ExtensionAccess;
-use Wikibase\Statement;
 use Wikibase\Test\Api\PermissionsTestCase;
+
+//TODO FIXME where to put this?
+require_once( __DIR__ . '/ApiTestSetup.php' );
 
 /**
  * @group WikibaseQuery
@@ -25,76 +19,24 @@
  */
 class PermissionsTest extends PermissionsTestCase {
 
+       const MODULE_NAME = 'entitiesbypropertyvalue';
        const PROPERTY_ID_STRING = 'P31337';
        const ITEM_ID_STRING = 'Q42';
 
-       protected $itemId;
-       protected $propertyId;
-
-       protected function getQueryStore() {
-               return 
ExtensionAccess::getWikibaseQuery()->getQueryStoreWithDependencies();
-       }
+       /**
+        * @var ApiTestSetup
+        */
+       protected $apiTestSetup;
 
        public function setUp() {
                parent::setUp();
-
-               $this->itemId = new ItemId( self::ITEM_ID_STRING );
-               $this->propertyId = new PropertyId( self::PROPERTY_ID_STRING );
-
-               $this->getQueryStore()->newInstaller()->install();
-
-               $this->createNewProperty();
-               $this->insertNewItem();
+               $this->apiTestSetup = new ApiTestSetup( self::ITEM_ID_STRING, 
self::PROPERTY_ID_STRING );
+               $this->apiTestSetup->setUp();
        }
 
        public function tearDown() {
-               $this->getQueryStore()->newUninstaller()->uninstall();
                parent::tearDown();
-       }
-
-       protected function createNewProperty() {
-               $property = Property::newEmpty();
-               $property->setId( $this->propertyId );
-               $property->setDataTypeId( 'string' );
-
-               $propertyContent = PropertyContent::newFromProperty( $property 
);
-
-               $propertyContent->save();
-       }
-
-       protected function insertNewItem() {
-               $storeUpdater = $this->getQueryStore()->newWriter();
-
-               $item = $this->newMockItem();
-
-               $storeUpdater->insertEntity( $item );
-       }
-
-       protected function newMockItem() {
-               $item = Item::newEmpty();
-
-               $item->setId( $this->itemId );
-
-               $claim = new Statement(
-                       new PropertyValueSnak(
-                               $this->propertyId,
-                               $this->newMockValue()
-                       )
-               );
-
-               $claim->setGuid( 'foo' );
-
-               $item->addClaim( $claim );
-
-               return $item;
-       }
-
-       protected function newMockValue() {
-               return new StringValue( 'API tests really suck' );
-       }
-
-       protected function newMockValueString() {
-               return '{"value":"API tests really suck","type":"string"}';
+               $this->apiTestSetup->tearDown();
        }
 
        /**
diff --git a/Tests/System/Specials/SimpleQueryTest.php 
b/Tests/System/Specials/SimpleQueryTest.php
index a48f703..556f4ab 100644
--- a/Tests/System/Specials/SimpleQueryTest.php
+++ b/Tests/System/Specials/SimpleQueryTest.php
@@ -1,6 +1,6 @@
 <?php
 
-namespace Tests\Integration\Wikibase\Query\Special;
+namespace Tests\System\Wikibase\Query\Special;
 
 use Wikibase\Test\PermissionsHelper;
 use \Wikibase\Test\SpecialPageTestBase;

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3c67f8fc776cf15564239aebf6318bd9c3db8ed6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseQuery
Gerrit-Branch: master
Gerrit-Owner: Addshore <addshorew...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to