jenkins-bot has submitted this change and it was merged.
Change subject: Refactor ModifyItemBase to ModifyEntityTestBase
......................................................................
Refactor ModifyItemBase to ModifyEntityTestBase
Will enable entities of all types to be created for api tests
Change-Id: I200a94eaa531cdc49631fa60915cc67c75073c10
---
M repo/Wikibase.classes.php
M repo/tests/phpunit/includes/EditEntityTest.php
M repo/tests/phpunit/includes/api/BotEditTest.php
M repo/tests/phpunit/includes/api/EditEntityTest.php
M repo/tests/phpunit/includes/api/EditPageTest.php
M repo/tests/phpunit/includes/api/GetEntitiesTest.php
M repo/tests/phpunit/includes/api/LangAttributeBase.php
M repo/tests/phpunit/includes/api/LinkTitlesTest.php
R repo/tests/phpunit/includes/api/ModifyEntityTestBase.php
M repo/tests/phpunit/includes/api/PermissionsTest.php
M repo/tests/phpunit/includes/api/SetAliasesTest.php
M repo/tests/phpunit/includes/api/SetDescriptionTest.php
M repo/tests/phpunit/includes/api/SetLabelTest.php
M repo/tests/phpunit/includes/api/SetQualifierTest.php
M repo/tests/phpunit/includes/api/SetSiteLinkTest.php
M repo/tests/phpunit/includes/content/EntityContentTest.php
16 files changed, 178 insertions(+), 170 deletions(-)
Approvals:
Daniel Kinzler: Looks good to me, approved
jenkins-bot: Verified
diff --git a/repo/Wikibase.classes.php b/repo/Wikibase.classes.php
index e953aea..4f7b4d0 100644
--- a/repo/Wikibase.classes.php
+++ b/repo/Wikibase.classes.php
@@ -164,7 +164,7 @@
// tests
'Wikibase\Test\TestItemContents' =>
'tests/phpunit/TestItemContents.php',
'Wikibase\Test\ActionTestCase' =>
'tests/phpunit/includes/actions/ActionTestCase.php',
- 'Wikibase\Test\Api\ModifyItemBase' =>
'tests/phpunit/includes/api/ModifyItemBase.php',
+ 'Wikibase\Test\Api\ModifyEntityTestBase' =>
'tests/phpunit/includes/api/ModifyEntityTestBase.php',
'Wikibase\Test\Api\LangAttributeBase' =>
'tests/phpunit/includes/api/LangAttributeBase.php',
'Wikibase\Test\EntityContentTest' =>
'tests/phpunit/includes/content/EntityContentTest.php',
'Wikibase\Test\EntityHandlerTest' =>
'tests/phpunit/includes/content/EntityHandlerTest.php',
diff --git a/repo/tests/phpunit/includes/EditEntityTest.php
b/repo/tests/phpunit/includes/EditEntityTest.php
index a2f91d0..9ec051e 100644
--- a/repo/tests/phpunit/includes/EditEntityTest.php
+++ b/repo/tests/phpunit/includes/EditEntityTest.php
@@ -7,7 +7,7 @@
use \Wikibase\ItemContent;
use \Wikibase\Item;
use \Status;
-use Wikibase\Test\Api\ModifyItemBase;
+use Wikibase\Test\Api\ModifyEntityTestBase;
/**
* Test EditEntity.
@@ -439,7 +439,7 @@
}
if ( $permissions !== null ) {
- ModifyItemBase::applyPermissions( array(
+ ModifyEntityTestBase::applyPermissions( array(
'*' => $permissions,
'user' => $permissions,
$group => $permissions,
diff --git a/repo/tests/phpunit/includes/api/BotEditTest.php
b/repo/tests/phpunit/includes/api/BotEditTest.php
index 5320abc..a513e91 100644
--- a/repo/tests/phpunit/includes/api/BotEditTest.php
+++ b/repo/tests/phpunit/includes/api/BotEditTest.php
@@ -56,7 +56,7 @@
* that hold the first tests in a pending state awaiting access to the
database.
* @group medium
*/
-class BotEditTest extends ModifyItemBase {
+class BotEditTest extends ModifyEntityTestBase {
protected static $baseOfItemIds = 1;
protected static $usepost;
@@ -112,7 +112,7 @@
* @depends testTokensAndRights
*/
function testSetItemTop() {
- $token = $this->getItemToken();
+ $token = $this->getEditToken();
$req = array(
'action' => 'wbeditentity',
@@ -139,7 +139,7 @@
* @dataProvider providerCreateItem
*/
function testCreateItem( $handle, $bot, $new, $data ) {
- $token = $this->getItemToken();
+ $token = $this->getEditToken();
$myid = null;
$req = array(
@@ -150,7 +150,7 @@
);
if ( !$new ) {
- $myid = $this->getItemId( $handle );
+ $myid = $this->getEntityId( $handle );
$req['id'] = $myid;
} else {
$req['new'] = 'item';
@@ -175,8 +175,8 @@
if ( $new ) {
// register new object for use by subsequent test cases
- $this->createItems(); // make sure self::$itemOutput is
initialized first.
- self::$itemOutput[$handle] = $second[0]['entity'];
+ $this->createEntities(); // make sure
self::$entityOutput is initialized first.
+ self::$entityOutput[$handle] = $second[0]['entity'];
$myid = $second[0]['entity']['id'];
}
diff --git a/repo/tests/phpunit/includes/api/EditEntityTest.php
b/repo/tests/phpunit/includes/api/EditEntityTest.php
index a238437..d59cc8c 100644
--- a/repo/tests/phpunit/includes/api/EditEntityTest.php
+++ b/repo/tests/phpunit/includes/api/EditEntityTest.php
@@ -53,7 +53,7 @@
* that hold the first tests in a pending state awaiting access to the
database.
* @group large
*/
-class EditEntityTest extends ModifyItemBase {
+class EditEntityTest extends ModifyEntityTestBase {
static public $id = null;
@@ -128,7 +128,7 @@
* Checks the creation of a property via the editEntity API module
*/
function testEditEntityCreateProperty() {
- $token = $this->getItemToken();
+ $token = $this->getEditToken();
$data =
'{"datatype":"string","labels":{"en":{"language":"en","value":"its a test!"}}}';
list($res,,) = $this->doApiRequest(
@@ -155,7 +155,7 @@
* note that upon completion the id will be stored for later reuse
*/
function testEditEntityWithToken() {
- $token = $this->getItemToken();
+ $token = $this->getEditToken();
list($res,,) = $this->doApiRequest(
array(
@@ -171,7 +171,7 @@
);
$this->assertSuccess( $res, 'entity', 'id' );
- $this->assertItemEquals( self::$expect, $res['entity'] );
+ $this->assertEntityEquals( self::$expect, $res['entity'] );
$this->assertRegExp( '/^q\d+$/',
$res['entity']['id'],
'Expected a qualfied ID with prefix' );
@@ -184,7 +184,7 @@
* Check failure to set the same entity again, without id
*/
function testEditEntityNoId() {
- $token = $this->getItemToken();
+ $token = $this->getEditToken();
$data = array( 'labels' => array(
"de" => array( "language" => "de", "value" =>
"Foo X" ),
@@ -216,7 +216,7 @@
* Check success of entity update with a valid id
*/
function testEditEntityWithId() {
- $token = $this->getItemToken();
+ $token = $this->getEditToken();
list($res,,) = $this->doApiRequest(
array(
@@ -237,14 +237,14 @@
// because the content stayed the same.
$this->assertSuccess( $res, 'entity', 'lastrevid' );
- $this->assertItemEquals( self::$expect, $res['entity'] );
+ $this->assertEntityEquals( self::$expect, $res['entity'] );
}
/**
* Check failure to set the same entity again, with illegal field
values in the json
*/
function testEditEntityWithIllegalData() {
- $token = $this->getItemToken();
+ $token = $this->getEditToken();
// these sets of failing data must be merged with an existing
entity
$failingData = array( //@todo: check each of these separately,
so we know that each one fails!
@@ -279,7 +279,7 @@
* Check success to set the same entity again, with legal field values
in the json
*/
function testEditEntityWithLegalData() {
- $token = $this->getItemToken();
+ $token = $this->getEditToken();
// request the test data from the entity itself
list($query,,) = $this->doApiRequest(
@@ -318,7 +318,7 @@
self::$users['wbeditor']->user
);
$this->assertSuccess( $res, 'entity', 'id' );
- $this->assertItemEquals( self::$expect,
$res['entity'] );
+ $this->assertEntityEquals( self::$expect,
$res['entity'] );
}
catch ( \UsageException $e ) {
$this->fail( "Got unexpected exception: $e" );
@@ -330,7 +330,7 @@
* Check if it possible to clear out the content of the object
*/
function testEditEntityEmptyData() {
- $token = $this->getItemToken();
+ $token = $this->getEditToken();
try {
list($res,,) = $this->doApiRequest(
@@ -347,7 +347,7 @@
self::$users['wbeditor']->user
);
$this->assertSuccess( $res, 'entity', 'id' );
- $this->assertItemEquals( array( 'id' => self::$id ),
$res['entity'] );
+ $this->assertEntityEquals( array( 'id' => self::$id ),
$res['entity'] );
}
catch ( \UsageException $e ) {
$this->fail( "Got unexpected exception: $e" );
@@ -460,7 +460,7 @@
* @dataProvider provideBadData
*/
function testEditEntityBadData( $data, $expectedErrorCode ) {
- $token = $this->getItemToken();
+ $token = $this->getEditToken();
try {
$this->doApiRequest(
@@ -572,8 +572,8 @@
* @dataProvider provideEditEntityData
*/
function testEditEntityData( $handle, $data, $expected = null ) {
- $id = $this->getItemId( $handle );
- $token = $this->getItemToken();
+ $id = $this->getEntityId( $handle );
+ $token = $this->getEditToken();
// wbsetentity
------------------------------------------------------
list($res,,) = $this->doApiRequest(
@@ -605,7 +605,7 @@
}
// check entity in database
-------------------------------------------
- $entity = $this->loadItem( $id );
+ $entity = $this->loadEntity( $id );
// check relevant entries
foreach ( $expected as $key => $exp ) {
@@ -615,7 +615,7 @@
}
// cleanup
------------------------------------------------------
- $this->resetItem( $handle );
+ $this->resetEntity( $handle );
}
static function flattenValues( $prop, $values ) {
diff --git a/repo/tests/phpunit/includes/api/EditPageTest.php
b/repo/tests/phpunit/includes/api/EditPageTest.php
index ebe0b57..7e863c9 100644
--- a/repo/tests/phpunit/includes/api/EditPageTest.php
+++ b/repo/tests/phpunit/includes/api/EditPageTest.php
@@ -45,7 +45,7 @@
* that hold the first tests in a pending state awaiting access to the
database.
* @group medium
*/
-class EditPageTest extends ModifyItemBase {
+class EditPageTest extends ModifyEntityTestBase {
/**
* @group API
@@ -58,7 +58,7 @@
$this->assertTrue( $status->isOK(), $status->getMessage() ); //
sanity check
$this->login();
- $token = $this->getItemToken();
+ $token = $this->getEditToken();
$content->getItem()->setLabel( "de", "Test" );
$data = $content->getItem()->toArray();
@@ -93,7 +93,7 @@
$page =
\Wikibase\EntityContentFactory::singleton()->getWikiPageForId( $id );
$this->login();
- $token = $this->getItemToken();
+ $token = $this->getEditToken();
$text = "hallo welt";
diff --git a/repo/tests/phpunit/includes/api/GetEntitiesTest.php
b/repo/tests/phpunit/includes/api/GetEntitiesTest.php
index 3bdd2cf..d0f5c0f 100644
--- a/repo/tests/phpunit/includes/api/GetEntitiesTest.php
+++ b/repo/tests/phpunit/includes/api/GetEntitiesTest.php
@@ -46,15 +46,15 @@
* that hold the first tests in a pending state awaiting access to the
database.
* @group medium
*/
-class GetEntitiesTest extends ModifyItemBase {
+class GetEntitiesTest extends ModifyEntityTestBase {
/**
- * @dataProvider provideItemHandles
+ * @dataProvider provideEntityHandles
*/
function testGetItemById( $handle ) {
- $this->createItems();
+ $this->createEntities();
- $item = $this->getItemOutput( $handle );
+ $item = $this->getEntityOutput( $handle );
$id = $item['id'];
list($res,,) = $this->doApiRequest(
@@ -65,7 +65,7 @@
);
$this->assertSuccess( $res, 'entities', $id );
- $this->assertItemEquals( $item, $res['entities'][$id] );
+ $this->assertEntityEquals( $item, $res['entities'][$id] );
$this->assertEquals( 1, count( $res['entities'] ), "requesting
a single item should return exactly one item entry" );
// This should be correct for all items we are testing
$this->assertEquals( \Wikibase\Item::ENTITY_TYPE,
$res['entities'][$id]['type'] );
@@ -93,12 +93,12 @@
}
/**
- * @dataProvider provideItemHandles
+ * @dataProvider provideEntityHandles
*/
function testGetItemByPrefixedId( $handle ) {
- $this->createItems();
+ $this->createEntities();
- $item = $this->getItemOutput( $handle );
+ $item = $this->getEntityOutput( $handle );
$id = $item['id'];
list($res,,) = $this->doApiRequest(
@@ -109,15 +109,15 @@
);
$this->assertSuccess( $res, 'entities', $id );
- $this->assertItemEquals( $item, $res['entities'][$id] );
+ $this->assertEntityEquals( $item, $res['entities'][$id] );
}
public static function provideGetItemByTitle() {
$calls = array();
- $handles = static::getItemHandles();
+ $handles = static::getEntityHandles();
foreach ( $handles as $handle ) {
- $item = static::getItemInput( $handle );
+ $item = static::getEntityInput( $handle );
if ( !isset( $item['sitelinks'] ) ) {
continue;
@@ -145,11 +145,11 @@
'format' => 'json', // make sure IDs are used as keys
) );
- $item = $this->getItemOutput( $handle );
+ $item = $this->getEntityOutput( $handle );
$id = $item['id'];
$this->assertSuccess( $res, 'entities', $id );
- $this->assertItemEquals( $item, $res['entities'][$id] );
+ $this->assertEntityEquals( $item, $res['entities'][$id] );
$this->assertEquals( 1, count( $res['entities'] ), "requesting
a single item should return exactly one item entry" );
}
@@ -237,8 +237,8 @@
* @group API
*/
public function testGetEntitiesMultipleIds() {
- $handles = $this->getItemHandles();
- $ids = array_map( array( $this, 'getItemId' ), $handles );
+ $handles = $this->getEntityHandles();
+ $ids = array_map( array( $this, 'getEntityId' ), $handles );
list( $res,, ) = $this->doApiRequest( array(
'action' => 'wbgetentities',
@@ -276,7 +276,7 @@
$this->assertEquals( count( $titles ), count( $res['entities']
), "the actual number of items differs from the number of requested items" );
foreach ( $handles as $handle ) {
- $id = $this->getItemId( $handle );
+ $id = $this->getEntityId( $handle );
$this->assertArrayHasKey( $id, $res['entities'],
"missing item" );
$this->assertEquals( $id, $res['entities'][$id]['id'],
"bad ID" );
@@ -297,9 +297,9 @@
* @dataProvider provideLanguages
*/
function testLanguages( $handle, $languages ) {
- $this->createItems();
+ $this->createEntities();
- $id = $this->getItemId( $handle );
+ $id = $this->getEntityId( $handle );
list($res,,) = $this->doApiRequest(
array(
@@ -351,9 +351,9 @@
* @dataProvider provideProps
*/
function testProps( $handle, $props, $expectedProps ) {
- $this->createItems();
+ $this->createEntities();
- $id = $this->getItemId( $handle );
+ $id = $this->getEntityId( $handle );
list($res,,) = $this->doApiRequest(
array(
@@ -384,8 +384,8 @@
* @dataProvider provideSitelinkUrls
*/
function testSitelinkUrls( $handle ) {
- $this->createItems();
- $id = $this->getItemId( $handle );
+ $this->createEntities();
+ $id = $this->getEntityId( $handle );
list($res,,) = $this->doApiRequest(
array(
@@ -429,8 +429,8 @@
* @dataProvider provideSitelinkSorting
*/
function testSitelinkSorting( $handle ) {
- $this->createItems();
- $id = $this->getItemId( $handle );
+ $this->createEntities();
+ $id = $this->getEntityId( $handle );
list($res,,) = $this->doApiRequest(
array(
@@ -474,9 +474,9 @@
* @dataProvider providerGetItemFormat
*/
function testGetItemFormat( $format, $usekeys ) {
- $this->createItems();
+ $this->createEntities();
- $item = $this->getItemOutput( 'Berlin' );
+ $item = $this->getEntityOutput( 'Berlin' );
$id = $item['id'];
list($res,,) = $this->doApiRequest(
diff --git a/repo/tests/phpunit/includes/api/LangAttributeBase.php
b/repo/tests/phpunit/includes/api/LangAttributeBase.php
index 908c0b8..aeb69ff 100644
--- a/repo/tests/phpunit/includes/api/LangAttributeBase.php
+++ b/repo/tests/phpunit/includes/api/LangAttributeBase.php
@@ -58,7 +58,7 @@
* @author John Erling Blad < [email protected] >
* @author Daniel Kinzler
*/
-abstract class LangAttributeBase extends ModifyItemBase {
+abstract class LangAttributeBase extends ModifyEntityTestBase {
public static function makeOverlyLongString( $text = "Test", $length =
null ) {
if ( $length === null ) {
@@ -76,11 +76,11 @@
* @dataProvider paramProvider
*/
public function doLanguageAttribute( $handle, $action, $attr,
$langCode, $value, $exception = null ) {
- $id = $this->getItemId( $handle );
+ $id = $this->getEntityId( $handle );
// update the item
----------------------------------------------------------------
$req = array(
- 'token' => $this->getItemToken(),
+ 'token' => $this->getEditToken(),
'id' => $id,
'action' => $action,
'language' => $langCode,
@@ -126,7 +126,7 @@
}
// check item in the database
----------------------------------------------------------------
- $item = $this->loadItem( $id );
+ $item = $this->loadEntity( $id );
$values = self::flattenArray( $item[$section], 'language',
'value' );
if ( $value !== '' ) {
@@ -141,7 +141,7 @@
$apiResponse['entity']['lastrevid'] );
// cleanup
----------------------------------------------------------------
- $this->resetItem( $handle );
+ $this->resetEntity( $handle );
}
}
diff --git a/repo/tests/phpunit/includes/api/LinkTitlesTest.php
b/repo/tests/phpunit/includes/api/LinkTitlesTest.php
index 7cdfb86..e205f06 100644
--- a/repo/tests/phpunit/includes/api/LinkTitlesTest.php
+++ b/repo/tests/phpunit/includes/api/LinkTitlesTest.php
@@ -45,7 +45,7 @@
* that hold the first tests in a pending state awaiting access to the
database.
* @group medium
*/
-class LinkTitlesTest extends ModifyItemBase {
+class LinkTitlesTest extends ModifyEntityTestBase {
public function testLinkTitlesWithNoToken( ) {
if ( !self::$usetoken ) {
@@ -130,10 +130,10 @@
* @dataProvider provideLinkTitles
*/
public function testLinkTitles( $handle, $item_spec, $fromsite,
$fromtitle, $tosite, $totitle, $expectedFailure = null ) {
- $token = $this->getItemToken();
+ $token = $this->getEditToken();
if ( $handle ) {
- $id = $this->getItemId( $handle );
- $this->resetItem( $handle ); //nasty. we shouldn't need
to do this. But apparently some other test spills bad state.
+ $id = $this->getEntityId( $handle );
+ $this->resetEntity( $handle ); //nasty. we shouldn't
need to do this. But apparently some other test spills bad state.
}
// set the sitelink -------------------------------
@@ -171,7 +171,7 @@
// check the item in the database
-------------------------------
if ( isset( $id ) ) {
- $item = $this->loadItem( $id );
+ $item = $this->loadEntity( $id );
$links = self::flattenArray(
$item['sitelinks'], 'site', 'title' );
$this->assertEquals( $fromtitle,
$links[$fromsite], 'wrong link target' );
$this->assertEquals( $totitle, $links[$tosite],
'wrong link target' );
@@ -185,7 +185,7 @@
// clean up, but note that we can't clean up newly created
items -------------------------------
if ( $handle ) {
- $this->resetItem( $handle );
+ $this->resetEntity( $handle );
}
$this->assertTrue( true );
diff --git a/repo/tests/phpunit/includes/api/ModifyItemBase.php
b/repo/tests/phpunit/includes/api/ModifyEntityTestBase.php
similarity index 82%
rename from repo/tests/phpunit/includes/api/ModifyItemBase.php
rename to repo/tests/phpunit/includes/api/ModifyEntityTestBase.php
index 5a551d3..4a5953b 100644
--- a/repo/tests/phpunit/includes/api/ModifyItemBase.php
+++ b/repo/tests/phpunit/includes/api/ModifyEntityTestBase.php
@@ -12,7 +12,7 @@
* The tests are using "Database" to get its own set of temporal tables.
* This is nice so we avoid poisoning an existing database.
*
- * The tests are using "medium" so they are able to run alittle longer before
they are killed.
+ * The tests are using "medium" so they are able to run a little longer before
they are killed.
* Without this they will be killed after 1 second, but the setup of the
tables takes so long
* time that the first few tests get killed.
*
@@ -47,14 +47,14 @@
* @author John Erling Blad < [email protected] >
* @author Daniel Kinzler
*/
-abstract class ModifyItemBase extends ApiTestCase {
+abstract class ModifyEntityTestBase extends ApiTestCase {
protected static $usepost;
protected static $usetoken;
protected static $userights;
- protected static $itemInput = null; // items in input format, using
handles as keys
- protected static $itemOutput = array(); // items in output format,
using handles as keys
+ 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;
@@ -107,39 +107,41 @@
self::$loginSession = false;
self::$token = false;
- self::initItems();
+ self::initEntities();
$this->setUpComplete = true;
}
/**
- * Initializes the static list of item input structures, using data
from makeItemData().
- * Note that test items are identified by "handles".
+ * Initializes the static list of entity input structures, using data
from makeEntityData().
+ * Note that test entities are identified by "handles".
*/
- protected static function initItems() {
- if ( self::$itemInput ) {
+ protected static function initEntities() {
+ if ( self::$entityInput ) {
return;
}
- self::$itemInput = array();
- $data = self::makeItemData();
+ self::$entityInput = array();
+ $data = self::makeEntityData();
- foreach ( $data as $item ) {
- self::$itemInput[ $item['handle'] ] = $item;
+ foreach ( $data as $entity ) {
+ self::$entityInput[ $entity['handle'] ] = $entity;
}
}
/**
- * Provides the item data that is to be used as input for creating the
test environment.
- * This data is used in particular by createItems().
- * Note that test items are identified by "handles".
+ * Provides the entity data that is to be used as input for creating
the test environment.
+ * This data is used in particular by createEntities().
+ * Note that test Entities are identified by "handles".
*/
- static function makeItemData() {
+ static function makeEntityData() {
return array(
array(
"handle" => "Empty",
+ "type" => "item",
),
array(
"handle" => "Berlin",
+ "type" => "item",
"sitelinks" => array(
array( "site" => "dewiki", "title" =>
"Berlin" ),
array( "site" => "enwiki", "title" =>
"Berlin" ),
@@ -166,6 +168,7 @@
),
array(
"handle" => "London",
+ "type" => "item",
"sitelinks" => array(
array( "site" => "enwiki", "title" =>
"London" ),
array( "site" => "dewiki", "title" =>
"London" ),
@@ -201,6 +204,7 @@
),
array(
"handle" => "Oslo",
+ "type" => "item",
"sitelinks" => array(
array( "site" => "dewiki", "title" =>
"Oslo" ),
array( "site" => "enwiki", "title" =>
"Oslo" ),
@@ -235,6 +239,7 @@
),
array(
"handle" => "Episkopi",
+ "type" => "item",
"sitelinks" => array(
array( "site" => "dewiki", "title" =>
"Episkopi Cantonment" ),
array( "site" => "enwiki", "title" =>
"Episkopi Cantonment" ),
@@ -258,6 +263,7 @@
),
array(
"handle" => "Leipzig",
+ "type" => "item",
"labels" => array(
array( "language" => "de", "value" =>
"Leipzig" ),
),
@@ -315,9 +321,9 @@
}
/**
- * Gets an item edit token. Returns a cached token if available.
+ * Gets an entity edit token. Returns a cached token if available.
*/
- function getItemToken() {
+ function getEditToken() {
$this->init();
if ( !self::$usetoken ) {
@@ -343,54 +349,54 @@
}
/**
- * Initializes the test environment with the items defined by
makeItemData() by creating these
- * items in the database.
+ * Initializes the test environment with the entities defined by
makeEntityData() by creating these
+ * entities in the database.
*/
- function createItems() {
- if ( self::$itemOutput ) {
+ function createEntities() {
+ if ( self::$entityOutput ) {
return;
}
- self::initItems();
- $token = $this->getItemToken();
+ self::initEntities();
+ $token = $this->getEditToken();
- foreach ( self::$itemInput as $item ) {
- $handle = $item['handle'];
- $createdItem = $this->setItem( $item, $token );
+ foreach ( self::$entityInput as $entity ) {
+ $handle = $entity['handle'];
+ $createdEntity = $this->setEntity( $entity, $token );
- self::$itemOutput[ $handle ] = $createdItem;
+ self::$entityOutput[ $handle ] = $createdEntity;
}
}
/**
- * Restores all well known items test in the database to their original
state.
+ * Restores all well known entities test in the database to their
original state.
*/
- function resetItems() {
- $this->createItems();
- $token = $this->getItemToken();
+ function resetEntities() {
+ $this->createEntities();
+ $token = $this->getEditToken();
- foreach ( self::$itemInput as $handle => $item ) {
- $item['id'] = $this->getItemId( $handle );
+ foreach ( self::$entityInput as $handle => $entity ) {
+ $entity['id'] = $this->getEntityId( $handle );
- $this->setItem( $item, $token );
+ $this->setEntity( $entity, $token );
}
}
/**
- * Restores the item with the given handle to its original state
+ * Restores the entity with the given handle to its original state
*/
- function resetItem( $handle ) {
- $item = $this->getItemInput( $handle );
- $item['id'] = $this->getItemId( $handle );
+ function resetEntity( $handle ) {
+ $entity = $this->getEntityInput( $handle );
+ $entity['id'] = $this->getEntityId( $handle );
- $token = $this->getItemToken();
- return $this->setItem( $item, $token );
+ $token = $this->getEditToken();
+ return $this->setEntity( $entity, $token );
}
/**
- * Creates or updates a single item in the database
+ * Creates or updates a single entity in the database
*/
- function setItem( $data, $token ) {
+ function setEntity( $data, $token ) {
$params = array(
'action' => 'wbeditentity',
'format' => 'json', // make sure IDs are used as keys.
@@ -404,8 +410,10 @@
$params['id'] = $data['id'];
unset( $data['id'] );
} else {
- $params['new'] = 'item';
+ $params['new'] = $data['type'];
}
+
+ unset( $data['type'] );
$data = json_encode( $data );
}
@@ -420,51 +428,51 @@
);
if ( !isset( $res['success'] ) || !isset( $res['entity'] ) ) {
- throw new \MWException( "failed to create item" );
+ throw new \MWException( "failed to create entity" );
}
return $res['entity'];
}
/**
- * Returns the item for the given handle, in input format.
+ * Returns the entity for the given handle, in input format.
*/
- static function getItemInput( $handle ) {
+ static function getEntityInput( $handle ) {
if ( !is_string( $handle ) ) {
trigger_error( "bad handle: $handle", E_USER_ERROR );
}
- self::initItems();
- return self::$itemInput[ $handle ];
+ self::initEntities();
+ return self::$entityInput[ $handle ];
}
/**
- * Returns the item for the given handle, in output format.
- * Will initialize the database with test items if necessary.
+ * Returns the entity for the given handle, in output format.
+ * Will initialize the database with test entities if necessary.
*/
- function getItemOutput( $handle ) {
- $this->createItems();
- return self::$itemOutput[ $handle ];
+ function getEntityOutput( $handle ) {
+ $this->createEntities();
+ return self::$entityOutput[ $handle ];
}
/**
- * Returns the database id for the given item handle.
- * Will initialize the database with test items if necessary.
+ * Returns the database id for the given entity handle.
+ * Will initialize the database with test entities if necessary.
*/
- function getItemId( $handle ) {
- $item = $this->getItemOutput( $handle );
- return $item['id'];
+ function getEntityId( $handle ) {
+ $entity = $this->getEntityOutput( $handle );
+ return $entity['id'];
}
/**
- * data provider for passing each item handle to the test function.
+ * data provider for passing each entity handle to the test function.
*/
- function provideItemHandles() {
- self::initItems();
+ function provideEntityHandles() {
+ self::initEntities();
$handles = array();
- foreach ( self::$itemInput as $handle => $item ) {
+ foreach ( self::$entityInput as $handle => $entity ) {
$handles[] = array( $handle );
}
@@ -472,18 +480,18 @@
}
/**
- * returns the list handles for the well known test items.
+ * returns the list handles for the well known test entities.
*/
- static function getItemHandles() {
- self::initItems();
+ static function getEntityHandles() {
+ self::initEntities();
- return array_keys( self::$itemInput );
+ return array_keys( self::$entityInput );
}
/**
- * Loads an item from the database (via an API call).
+ * Loads an entity from the database (via an API call).
*/
- function loadItem( $id ) {
+ function loadEntity( $id ) {
list($res,,) = $this->doApiRequest(
array(
'action' => 'wbgetentities',
@@ -580,13 +588,13 @@
}
/**
- * Compares two item structures and asserts that they are equal. Only
fields present in $expected are considered.
+ * Compares two entity structures and asserts that they are equal. Only
fields present in $expected are considered.
* $expected and $actual can both be either in "flat" or in "deep"
form, they are converted as needed before comparison.
*
* @param $expected
* @param $actual
*/
- public function assertItemEquals( $expected, $actual ) {
+ public function assertEntityEquals( $expected, $actual ) {
if ( isset( $expected['id'] ) ) {
$this->assertEquals( $expected['id'], $actual['id'] );
}
diff --git a/repo/tests/phpunit/includes/api/PermissionsTest.php
b/repo/tests/phpunit/includes/api/PermissionsTest.php
index 59059b7..b57cc52 100644
--- a/repo/tests/phpunit/includes/api/PermissionsTest.php
+++ b/repo/tests/phpunit/includes/api/PermissionsTest.php
@@ -48,7 +48,7 @@
* that hold the first tests in a pending state awaiting access to the
database.
* @group medium
*/
-class PermissionsTest extends ModifyItemBase {
+class PermissionsTest extends ModifyEntityTestBase {
protected $permissions;
protected $old_user;
@@ -170,7 +170,7 @@
*/
function testGetEntities( $permissions, $expectedError ) {
$params = array(
- 'ids' => $this->getItemId( "Oslo" ),
+ 'ids' => $this->getEntityId( "Oslo" ),
);
$this->doPermissionsTest( 'wbgetentities', $params,
$permissions, $expectedError );
@@ -241,7 +241,7 @@
$dbw->delete( 'wb_items_per_site', '*', __METHOD__ );
$params = array(
- 'id' => $this->getItemId( "Oslo" ),
+ 'id' => $this->getEntityId( "Oslo" ),
'linksite' => 'enwiki',
'linktitle' => 'Oslo',
);
@@ -268,7 +268,7 @@
*/
function testSetLabel( $permissions, $expectedError ) {
$params = array(
- 'id' => $this->getItemId( "Oslo" ),
+ 'id' => $this->getEntityId( "Oslo" ),
'language' => 'de',
'value' => 'Oslo',
);
@@ -295,7 +295,7 @@
*/
function testSetDescription( $permissions, $expectedError ) {
$params = array(
- 'id' => $this->getItemId( "Oslo" ),
+ 'id' => $this->getEntityId( "Oslo" ),
'language' => 'en',
'value' => 'Capitol of Norway',
);
diff --git a/repo/tests/phpunit/includes/api/SetAliasesTest.php
b/repo/tests/phpunit/includes/api/SetAliasesTest.php
index 423530c..28a152a 100644
--- a/repo/tests/phpunit/includes/api/SetAliasesTest.php
+++ b/repo/tests/phpunit/includes/api/SetAliasesTest.php
@@ -2,7 +2,7 @@
namespace Wikibase\Test\Api;
use ApiTestCase;
-//use Wikibase\Test\ModifyItemBase;
+//use Wikibase\Test\ModifyEntityTestBase;
/**
* Tests for the ApiSetAliases API module.
@@ -59,7 +59,7 @@
* @licence GNU GPL v2+
* @author Jeroen De Dauw < [email protected] >
*/
-class SetAliasesTest extends ModifyItemBase {
+class SetAliasesTest extends ModifyEntityTestBase {
public function paramProvider() {
return array(
@@ -86,12 +86,12 @@
* @dataProvider paramProvider
*/
public function testSetAliases( $handle, $langCode, $op, $value,
$expected ) {
- $id = $this->getItemId( $handle );
+ $id = $this->getEntityId( $handle );
$expected = $expected === '' ? array() : explode( '|',
$expected );
// update the item
----------------------------------------------------------------
$req = array(
- 'token' => $this->getItemToken(),
+ 'token' => $this->getEditToken(),
'id' => $id,
'action' => 'wbsetaliases',
'language' => $langCode,
@@ -115,7 +115,7 @@
}
// check item in database
--------------------------------------------------
- $item = $this->loadItem( $id );
+ $item = $this->loadEntity( $id );
$aliases = self::flattenArray( $item['aliases'], 'language',
'value', true );
$actual = isset( $aliases[ $langCode ] ) ? $aliases[ $langCode
] : array();
@@ -130,7 +130,7 @@
public function testSetAliases_length( ) {
$handle = 'Oslo';
- $id = $this->getItemId( $handle );
+ $id = $this->getEntityId( $handle );
$langCode = 'en';
$op = 'add';
$value = LangAttributeBase::makeOverlyLongString();
@@ -138,7 +138,7 @@
// update the item
----------------------------------------------------------------
$req = array(
- 'token' => $this->getItemToken(),
+ 'token' => $this->getEditToken(),
'id' => $id,
'action' => 'wbsetaliases',
'language' => $langCode,
@@ -162,7 +162,7 @@
$badId = 'xyz123+++';
$req = array(
- 'token' => $this->getItemToken(),
+ 'token' => $this->getEditToken(),
'id' => $badId,
'action' => 'wbsetaliases',
'language' => 'en',
@@ -184,7 +184,7 @@
* @dataProvider paramProvider
*/
public function testReset( $handle ) {
- $this->resetItem( $handle );
+ $this->resetEntity( $handle );
$this->assertTrue( true );
}
}
\ No newline at end of file
diff --git a/repo/tests/phpunit/includes/api/SetDescriptionTest.php
b/repo/tests/phpunit/includes/api/SetDescriptionTest.php
index 50c3222..0bc59d5 100644
--- a/repo/tests/phpunit/includes/api/SetDescriptionTest.php
+++ b/repo/tests/phpunit/includes/api/SetDescriptionTest.php
@@ -77,7 +77,7 @@
*/
public function testLanguageAttribute( $handle, $langCode, $value,
$exception = null ) {
$this->doLanguageAttribute( $handle, 'wbsetdescription',
'description', $langCode, $value, $exception );
- $this->getItemId( $handle );
+ $this->getEntityId( $handle );
}
}
diff --git a/repo/tests/phpunit/includes/api/SetLabelTest.php
b/repo/tests/phpunit/includes/api/SetLabelTest.php
index 90a2c80..c0e79d8 100644
--- a/repo/tests/phpunit/includes/api/SetLabelTest.php
+++ b/repo/tests/phpunit/includes/api/SetLabelTest.php
@@ -77,7 +77,7 @@
*/
public function testLanguageAttribute( $handle, $langCode, $value,
$exception = null ) {
$this->doLanguageAttribute( $handle, 'wbsetlabel', 'label',
$langCode, $value, $exception );
- $id = $this->getItemId( $handle );
+ $id = $this->getEntityId( $handle );
}
}
diff --git a/repo/tests/phpunit/includes/api/SetQualifierTest.php
b/repo/tests/phpunit/includes/api/SetQualifierTest.php
index a0a1018..e8ed394 100644
--- a/repo/tests/phpunit/includes/api/SetQualifierTest.php
+++ b/repo/tests/phpunit/includes/api/SetQualifierTest.php
@@ -46,7 +46,7 @@
* @author Katie Filbert < [email protected] >
* @author Daniel Kinzler
*/
-class SetQualifierTest extends ModifyItemBase {
+class SetQualifierTest extends ModifyEntityTestBase {
/**
* @return Snak[]
@@ -172,7 +172,7 @@
}
protected function makeAddRequest( $statementGuid, Snak $qualifier,
EntityId $entityId ) {
- $token = $this->getItemToken();
+ $token = $this->getEditToken();
$params = array(
'action' => 'wbsetqualifier',
diff --git a/repo/tests/phpunit/includes/api/SetSiteLinkTest.php
b/repo/tests/phpunit/includes/api/SetSiteLinkTest.php
index 4d61654..48a1126 100644
--- a/repo/tests/phpunit/includes/api/SetSiteLinkTest.php
+++ b/repo/tests/phpunit/includes/api/SetSiteLinkTest.php
@@ -46,7 +46,7 @@
* that hold the first tests in a pending state awaiting access to the
database.
* @group medium
*/
-class SetSiteLinkTest extends ModifyItemBase {
+class SetSiteLinkTest extends ModifyEntityTestBase {
public function setup() {
parent::setup();
@@ -60,7 +60,7 @@
}
public function testSetLiteLinkWithNoId( ) {
- $token = $this->getItemToken();
+ $token = $this->getEditToken();
$req = array(
'action' => 'wbsetsitelink',
@@ -79,7 +79,7 @@
}
public function testSetLiteLinkWithBadId( ) {
- $token = $this->getItemToken();
+ $token = $this->getEditToken();
$req = array(
'action' => 'wbsetsitelink',
@@ -99,7 +99,7 @@
}
public function testSetLiteLinkWithBadSite( ) {
- $token = $this->getItemToken();
+ $token = $this->getEditToken();
$req = array(
'action' => 'wbsetsitelink',
@@ -120,7 +120,7 @@
}
public function testSetLiteLinkWithBadTitle( ) {
- $token = $this->getItemToken();
+ $token = $this->getEditToken();
$req = array(
'action' => 'wbsetsitelink',
@@ -148,7 +148,7 @@
$req = array(
'action' => 'wbsetsitelink',
- 'id' => $this->getItemId( "Berlin" ),
+ 'id' => $this->getEntityId( "Berlin" ),
'linksite' => "enwiki",
'linktitle' => "testSetLiteLinkWithNoToken",
);
@@ -195,10 +195,10 @@
* @dataProvider provideSetLiteLink
*/
public function testSetLiteLink( $handle, $item_spec, $linksite,
$linktitle, $expectedTitle = null, $expectedFailure = null ) {
- $token = $this->getItemToken();
- $id = $this->getItemId( $handle );
+ $token = $this->getEditToken();
+ $id = $this->getEntityId( $handle );
- $this->resetItem( $handle ); //nasty. we shouldn't need to do
this. But apparently some other test spills bad state.
+ $this->resetEntity( $handle ); //nasty. we shouldn't need to do
this. But apparently some other test spills bad state.
if ( array_key_exists( 'id', $item_spec ) && empty(
$item_spec['id'] ) ) {
//NOTE: data provider is called before setUp and thus
can't determine IDs.
@@ -261,7 +261,7 @@
}
// check the item in the database
-------------------------------
- $item = $this->loadItem( $id );
+ $item = $this->loadEntity( $id );
$links = self::flattenArray( $item['sitelinks'], 'site',
'title' );
if ( $linktitle === '' ) {
@@ -275,11 +275,11 @@
}
// clean up -------------------------------
- $this->resetItem( $handle );
+ $this->resetEntity( $handle );
}
public function testSetLiteLinkWithBadTargetSite( ) {
- $token = $this->getItemToken();
+ $token = $this->getEditToken();
$req = array(
'action' => 'wbsetsitelink',
diff --git a/repo/tests/phpunit/includes/content/EntityContentTest.php
b/repo/tests/phpunit/includes/content/EntityContentTest.php
index d78b502..099897b 100644
--- a/repo/tests/phpunit/includes/content/EntityContentTest.php
+++ b/repo/tests/phpunit/includes/content/EntityContentTest.php
@@ -2,7 +2,7 @@
namespace Wikibase\Test;
use Wikibase\EntityContent;
-use Wikibase\Test\Api\ModifyItemBase;
+use Wikibase\Test\Api\ModifyEntityTestBase;
/**
* Tests for the Wikibase\EntityContent class.
@@ -256,7 +256,7 @@
}
if ( $permissions !== null ) {
- ModifyItemBase::applyPermissions( array(
+ ModifyEntityTestBase::applyPermissions( array(
'*' => $permissions,
'user' => $permissions,
$group => $permissions,
--
To view, visit https://gerrit.wikimedia.org/r/72316
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I200a94eaa531cdc49631fa60915cc67c75073c10
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Anja Jentzsch <[email protected]>
Gerrit-Reviewer: Ataherivand <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Daniel Werner <[email protected]>
Gerrit-Reviewer: Denny Vrandecic <[email protected]>
Gerrit-Reviewer: Henning Snater <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Jens Ohlig <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: John Erling Blad <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Liangent <[email protected]>
Gerrit-Reviewer: Lydia Pintscher <[email protected]>
Gerrit-Reviewer: Markus Kroetzsch <[email protected]>
Gerrit-Reviewer: Nikola Smolenski <[email protected]>
Gerrit-Reviewer: Nilesh <[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