jenkins-bot has submitted this change and it was merged.
Change subject: \SMW\StoreUpdater (compartmentalize ParserData)
......................................................................
\SMW\StoreUpdater (compartmentalize ParserData)
Code coverage: 77% (needs DI framework)
CRAP: 12
ParserData becomes a DispatchableSubject to call the 'runStoreUpdater'
that initiates the update procedures that once where part of
ParserData.
## Program flow
SMW\ParserData->updateStore( )
SMW\ObservableSubject->setState( )
SMW\ObservableSubject->notify( )
SMW\Observer->update( )
SMW\UpdateObserver->runStoreUpdater( )
SMW\StoreUpdater->doUpdate( )
Change-Id: I8887e1e8d7097e3d17f075225d423121a76e4876
---
M SemanticMediaWiki.classes.php
M SemanticMediaWiki.hooks.php
M includes/ObservableSubjectDispatcher.php
M includes/ParserData.php
A includes/StoreUpdater.php
R includes/UpdateObserver.php
M includes/hooks/LinksUpdateConstructed.php
M includes/jobs/UpdateJob.php
R tests/phpunit/MockUpdateObserver.php
M tests/phpunit/includes/ParserDataTest.php
M tests/phpunit/includes/PropertyChangeNotifierTest.php
A tests/phpunit/includes/StoreUpdaterTest.php
R tests/phpunit/includes/UpdateObserverTest.php
13 files changed, 534 insertions(+), 115 deletions(-)
Approvals:
Mwjames: Looks good to me, approved
jenkins-bot: Verified
diff --git a/SemanticMediaWiki.classes.php b/SemanticMediaWiki.classes.php
index 8f7f723..d313804 100644
--- a/SemanticMediaWiki.classes.php
+++ b/SemanticMediaWiki.classes.php
@@ -55,12 +55,13 @@
'SMW\MessageReporter' => 'includes/MessageReporter.php',
'SMW\ObservableMessageReporter' => 'includes/MessageReporter.php',
'SMW\ContentParser' => 'includes/ContentParser.php',
- 'SMW\ChangeObserver' => 'includes/ChangeObserver.php',
+ 'SMW\UpdateObserver' => 'includes/UpdateObserver.php',
'SMW\TitleAccess' => 'includes/TitleAccess.php',
'SMW\Observable' => 'includes/ObservableSubject.php',
'SMW\Publisher' => 'includes/ObservableSubject.php',
'SMW\ObservableSubject' => 'includes/ObservableSubject.php',
+ 'SMW\StoreUpdater' => 'includes/StoreUpdater.php',
'SMW\Observer' => 'includes/Observer.php',
'SMW\Subscriber' => 'includes/Observer.php',
@@ -310,7 +311,7 @@
'SMW\Test\MockObjectBuilder' =>
'tests/phpunit/MockObjectBuilder.php',
'SMW\Test\SpecialPageTestCase' =>
'tests/phpunit/SpecialPageTestCase.php',
'SMW\Test\CompatibilityTestCase' =>
'tests/phpunit/CompatibilityTestCase.php',
- 'SMW\Test\MockChangeObserver' =>
'tests/phpunit/MockChangeObserver.php',
+ 'SMW\Test\MockUpdateObserver' =>
'tests/phpunit/MockUpdateObserver.php',
// Jobs
'SMW\UpdateDispatcherJob' => 'includes/jobs/UpdateDispatcherJob.php',
diff --git a/SemanticMediaWiki.hooks.php b/SemanticMediaWiki.hooks.php
index b7b0314..555f844 100644
--- a/SemanticMediaWiki.hooks.php
+++ b/SemanticMediaWiki.hooks.php
@@ -511,7 +511,7 @@
$cache = \SMW\CacheHandler::newFromId()->key( 'autorefresh',
$parser->getTitle()->getArticleID() );
if( $cache->get() ) {
- $parserData->updateStore();
+ $parserData->setObservableDispatcher( new
\SMW\ObservableSubjectDispatcher( new \SMW\UpdateObserver() ) )->updateStore();
$cache->delete();
}
diff --git a/includes/ObservableSubjectDispatcher.php
b/includes/ObservableSubjectDispatcher.php
index 44981fb..619514a 100644
--- a/includes/ObservableSubjectDispatcher.php
+++ b/includes/ObservableSubjectDispatcher.php
@@ -64,7 +64,7 @@
* @par Example:
* @code
* $changeNotifier = new PropertyChangeNotifier( ... );
- * $changeNotifier->setObservableDispatcher( new ObservableSubjectDispatcher(
new ChangeObserver() ) );
+ * $changeNotifier->setObservableDispatcher( new ObservableSubjectDispatcher(
new UpdateObserver() ) );
* @endcode
*
* @ingroup Observer
diff --git a/includes/ParserData.php b/includes/ParserData.php
index 307f6e8..1e67575 100644
--- a/includes/ParserData.php
+++ b/includes/ParserData.php
@@ -111,7 +111,7 @@
* @author Markus Krötzsch
* @author mwjames
*/
-class ParserData extends Observer implements IParserData {
+class ParserData extends Observer implements IParserData, DispatchableSubject {
/**
* Represents Title object
@@ -149,6 +149,9 @@
*/
protected $updateJobs = true;
+ /** @var ObservableDispatcher */
+ protected $dispatcher;
+
/**
* Constructor
*
@@ -162,7 +165,6 @@
$this->title = $title;
$this->parserOutput = $parserOutput;
$this->options = $options;
- $this->updateJobs = $GLOBALS['smwgEnableUpdateJobs'];
$this->setData();
}
@@ -175,6 +177,29 @@
*/
public function getTitle() {
return $this->title;
+ }
+
+ /**
+ * Returns update status
+ *
+ * @since 1.9
+ *
+ * @return boolean
+ */
+ public function getUpdateStatus() {
+ return $this->updateJobs;
+ }
+
+ /**
+ * Invokes an ObservableDispatcher object to deploy state changes to an
Observer
+ *
+ * @since 1.9
+ *
+ * @param ObservableDispatcher $dispatcher
+ */
+ public function setObservableDispatcher( ObservableDispatcher
$dispatcher ) {
+ $this->dispatcher = $dispatcher->setSubject( $this );
+ return $this;
}
/**
@@ -229,6 +254,7 @@
*/
public function disableUpdateJobs() {
$this->updateJobs = false;
+ return $this;
}
/**
@@ -340,82 +366,12 @@
/**
* Updates the store with semantic data attached to a ParserOutput
object
*
- * This function takes care of storing the collected semantic data and
takes
- * care of clearing out any outdated entries for the processed page. It
assume that
- * parsing has happened and that all relevant data is contained in the
provided parser
- * output.
- *
- * Optionally, this function also takes care of triggering indirect
updates that might be
- * needed for overall database consistency. If the saved page describes
a property or data type,
- * the method checks whether the property type, the data type, the
allowed values, or the
- * conversion factors have changed. If so, it triggers SMWUpdateJobs
for the relevant articles,
- * which then asynchronously update the semantic data in the database.
- *
- * @todo FIXME: Some job generations here might create too many jobs at
once
- * on a large wiki. Use incremental jobs instead.
- *
- * To disable jobs either set $smwgEnableUpdateJobs = false or invoke
- * SMW\ParserData::disableUpdateJobs()
- *
- * Called from SMWUpdateJob::run, SMWHooks::onLinksUpdateConstructed,
- * SMWHooks::onParserAfterTidy
- *
* @since 1.9
*
* @return boolean
*/
public function updateStore() {
- Profiler::In( __METHOD__, true );
-
- // Protect against namespace -1 see Bug 50153
- if ( $this->title->isSpecialPage() ) {
- return true;
- }
-
- $namespace = $this->title->getNamespace();
- $wikiPage = WikiPage::factory( $this->title );
- $revision = $wikiPage->getRevision();
- $store = StoreFactory::getStore();
-
- // FIXME get rid of globals and use options array instead while
- // invoking the constructor
- $this->options = array(
- 'smwgDeclarationProperties' =>
$GLOBALS['smwgDeclarationProperties'],
- 'smwgPageSpecialProperties' =>
$GLOBALS['smwgPageSpecialProperties']
- );
-
- // Make sure to have a valid revision (null means delete etc.)
- // Check if semantic data should be processed and displayed for
a page in
- // the given namespace
- $processSemantics = $revision !== null ?
smwfIsSemanticsProcessed( $namespace ) : false;
-
- if ( $processSemantics ) {
- $user = \User::newFromId( $revision->getUser() );
-
- $complementor = new BasePropertyAnnotator(
$this->semanticData, Settings::newFromGlobals() );
- $complementor->attach( $this );
- $complementor->addSpecialProperties( $wikiPage,
$revision, $user );
-
- } else {
- // data found, but do all operations as if it was empty
- $this->semanticData = new SMWSemanticData(
$this->getSubject() );
- }
-
- // Comparison must happen *before* the storage update;
- // even finding uses of a property fails after its type was
changed.
- if ( $this->updateJobs ) {
- $changeNotifier = new PropertyChangeNotifier( $store,
$this->semanticData, Settings::newFromGlobals() );
- $changeNotifier->setObservableDispatcher( new
ObservableSubjectDispatcher( new ChangeObserver() ) )->detectChanges();
- }
-
- // Actually store semantic data, or at least clear it if needed
- if ( $processSemantics ) {
- $store->updateData( $this->semanticData );
- } else {
- $store->clearData( $this->semanticData->getSubject() );
- }
-
- Profiler::Out( __METHOD__, true );
+ $this->dispatcher->setState( 'runStoreUpdater' );
return true;
}
diff --git a/includes/StoreUpdater.php b/includes/StoreUpdater.php
new file mode 100644
index 0000000..237afd5
--- /dev/null
+++ b/includes/StoreUpdater.php
@@ -0,0 +1,154 @@
+<?php
+
+namespace SMW;
+
+use WikiPage;
+use Title;
+use User;
+
+/**
+ * Initiates update of the Store
+ *
+ * @file
+ *
+ * @license GNU GPL v2+
+ * @since 1.9
+ *
+ * @author mwjames
+ */
+
+/**
+ * Initiates update of the Store
+ *
+ * @ingroup SMW
+ */
+class StoreUpdater {
+
+ /** @var Store */
+ protected $store;
+
+ /** @var SemanticData */
+ protected $semanticData;
+
+ /** @var Settings */
+ protected $settings;
+
+ /** @var $updateJobs */
+ protected $updateJobs = null;
+
+ /**
+ * @since 1.9
+ *
+ * @param SemanticData $semanticData
+ * @param Settings $settings
+ */
+ public function __construct( Store $store, SemanticData $semanticData,
Settings $settings ) {
+ $this->store = $store;
+ $this->semanticData = $semanticData;
+ $this->settings = $settings;
+
+ $this->setUpdateStatus( $settings->get( 'smwgEnableUpdateJobs'
) );
+ }
+
+ /**
+ * Returns the subject
+ *
+ * @since 1.9
+ *
+ * @return DIWikiPage
+ */
+ public function getSubject() {
+ return $this->semanticData->getSubject();
+ }
+
+ /**
+ * Sets the update status
+ *
+ * @since 1.9
+ */
+ public function setUpdateStatus( $status ) {
+ $this->updateJobs = (bool)$status;
+ return $this;
+ }
+
+ /**
+ * Updates the store with invoked semantic data
+ *
+ * This function takes care of storing the collected semantic data and
+ * clearing out any outdated entries for the processed page. It assumes
+ * that parsing has happened and that all relevant information are
+ * contained and provided for.
+ *
+ * Optionally, this function also takes care of triggering indirect
updates
+ * that might be needed for an overall database consistency. If the
saved page
+ * describes a property or data type, the method checks whether the
property
+ * type, the data type, the allowed values, or the conversion factors
have
+ * changed. If so, it triggers UpdateDispatcherJob for the relevant
articles,
+ * which then asynchronously undergoes an update.
+ *
+ * @since 1.9
+ *
+ * @return true
+ */
+ public function doUpdate() {
+ Profiler::In( __METHOD__, true );
+
+ $title = $this->getSubject()->getTitle();
+
+ // Protect against namespace -1 see Bug 50153
+ if ( $title->isSpecialPage() ) {
+ return false;
+ }
+
+ $wikiPage = WikiPage::factory( $title );
+ $revision = $wikiPage->getRevision();
+
+ // Make sure to have a valid revision (null means delete etc.)
+ // Check if semantic data should be processed and displayed for
a page in
+ // the given namespace
+ $processSemantics = $revision !== null && $this->isValid(
$title );
+
+ if ( $processSemantics ) {
+
+ $user = User::newFromId( $revision->getUser() );
+
+ $propertyAnnotator = new BasePropertyAnnotator(
$this->semanticData, $this->settings );
+ $propertyAnnotator->addSpecialProperties( $wikiPage,
$revision, $user );
+
+ } else {
+ // data found, but do all operations as if it was empty
+ $this->semanticData = new SemanticData(
$this->getSubject() );
+ }
+
+ // Comparison must happen *before* the storage update;
+ // even finding uses of a property fails after its type changed.
+ if ( $this->updateJobs ) {
+ $changeNotifier = new PropertyChangeNotifier(
$this->store, $this->semanticData, $this->settings );
+ $changeNotifier->setObservableDispatcher( new
ObservableSubjectDispatcher( new UpdateObserver() ) )->detectChanges();
+ }
+
+ // Actually store semantic data, or at least clear it if needed
+ if ( $processSemantics ) {
+ $this->store->updateData( $this->semanticData );
+ } else {
+ $this->store->clearData(
$this->semanticData->getSubject() );
+ }
+
+ Profiler::Out( __METHOD__, true );
+ return true;
+ }
+
+ /**
+ * Returns whether the current Title is valid
+ *
+ * @since 1.9
+ *
+ * @param Title $title
+ *
+ * @return boolean
+ */
+ protected function isValid( Title $title ) {
+ return NamespaceExaminer::newFromArray( $this->settings->get(
'smwgNamespacesWithSemanticLinks' ) )->isSemanticEnabled(
$title->getNamespace() );
+ }
+
+}
diff --git a/includes/ChangeObserver.php b/includes/UpdateObserver.php
similarity index 81%
rename from includes/ChangeObserver.php
rename to includes/UpdateObserver.php
index 81d9611..6a26d95 100644
--- a/includes/ChangeObserver.php
+++ b/includes/UpdateObserver.php
@@ -18,12 +18,12 @@
* General purpose change agent to enforce loose coupling by having
* a Publisher (subject) sent a change notification to this observer
*
- * @note When testing rountrips, use MockChangeObserver instead
+ * @note When testing rountrips, use MockUpdateObserver instead
*
* @ingroup Observer
* @ingroup Utility
*/
-class ChangeObserver extends Observer implements Cacheable, Configurable,
StoreAccess {
+class UpdateObserver extends Observer implements Cacheable, Configurable,
StoreAccess {
/** @var Settings */
protected $settings = null;
@@ -108,11 +108,29 @@
}
/**
+ * Store updater
+ *
+ * @note Is called from UpdateJob::run,
LinksUpdateConstructed::process, and
+ * ParserAfterTidy::process
+ *
+ * @since 1.9
+ *
+ * @param ParserData $subject
+ *
+ * @return true
+ */
+ public function runStoreUpdater( ParserData $subject ) {
+
+ $updater = new StoreUpdater( $this->getStore(),
$subject->getData(), $this->getSettings() );
+ $updater->setUpdateStatus( $subject->getUpdateStatus()
)->doUpdate();
+
+ return true;
+ }
+
+ /**
* UpdateJob dispatching
*
- * loading of data
- *
- * Generally by the time the job is execute the store has been updated
and
+ * Normally by the time the job is execute the store has been updated
and
* data that belong to a property potentially are no longer are
associate
* with a subject.
*
diff --git a/includes/hooks/LinksUpdateConstructed.php
b/includes/hooks/LinksUpdateConstructed.php
index 6a1b706..3a7c550 100644
--- a/includes/hooks/LinksUpdateConstructed.php
+++ b/includes/hooks/LinksUpdateConstructed.php
@@ -46,7 +46,7 @@
public function process() {
$parserData = new ParserData( $this->linksUpdate->getTitle(),
$this->linksUpdate->getParserOutput() );
- $parserData->updateStore();
+ $parserData->setObservableDispatcher( new
ObservableSubjectDispatcher( new UpdateObserver() ) )->updateStore();
return true;
}
diff --git a/includes/jobs/UpdateJob.php b/includes/jobs/UpdateJob.php
index 6b498b5..ca60bed 100644
--- a/includes/jobs/UpdateJob.php
+++ b/includes/jobs/UpdateJob.php
@@ -79,8 +79,9 @@
Profiler::In( __METHOD__ . '-update' );
$parserData = new ParserData( $this->getTitle(),
$this->getContentParser()->getOutput() );
- $parserData->disableUpdateJobs();
- $parserData->updateStore();
+ $parserData->setObservableDispatcher( new
ObservableSubjectDispatcher( new UpdateObserver() ) )
+ ->disableUpdateJobs()
+ ->updateStore();
Profiler::Out( __METHOD__ . '-update' );
Profiler::Out( __METHOD__ . '-run' );
diff --git a/tests/phpunit/MockChangeObserver.php
b/tests/phpunit/MockUpdateObserver.php
similarity index 75%
rename from tests/phpunit/MockChangeObserver.php
rename to tests/phpunit/MockUpdateObserver.php
index 51015ae..fd5e14f 100644
--- a/tests/phpunit/MockChangeObserver.php
+++ b/tests/phpunit/MockUpdateObserver.php
@@ -2,11 +2,12 @@
namespace SMW\Test;
-use \SMW\ChangeObserver;
+use \SMW\UpdateObserver;
use \SMW\TitleAccess;
+use \SMW\ParserData;
/**
- * MockChangeAgent should only be used during testing to establish that
+ * MockUpdateObserver should only be used during testing to establish that
* a correct behaviour between Observer and Subject has been established.
*
* @file
@@ -18,7 +19,7 @@
*/
/**
- * MockChangeObserver should only be used during testing to establish that
+ * MockUpdateObserver should only be used during testing to establish that
* a correct behaviour between Observer and Subject has been established.
*
* Use the setNotifier/getNotifier to verify the function that was expected
@@ -31,7 +32,7 @@
*
* @par Example:
* @code
- * $observer = new MockChangeObserver();
+ * $observer = new MockUpdateObserver();
* $instance->attach( $observer );
*
* $this->assertEquals( 'runFoo', $observer->getNotifier() )
@@ -40,7 +41,7 @@
* @ingroup Observer
* @codeCoverageIgnore
*/
-class MockChangeObserver extends ChangeObserver {
+class MockUpdateObserver extends UpdateObserver {
/** @var string */
protected $notifier = null;
@@ -69,7 +70,7 @@
}
/**
- * @see ChangeObserver::runUpdateDispatcher
+ * @see UpdateObserver::runUpdateDispatcher
*
* @since 1.9
*
@@ -79,4 +80,15 @@
$this->setNotifier( __FUNCTION__ );
}
+ /**
+ * @see UpdateObserver::runStoreUpdater
+ *
+ * @since 1.9
+ *
+ * @param ParserData $subject
+ */
+ public function runStoreUpdater( ParserData $subject ) {
+ $this->setNotifier( __FUNCTION__ );
+ }
+
}
diff --git a/tests/phpunit/includes/ParserDataTest.php
b/tests/phpunit/includes/ParserDataTest.php
index 6104461..be4cfa2 100644
--- a/tests/phpunit/includes/ParserDataTest.php
+++ b/tests/phpunit/includes/ParserDataTest.php
@@ -2,6 +2,7 @@
namespace SMW\Test;
+use SMW\ObservableSubjectDispatcher;
use SMW\DataValueFactory;
use SMW\ParserData;
use SMW\Settings;
@@ -63,8 +64,8 @@
*/
public function testConstructor() {
$instance = $this->getInstance(
- $this->getTitle(),
- $this->getParserOutput()
+ $this->newTitle(),
+ $this->newParserOutput()
);
$this->assertInstanceOf( $this->getClass(), $instance );
}
@@ -119,4 +120,28 @@
}
}
+ /**
+ * @test ParserData::updateStore
+ *
+ * @since 1.9
+ */
+ public function testUpdateStore() {
+
+ $notifier = 'runStoreUpdater';
+ $title = $this->newTitle();
+ $parserOutput = $this->newParserOutput();
+
+ $instance = $this->getInstance( $title, $parserOutput );
+ $observer = new MockUpdateObserver();
+
+ $instance->setObservableDispatcher( new
ObservableSubjectDispatcher( $observer ) );
+
+ $this->assertTrue( $instance->updateStore() );
+
+ // Verify that the Observer was notified
+ $this->assertEquals( $notifier, $observer->getNotifier() );
+
+ }
+
+
}
diff --git a/tests/phpunit/includes/PropertyChangeNotifierTest.php
b/tests/phpunit/includes/PropertyChangeNotifierTest.php
index 263c9a9..5a52623 100644
--- a/tests/phpunit/includes/PropertyChangeNotifierTest.php
+++ b/tests/phpunit/includes/PropertyChangeNotifierTest.php
@@ -93,7 +93,7 @@
);
$instance = $this->getInstance( $store, $data, $settings );
- $observer = new MockChangeObserver();
+ $observer = new MockUpdateObserver();
$instance->setObservableDispatcher( new
ObservableSubjectDispatcher( $observer ) );
diff --git a/tests/phpunit/includes/StoreUpdaterTest.php
b/tests/phpunit/includes/StoreUpdaterTest.php
new file mode 100644
index 0000000..ad2f136
--- /dev/null
+++ b/tests/phpunit/includes/StoreUpdaterTest.php
@@ -0,0 +1,206 @@
+<?php
+
+namespace SMW\Test;
+
+use SMW\StoreUpdater;
+use SMW\SemanticData;
+use SMW\DIWikiPage;
+
+use Title;
+
+/**
+ * Tests for the StoreUpdater class
+ *
+ * @file
+ *
+ * @license GNU GPL v2+
+ * @since 1.9
+ *
+ * @author mwjames
+ */
+
+/**
+ * @covers \SMW\StoreUpdater
+ *
+ * @ingroup Test
+ *
+ * @group SMW
+ * @group SMWExtension
+ */
+class StoreUpdaterTest extends SemanticMediaWikiTestCase {
+
+ /**
+ * Returns the name of the class to be tested
+ *
+ * @return string|false
+ */
+ public function getClass() {
+ return '\SMW\StoreUpdater';
+ }
+
+ /**
+ * Helper method that returns a StoreUpdater object
+ *
+ * @since 1.9
+ *
+ * @param $store
+ * @param $data
+ * @param $settings
+ *
+ * @return StoreUpdater
+ */
+ private function getInstance( $store = null, $data = null, $settings =
null ) {
+
+ if ( $store === null ) {
+ $store = $this->newMockObject()->getMockStore();
+ }
+
+ if ( $data === null ) {
+ $data = $this->newMockObject()->getMockSemanticData();
+ }
+
+ if ( $settings === null ) {
+ $settings = $this->getSettings( array(
+ 'smwgEnableUpdateJobs' => false,
+ 'smwgNamespacesWithSemanticLinks' => array(
NS_MAIN => true )
+ ) );
+ }
+
+ return new StoreUpdater( $store, $data, $settings );
+ }
+
+ /**
+ * @test StoreUpdater::__construct
+ *
+ * @since 1.9
+ */
+ public function testConstructor() {
+ $this->assertInstanceOf( $this->getClass(),
$this->getInstance() );
+ }
+
+ /**
+ * @test StoreUpdater::doUpdate
+ *
+ * @since 1.9
+ */
+ public function testDoUpdate() {
+
+ $store = \SMW\StoreFactory::getStore();
+ $data = new \SMW\SemanticData( $this->newSubject() );
+
+ $instance = $this->getInstance( $store, $data );
+ $instance->setUpdateStatus( false );
+
+ $this->assertTrue( $instance->doUpdate() );
+
+ }
+
+ /**
+ * @test StoreUpdater::doUpdate
+ * @dataProvider titleDataProvider
+ *
+ * @since 1.9
+ *
+ * @param $setup
+ * @param $expected
+ */
+ public function testDoUpdateOnMock( $setup, $expected ) {
+
+ $mockStore = $this->newMockObject( array(
+ 'updateData' => array( $this,
'mockStoreUpdateDataCallback' ),
+ 'clearData' => array( $this,
'mockStoreClearDataCallback' ),
+ ) )->getMockStore();
+
+ $mockSubject = $this->newMockObject( array(
+ 'getTitle' => $setup['title']
+ ) )->getMockDIWikIPage();
+
+ $mockData = $this->newMockObject( array(
+ 'getSubject' => $mockSubject,
+ ) )->getMockSemanticData();
+
+ $instance = $this->getInstance( $mockStore, $mockData );
+ $instance->setUpdateStatus( $setup['updateStatus'] );
+
+ $this->assertEquals( $expected['return'], $instance->doUpdate()
);
+
+ // Callback adds a property, this is only done for this test to
verify
+ // that an expected function did run through the mock object
+ if ( $expected['mockCallback'] ) {
+ $this->assertEquals( $expected['mockCallback'],
$mockData->getSubject()->mockCallback );
+ }
+
+ }
+
+ /**
+ * @return array
+ */
+ public function titleDataProvider() {
+
+ $provider = array();
+
+ // #0 Clear data, updateStatus = false
+ $provider[] = array(
+ array(
+ 'title' => $this->newTitle( NS_MAIN,
'ClearData' ),
+ 'updateStatus' => false
+ ),
+ array(
+ 'return' => true,
+ 'mockCallback' => 'clear'
+ )
+ );
+
+ // #1 Clear data, updateStatus = true
+ $provider[] = array(
+ array(
+ 'title' => $this->newTitle( NS_MAIN,
'ClearData' ),
+ 'updateStatus' => true
+ ),
+ array(
+ 'return' => true,
+ 'mockCallback' => 'clear'
+ )
+ );
+
+ // FIXME $wikiPage = WikiPage::factory( $title );
+ //
+ // Needs DI framework to create wikipage object in order
+ // to inject a revision, as for the momement it can't
+ // be tested
+
+ // #2 Specialpage
+ $title = $this->newMockObject( array(
+ 'isSpecialPage' => true
+ ) )->getMockTitle();
+
+ $provider[] = array(
+ array(
+ 'title' => $title,
+ 'updateStatus' => false
+ ),
+ array(
+ 'return' => false,
+ 'mockCallback' => false
+ )
+ );
+
+ return $provider;
+
+ }
+
+ /**
+ * @since 1.9
+ */
+ public function mockStoreUpdateDataCallback( SemanticData $data ) {
+ return $data->getSubject()->getTitle()->getText() === 'Lila' ?
$data->mockCallback = 'clear' : null;
+ }
+
+ /**
+ * @since 1.9
+ */
+ public function mockStoreClearDataCallback( DIWikiPage $di ) {
+ return $di->getTitle()->getText() === 'ClearData' ?
$di->mockCallback = 'clear' : null;
+ }
+
+}
diff --git a/tests/phpunit/includes/ChangeObserverTest.php
b/tests/phpunit/includes/UpdateObserverTest.php
similarity index 61%
rename from tests/phpunit/includes/ChangeObserverTest.php
rename to tests/phpunit/includes/UpdateObserverTest.php
index d61483b..940e0ae 100644
--- a/tests/phpunit/includes/ChangeObserverTest.php
+++ b/tests/phpunit/includes/UpdateObserverTest.php
@@ -2,10 +2,10 @@
namespace SMW\Test;
-use SMW\ChangeObserver;
+use SMW\UpdateObserver;
/**
- * Tests for the ChangeObserver class
+ * Tests for the UpdateObserver class
*
* @file
*
@@ -16,14 +16,14 @@
*/
/**
- * @covers \SMW\ChangeObserver
+ * @covers \SMW\UpdateObserver
*
* @ingroup Test
*
* @group SMW
* @group SMWExtension
*/
-class ChangeObserverTest extends SemanticMediaWikiTestCase {
+class UpdateObserverTest extends SemanticMediaWikiTestCase {
/**
* Returns the name of the class to be tested
@@ -31,24 +31,24 @@
* @return string|false
*/
public function getClass() {
- return '\SMW\ChangeObserver';
+ return '\SMW\UpdateObserver';
}
/**
- * Helper method that returns a ChangeObserver object
+ * Helper method that returns a UpdateObserver object
*
* @since 1.9
*
* @param $data
*
- * @return ChangeObserver
+ * @return UpdateObserver
*/
private function getInstance() {
- return new ChangeObserver();
+ return new UpdateObserver();
}
/**
- * @test ChangeObserver::__construct
+ * @test UpdateObserver::__construct
*
* @since 1.9
*/
@@ -57,8 +57,8 @@
}
/**
- * @test ChangeObserver::getStore
- * @test ChangeObserver::setStore
+ * @test UpdateObserver::getStore
+ * @test UpdateObserver::setStore
*
* @since 1.9
*/
@@ -75,7 +75,7 @@
}
/**
- * @test ChangeObserver::getCache
+ * @test UpdateObserver::getCache
*
* @since 1.9
*/
@@ -86,36 +86,82 @@
}
/**
- * @test ChangeObserver::setSettings
- * @test ChangeObserver::getSettings
- * @dataProvider titleDataProvider
+ * @test UpdateObserver::setSettings
+ * @test UpdateObserver::getSettings
+ * @dataProvider updateDispatcherDataProvider
*
* @since 1.9
*/
public function testGetSetSettings( $setup ) {
$instance = $this->getInstance();
- $settings = $this->getSettings( $setup['settings'] );
+ $settings = $this->newSettings( $setup['settings'] );
$this->assertInstanceOf( '\SMW\Settings',
$instance->getSettings() );
- $instance->setSettings( $settings ) ;
+ $instance->setSettings( $settings );
$this->assertEquals( $settings , $instance->getSettings() );
}
/**
- * @test ChangeObserver::runUpdateDispatcher
- * @dataProvider titleDataProvider
+ * @test UpdateObserver::runUpdateDispatcher
+ * @dataProvider updateDispatcherDataProvider
*
* @since 1.9
*/
public function testUpdateDispatcherJob( $setup, $expected ) {
$instance = $this->getInstance();
- $instance->setSettings( $this->getSettings( $setup['settings']
) );
+ $instance->setSettings( $this->newSettings( $setup['settings']
) );
$this->assertTrue( $instance->runUpdateDispatcher(
$setup['title'] ) );
+ }
+
+ /**
+ * @test UpdateObserver::runUpdateDispatcher
+ * @dataProvider storeUpdaterDataProvider
+ *
+ * @since 1.9
+ */
+ public function testStoreUpdater( $setup, $expected ) {
+
+ $instance = $this->getInstance();
+ $instance->setSettings( $this->newSettings( $setup['settings']
) );
+
+ $this->assertTrue( $instance->runStoreUpdater(
$setup['parserData'] ) );
+ }
+
+ /**
+ * @return array
+ */
+ public function storeUpdaterDataProvider() {
+
+ $subject = $this->newSubject();
+ $mockData = $this->newMockObject( array(
+ 'getSubject' => $subject
+ ) )->getMockSemanticData();
+
+ $parserData = $this->newMockObject( array(
+ 'getData' => $mockData,
+ ) )->getMockParserData();
+
+ $provider = array();
+
+ // #0
+ $provider[] = array(
+ array(
+ 'settings' => array(
+ 'smwgEnableUpdateJobs' =>
false,
+ 'smwgNamespacesWithSemanticLinks' =>
array( NS_MAIN => true )
+ ),
+ 'parserData' => $parserData
+ ),
+ array()
+ );
+
+ return $provider;
+
}
/**
@@ -124,7 +170,7 @@
*
* @return array
*/
- public function titleDataProvider() {
+ public function updateDispatcherDataProvider() {
$title = $this->newMockObject( array(
'getTitle' => $this->newTitle()
--
To view, visit https://gerrit.wikimedia.org/r/78154
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8887e1e8d7097e3d17f075225d423121a76e4876
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/SemanticMediaWiki
Gerrit-Branch: master
Gerrit-Owner: Mwjames <[email protected]>
Gerrit-Reviewer: Mwjames <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits