Addshore has uploaded a new change for review.
https://gerrit.wikimedia.org/r/77899
Change subject: General further tidy up of the test base
......................................................................
General further tidy up of the test base
Change-Id: Ibc025dc2871e32726e6a1a1765e8454d49958759
---
M repo/tests/phpunit/includes/api/BotEditTest.php
M repo/tests/phpunit/includes/api/LinkTitlesTest.php
M repo/tests/phpunit/includes/api/ModifyEntityTestBase.php
3 files changed, 33 insertions(+), 72 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/99/77899/1
diff --git a/repo/tests/phpunit/includes/api/BotEditTest.php
b/repo/tests/phpunit/includes/api/BotEditTest.php
index 2162568..5d0108a 100644
--- a/repo/tests/phpunit/includes/api/BotEditTest.php
+++ b/repo/tests/phpunit/includes/api/BotEditTest.php
@@ -61,16 +61,18 @@
protected static $baseOfItemIds = 1;
public function setUp() {
- global $wgUser;
parent::setUp();
- ApiTestCase::$users['wbbot'] = new TestUser(
+ self::$users['wbbot'] = new TestUser(
'Apitestbot',
'Api Test Bot',
'[email protected]',
array( 'bot' )
);
- $wgUser = self::$users['wbbot']->user;
+
+ $this->setMwGlobals( array(
+ 'wgUser' => self::$users['wbbot']->user,
+ ) );
$this->login( 'wbbot' );
}
diff --git a/repo/tests/phpunit/includes/api/LinkTitlesTest.php
b/repo/tests/phpunit/includes/api/LinkTitlesTest.php
index 92e153a..d20d31e 100644
--- a/repo/tests/phpunit/includes/api/LinkTitlesTest.php
+++ b/repo/tests/phpunit/includes/api/LinkTitlesTest.php
@@ -175,16 +175,6 @@
$this->assertEquals( $totitle, $links[$tosite], 'wrong
link target' );
}
- if ( $cleanUp ) {
- // This sucks really bad, but it's the only way we can
do this
- // for several reasons:
- // This tests assume the entities to not being reseted
during
- // run time (so we can't use the setUp/ tearDown
functions for
- // this) but it changes them so they have to be cleared
out at
- // some point.
- $this->resetEntities();
- }
-
$this->assertTrue( true );
}
diff --git a/repo/tests/phpunit/includes/api/ModifyEntityTestBase.php
b/repo/tests/phpunit/includes/api/ModifyEntityTestBase.php
index f31b7ce..50b7a5b 100644
--- a/repo/tests/phpunit/includes/api/ModifyEntityTestBase.php
+++ b/repo/tests/phpunit/includes/api/ModifyEntityTestBase.php
@@ -57,39 +57,29 @@
protected static $entityInput = null; // entities in input format,
using handles as keys
protected static $entityOutput = array(); // entities in output format,
using handles as keys
- protected static $loginSession = null;
protected static $loginUser = null;
- protected static $token = null;
public function setUp() {
- global $wgUser;
parent::setUp();
- static $hasSites = false;
-
- if ( !$hasSites ) {
- \TestSites::insertIntoDb();
- $hasSites = true;
- }
+ \TestSites::insertIntoDb();
self::$usepost = Settings::get( 'apiInDebug' ) ? Settings::get(
'apiDebugWithPost' ) : true;
self::$usetoken = Settings::get( 'apiInDebug' ) ?
Settings::get( 'apiDebugWithTokens' ) : true;
self::$userights = Settings::get( 'apiInDebug' ) ?
Settings::get( 'apiDebugWithRights' ) : true;
- ApiTestCase::$users['wbeditor'] = new TestUser(
+ self::$users['wbeditor'] = new TestUser(
'Apitesteditor',
'Api Test Editor',
'[email protected]',
array( 'wbeditor' )
);
- $wgUser = self::$users['wbeditor']->user;
+ $this->setMwGlobals( array(
+ 'wgUser' => self::$users['wbeditor']->user,
+ ) );
$this->login();
-
- //TODO: preserve session and token between calls?!
- self::$loginSession = false;
- self::$token = false;
self::initEntities();
}
@@ -104,9 +94,8 @@
}
self::$entityInput = array();
- $data = self::makeEntityData();
- foreach ( $data as $entity ) {
+ foreach ( self::makeEntityData() as $entity ) {
self::$entityInput[ $entity['handle'] ] = $entity;
}
}
@@ -116,7 +105,7 @@
* This data is used in particular by createEntities().
* Note that test Entities are identified by "handles".
*/
- static function makeEntityData() {
+ protected static function makeEntityData() {
return array(
array(
"handle" => "Empty",
@@ -262,9 +251,9 @@
* Performs a login, if necessary, and returns the resulting session.
*/
function login( $user = 'wbeditor' ) {
- self::doLogin( $user );
+ $data = self::doLogin( $user );
self::$loginUser = self::$users[ $user ];
- return self::$loginSession;
+ return $data;
}
/**
@@ -284,42 +273,24 @@
return;
}
- self::initEntities();
- $token = $this->getToken();
-
- foreach ( self::$entityInput as $entity ) {
+ foreach ( self::getEntityInput() as $entity ) {
$handle = $entity['handle'];
- $createdEntity = $this->setEntity( $entity, $token );
+ $createdEntity = $this->setEntity( $entity );
self::$entityOutput[ $handle ] = $createdEntity;
}
}
/**
- * Restores all well known entities test in the database to their
original state.
- */
- function resetEntities() {
- $this->createEntities();
- $token = $this->getToken();
-
- foreach ( self::$entityInput as $handle => $entity ) {
- $entity['id'] = $this->getEntityId( $handle );
-
- $data = $this->setEntity( $entity, $token );
-
- self::$entityOutput[ $handle ] = $data;
- }
- }
-
- /**
* Restores the entity with the given handle to its original state
+ * @param $handle of entity to reset
+ * @return mixed
*/
function resetEntity( $handle ) {
$entity = $this->getEntityInput( $handle );
$entity['id'] = $this->getEntityId( $handle );
- $token = $this->getToken();
- $data = $this->setEntity( $entity, $token );
+ $data = $this->setEntity( $entity );
self::$entityOutput[ $handle ] = $data;
return $data;
@@ -327,13 +298,15 @@
/**
* Creates or updates a single entity in the database
+ * @param $data array|string data to set as array of json string
+ * @return mixed
+ * @throws \MWException
*/
- function setEntity( $data, $token ) {
+ function setEntity( $data ) {
$params = array(
'action' => 'wbeditentity',
'clear' => true,
'format' => 'json', // make sure IDs are used as keys.
- 'token' => $token,
);
if ( !is_string($data) ) {
@@ -353,12 +326,7 @@
$params['data'] = $data;
- list( $res,, ) = $this->doApiRequest(
- $params,
- null,
- false,
- self::$users['wbeditor']->user
- );
+ list( $res,, ) = $this->doApiRequestWithToken( $params );
if ( !isset( $res['success'] ) || !isset( $res['entity'] ) ) {
throw new \MWException( "failed to create entity" );
@@ -370,12 +338,17 @@
/**
* Returns the entity for the given handle, in input format.
*/
- static function getEntityInput( $handle ) {
+ static function getEntityInput( $handle = null ) {
+ self::initEntities();
+
+ if( $handle === null ){
+ return self::$entityInput;
+ }
+
if ( !is_string( $handle ) ) {
trigger_error( "bad handle: $handle", E_USER_ERROR );
}
- self::initEntities();
return self::$entityInput[ $handle ];
}
@@ -401,11 +374,9 @@
* data provider for passing each entity handle to the test function.
*/
function provideEntityHandles() {
- self::initEntities();
-
$handles = array();
- foreach ( self::$entityInput as $handle => $entity ) {
+ foreach ( self::getEntityInput() as $handle => $entity ) {
$handles[] = array( $handle );
}
@@ -416,9 +387,7 @@
* returns the list handles for the well known test entities.
*/
static function getEntityHandles() {
- self::initEntities();
-
- return array_keys( self::$entityInput );
+ return array_keys( self::getEntityInput() );
}
/**
--
To view, visit https://gerrit.wikimedia.org/r/77899
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibc025dc2871e32726e6a1a1765e8454d49958759
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits