Daniel Kinzler has uploaded a new change for review.

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

Change subject: Delete old test items during test setup.
......................................................................

Delete old test items during test setup.

This should make tests that rely on entity data in the database more robust,
by making sure that each test suite starts with a clean set of entities.

Change-Id: I393751e16ab4ebdda9a722370a31c24b449d6375
---
M repo/tests/phpunit/includes/api/EntityTestHelper.php
M repo/tests/phpunit/includes/api/WikibaseApiTestCase.php
2 files changed, 26 insertions(+), 4 deletions(-)


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

diff --git a/repo/tests/phpunit/includes/api/EntityTestHelper.php 
b/repo/tests/phpunit/includes/api/EntityTestHelper.php
index 70a23ce..7fbc9a9 100644
--- a/repo/tests/phpunit/includes/api/EntityTestHelper.php
+++ b/repo/tests/phpunit/includes/api/EntityTestHelper.php
@@ -357,7 +357,7 @@
         * @param string $handle
         * @throws OutOfBoundsException
         */
-       private static function unRegisterEntity( $handle ) {
+       public static function unRegisterEntity( $handle ) {
                unset( self::$activeIds[ self::$activeHandles[ $handle ] ] );
                unset( self::$activeHandles[ $handle ] );
        }
diff --git a/repo/tests/phpunit/includes/api/WikibaseApiTestCase.php 
b/repo/tests/phpunit/includes/api/WikibaseApiTestCase.php
index 83e8534..3b0477e 100644
--- a/repo/tests/phpunit/includes/api/WikibaseApiTestCase.php
+++ b/repo/tests/phpunit/includes/api/WikibaseApiTestCase.php
@@ -3,12 +3,15 @@
 namespace Wikibase\Test\Api;
 
 use ApiTestCase;
+use OutOfBoundsException;
 use Revision;
 use TestSites;
 use TestUser;
+use Title;
 use UsageException;
 use User;
 use Wikibase\Repo\WikibaseRepo;
+use WikiPage;
 
 /**
  * Base class for test classes that test the API modules that derive from 
ApiWikibaseModifyItem.
@@ -97,9 +100,11 @@
                $activeHandles = EntityTestHelper::getActiveHandles();
 
                foreach ( $activeHandles as $handle => $id ) {
-                       $params = EntityTestHelper::getEntityClear( $handle );
-                       $params['action'] = 'wbeditentity';
-                       $this->doApiRequestWithToken( $params );
+                       $title = $this->getTestEntityTitle( $handle );
+
+                       $page = WikiPage::factory( $title );
+                       $page->doDeleteArticle( 'Test reset' );
+                       EntityTestHelper::unRegisterEntity( $handle );
                }
 
                foreach ( $handles as $handle ) {
@@ -117,6 +122,23 @@
        }
 
        /**
+        * @param string $handle
+        *
+        * @return null|Title
+        */
+       protected function getTestEntityTitle( $handle ) {
+               try {
+                       $idString = EntityTestHelper::getId( $handle );
+                       $id = 
WikibaseRepo::getDefaultInstance()->getEntityIdParser()->parse( $idString );
+                       $title =  
WikibaseRepo::getDefaultInstance()->getEntityTitleLookup()->getTitleForId( $id 
);
+               } catch ( OutOfBoundsException $ex ) {
+                       $title = null;
+               }
+
+               return $title;
+       }
+
+       /**
         * Loads an entity from the database (via an API call).
         *
         * @param string $id

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I393751e16ab4ebdda9a722370a31c24b449d6375
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <daniel.kinz...@wikimedia.de>

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

Reply via email to