Hoo man has uploaded a new change for review.
https://gerrit.wikimedia.org/r/244216
Change subject: Add integration tests for Lua in process caching
......................................................................
Add integration tests for Lua in process caching
Ugly given the way Scribunto initializes stuff, but it works.
Change-Id: Iba405dfa98c9dc5e828f3910979e9d3e5d7d231e
---
M client/tests/phpunit/MockClientStore.php
M
client/tests/phpunit/includes/DataAccess/PropertyParserFunction/PropertyParserFunctionIntegrationTest.php
A
client/tests/phpunit/includes/DataAccess/Scribunto/LuaWikibaseLibraryInProcessEntityCacheTests.lua
A
client/tests/phpunit/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseInProcessEntityCacheTest.php
M
client/tests/phpunit/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseLibraryTest.php
M
client/tests/phpunit/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseLibraryTestCase.php
6 files changed, 138 insertions(+), 14 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/16/244216/1
diff --git a/client/tests/phpunit/MockClientStore.php
b/client/tests/phpunit/MockClientStore.php
index 6a10b3f..2b88494 100644
--- a/client/tests/phpunit/MockClientStore.php
+++ b/client/tests/phpunit/MockClientStore.php
@@ -8,6 +8,7 @@
use Wikibase\Client\Usage\NullUsageTracker;
use Wikibase\ClientStore;
use Wikibase\DataModel\Services\Entity\NullEntityPrefetcher;
+use Wikibase\DataModel\Services\Lookup\EntityLookup;
use Wikibase\PropertyInfoStore;
use Wikibase\Store\EntityIdLookup;
use Wikibase\TermIndex;
@@ -43,6 +44,11 @@
* @var PropertyInfoStore|null
*/
private static $propertyInfoStore = null;
+
+ /**
+ * @var EntityLookup|null
+ */
+ private static $entityLookup = null;
/**
* @see ClientStore::getUsageLookup
@@ -137,10 +143,21 @@
/**
* @see ClientStore::getEntityLookup
*
- * @return MockRepository
+ * @return EntityLookup
*/
public function getEntityLookup() {
- return $this->getMockRepository();
+ if ( !self::$entityLookup ) {
+ return $this->getMockRepository();
+ }
+
+ return self::$entityLookup;
+ }
+
+ /**
+ * @param EntityLookup|null $entityLookup
+ */
+ public function setEntityLookup( EntityLookup $entityLookup = null ) {
+ return self::$entityLookup = $entityLookup;
}
/**
diff --git
a/client/tests/phpunit/includes/DataAccess/PropertyParserFunction/PropertyParserFunctionIntegrationTest.php
b/client/tests/phpunit/includes/DataAccess/PropertyParserFunction/PropertyParserFunctionIntegrationTest.php
index 9e5630f..50b3440 100644
---
a/client/tests/phpunit/includes/DataAccess/PropertyParserFunction/PropertyParserFunctionIntegrationTest.php
+++
b/client/tests/phpunit/includes/DataAccess/PropertyParserFunction/PropertyParserFunctionIntegrationTest.php
@@ -38,9 +38,9 @@
}
$this->assertInstanceOf(
- 'Wikibase\Test\MockRepository',
- $wikibaseClient->getStore()->getEntityLookup(),
- 'Mocking the default client EntityLookup failed'
+ 'Wikibase\Test\MockClientStore',
+ $wikibaseClient->getStore(),
+ 'Mocking the default ClientStore failed'
);
$this->setMwGlobals( 'wgContLang', Language::factory( 'de' ) );
diff --git
a/client/tests/phpunit/includes/DataAccess/Scribunto/LuaWikibaseLibraryInProcessEntityCacheTests.lua
b/client/tests/phpunit/includes/DataAccess/Scribunto/LuaWikibaseLibraryInProcessEntityCacheTests.lua
new file mode 100644
index 0000000..6cd9c93
--- /dev/null
+++
b/client/tests/phpunit/includes/DataAccess/Scribunto/LuaWikibaseLibraryInProcessEntityCacheTests.lua
@@ -0,0 +1,36 @@
+--[[
+ Integration tests verifiying that we cache entities in memory in the
right way.
+
+ @license GNU GPL v2+
+ @author Marius Hoch < [email protected] >
+]]
+
+local testframework = require 'Module:TestFramework'
+
+function testGetEntities()
+ -- Get Q1-Q18 and Q199024 (19 entities)
+ for i = 1, 18 do
+ mw.wikibase.getEntity( 'Q' .. i )
+ end
+ mw.wikibase.getEntity( 'Q199024' )
+
+ -- These are in memory cached now
+ mw.wikibase.getEntity( 'Q16' )
+ mw.wikibase.getEntity( 'Q12' )
+ mw.wikibase.getEntity( 'Q13' )
+ mw.wikibase.getEntity( 'Q14' )
+
+ -- Q1 is no longer cached, thus we just loaded 20 entities
+ mw.wikibase.getEntity( 'Q1' )
+
+ -- Make sure this points to the right table (cached)
+ return mw.wikibase.getEntity( 'Q199024' ).id
+end
+
+local tests = {
+ { name = "Load 20 entities and operate on cache then", func =
testGetEntities,
+ expect = { 'Q199024' }
+ }
+}
+
+return testframework.getTestProvider( tests )
diff --git
a/client/tests/phpunit/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseInProcessEntityCacheTest.php
b/client/tests/phpunit/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseInProcessEntityCacheTest.php
new file mode 100644
index 0000000..3cfb452
--- /dev/null
+++
b/client/tests/phpunit/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseInProcessEntityCacheTest.php
@@ -0,0 +1,51 @@
+<?php
+
+namespace Wikibase\Client\Tests\DataAccess\Scribunto;
+
+use Wikibase\Client\WikibaseClient;
+use Wikibase\DataModel\Entity\Item;
+use Wikibase\DataModel\Entity\ItemId;
+use Wikibase\DataModel\Services\Lookup\EntityLookup;
+
+/**
+ * Verifies that arbitrary data access doesn't work, if it's disabled.
+ *
+ * @covers Wikibase\Client\DataAccess\Scribunto\Scribunto_LuaWikibaseLibrary
+ *
+ * @group WikibaseScribunto
+ * @group WikibaseIntegration
+ * @group WikibaseClient
+ * @group Wikibase
+ *
+ * @licence GNU GPL v2+
+ * @author Marius Hoch < [email protected] >
+ */
+class Scribunto_LuaWikibaseInProcessEntityCacheTest extends
Scribunto_LuaWikibaseLibraryTestCase {
+
+ protected static $moduleName =
'LuaWikibaseLibraryInProcessEntityCacheTests';
+
+ protected function getTestModules() {
+ return parent::getTestModules() + array(
+ 'LuaWikibaseLibraryInProcessEntityCacheTests' =>
__DIR__ . '/LuaWikibaseLibraryInProcessEntityCacheTests.lua',
+ );
+ }
+
+ /**
+ * @return EntityLookup
+ */
+ protected static function getEntityLookup() {
+ $phpunit = new self();
+
+ $entityLookup = $phpunit->getMock(
'Wikibase\DataModel\Services\Lookup\EntityLookup' );
+ $entityLookup->expects( $phpunit->exactly( 20 ) )
+ ->method( 'getEntity' )
+ ->will( $phpunit->returnCallback(
+ function( ItemId $itemId ) {
+ return new Item( $itemId );
+ }
+ ) );
+
+ return $entityLookup;
+ }
+
+}
diff --git
a/client/tests/phpunit/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseLibraryTest.php
b/client/tests/phpunit/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseLibraryTest.php
index 7a99796..d8eda28 100644
---
a/client/tests/phpunit/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseLibraryTest.php
+++
b/client/tests/phpunit/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseLibraryTest.php
@@ -31,6 +31,14 @@
);
}
+ /**
+ * @return int
+ */
+ protected static function getEntityAccessLimit() {
+ // testGetEntity_entityAccessLimitExceeded needs this to be 2
+ return 2;
+ }
+
public function testConstructor() {
$engine = Scribunto::newDefaultEngine( array() );
$luaWikibaseLibrary = new Scribunto_LuaWikibaseLibrary( $engine
);
diff --git
a/client/tests/phpunit/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseLibraryTestCase.php
b/client/tests/phpunit/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseLibraryTestCase.php
index edbac62..600d3cf 100644
---
a/client/tests/phpunit/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseLibraryTestCase.php
+++
b/client/tests/phpunit/includes/DataAccess/Scribunto/Scribunto_LuaWikibaseLibraryTestCase.php
@@ -53,12 +53,10 @@
*/
private static function doMock() {
$wikibaseClient = WikibaseClient::getDefaultInstance( 'reset' );
- $store = $wikibaseClient->getStore();
- if ( ! $store instanceof MockClientStore ) {
- $store = new MockClientStore( 'de' );
- $wikibaseClient->overrideStore( $store );
- }
+ $store = new MockClientStore( 'de' );
+ $store->setEntityLookup( static::getEntityLookup() );
+ $wikibaseClient->overrideStore( $store );
$settings = $wikibaseClient->getSettings();
if ( self::$oldAllowArbitraryDataAccess === null ) {
@@ -73,7 +71,7 @@
$settings->setSetting(
'entityAccessLimit',
- 2
+ static::getEntityAccessLimit()
);
$testHelper = new WikibaseDataAccessTestItemSetUpHelper( $store
);
@@ -100,9 +98,9 @@
$wikibaseClient = WikibaseClient::getDefaultInstance();
$this->assertInstanceOf(
- 'Wikibase\Test\MockRepository',
- $wikibaseClient->getStore()->getEntityLookup(),
- 'Mocking the default client EntityLookup failed'
+ 'Wikibase\Test\MockClientStore',
+ $wikibaseClient->getStore(),
+ 'Mocking the default ClientStore failed'
);
$this->setMwGlobals( 'wgContLang', Language::factory( 'de' ) );
@@ -128,4 +126,18 @@
return Title::newFromText( 'WikibaseClientDataAccessTest' );
}
+ /**
+ * @return EntityLookup|null
+ */
+ protected static function getEntityLookup() {
+ return null;
+ }
+
+ /**
+ * @return int
+ */
+ protected static function getEntityAccessLimit() {
+ return PHP_INT_MAX;
+ }
+
}
--
To view, visit https://gerrit.wikimedia.org/r/244216
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iba405dfa98c9dc5e828f3910979e9d3e5d7d231e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Hoo man <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits