jenkins-bot has submitted this change and it was merged.

Change subject: Test was missing, didn't caught a renaming issue (newCacheId)
......................................................................


Test was missing, didn't caught a renaming issue (newCacheId)

ArticlePurge::newIdGenerator -> ArticlePurge::newCacheId

Change-Id: I2d8fd6dca1811cb74b41f8278bc7af0e2f262b4f
---
M SemanticMediaWiki.classes.php
M SemanticMediaWiki.hooks.php
A includes/hooks/TitleMoveComplete.php
M tests/phpunit/includes/HooksTest.php
A tests/phpunit/includes/hooks/TitleMoveCompleteTest.php
5 files changed, 253 insertions(+), 53 deletions(-)

Approvals:
  Mwjames: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/SemanticMediaWiki.classes.php b/SemanticMediaWiki.classes.php
index 0236925..67e8a3a 100644
--- a/SemanticMediaWiki.classes.php
+++ b/SemanticMediaWiki.classes.php
@@ -103,6 +103,7 @@
        'SMW\CacheIdGenerator'            => 
'includes/cache/CacheIdGenerator.php',
 
        // Hooks
+       'SMW\TitleMoveComplete'            => 
'includes/hooks/TitleMoveComplete.php',
        'SMW\SpecialStatsAddExtra'         => 
'includes/hooks/SpecialStatsAddExtra.php',
        'SMW\OutputPageParserOutput'       => 
'includes/hooks/OutputPageParserOutput.php',
        'SMW\SkinAfterContent'             => 
'includes/hooks/SkinAfterContent.php',
diff --git a/SemanticMediaWiki.hooks.php b/SemanticMediaWiki.hooks.php
index 2e09ae6..2b1556a 100644
--- a/SemanticMediaWiki.hooks.php
+++ b/SemanticMediaWiki.hooks.php
@@ -550,18 +550,7 @@
         * @return true
         */
        public static function onTitleMoveComplete( &$oldTitle, &$newTitle, 
&$user, $oldId, $newId ) {
-
-               \SMW\CacheHandler::newFromId()->setCacheEnabled( $newId > 0 )
-                       ->setKey( \SMW\ArticlePurge::newIdGenerator( $newId ) )
-                       ->set( $GLOBALS['smwgAutoRefreshOnPageMove'] );
-
-               \SMW\CacheHandler::newFromId()->setCacheEnabled( $oldId > 0 )
-                       ->setKey( \SMW\ArticlePurge::newIdGenerator( $oldId ) )
-                       ->set( $GLOBALS['smwgAutoRefreshOnPageMove'] );
-
-               smwfGetStore()->changeTitle( $oldTitle, $newTitle, $oldId, 
$newId );
-
-               return true;
+               return \SMW\FunctionHookRegistry::register( new 
\SMW\TitleMoveComplete( $oldTitle, $newTitle, $user, $oldId, $newId ) 
)->process();
        }
 
        /**
diff --git a/includes/hooks/TitleMoveComplete.php 
b/includes/hooks/TitleMoveComplete.php
new file mode 100644
index 0000000..fac22a2
--- /dev/null
+++ b/includes/hooks/TitleMoveComplete.php
@@ -0,0 +1,98 @@
+<?php
+
+namespace SMW;
+
+/**
+ * TitleMoveComplete hook
+ *
+ * @file
+ *
+ * @license GNU GPL v2+
+ * @since   1.9
+ *
+ * @author mwjames
+ */
+
+/**
+ * TitleMoveComplete occurs whenever a request to move an article
+ * is completed
+ *
+ * This method will be called whenever an article is moved so that
+ * semantic properties are moved accordingly.
+ *
+ * @see http://www.mediawiki.org/wiki/Manual:Hooks/TitleMoveComplete
+ *
+ * @ingroup Hook
+ */
+class TitleMoveComplete extends FunctionHook {
+
+       /** @var Title */
+       protected $oldTitle = null;
+
+       /** @var Title */
+       protected $newTitle = null;
+
+       /** @var Use */
+       protected $user = null;
+
+       /** @var integer */
+       protected $oldId;
+
+       /** @var integer */
+       protected $newId;
+
+       /**
+        * @since  1.9
+        *
+        * @param Title $oldTitle old title
+        * @param Title $newTitle: new title
+        * @param Use $user user who did the move
+        * @param $oldId database ID of the page that's been moved
+        * @param $newId database ID of the created redirect
+        */
+       public function __construct( &$oldTitle, &$newTitle, &$user, $oldId, 
$newId ) {
+               $this->oldTitle = $oldTitle;
+               $this->newTitle = $newTitle;
+               $this->user = $user;
+               $this->oldId = $oldId;
+               $this->newId = $newId;
+       }
+
+       /**
+        * @see FunctionHook::process
+        *
+        * @since 1.9
+        *
+        * @return true
+        */
+       public function process() {
+
+               /**
+                * @var Store $store
+                */
+               $store = $this->getDependencyBuilder()->newObject( 'Store' );
+
+               /**
+                * @var Settings $settings
+                */
+               $settings = $this->getDependencyBuilder()->newObject( 
'Settings' );
+
+               /**
+                * @var CacheHandler $cache
+                */
+               $cache = $this->getDependencyBuilder()->newObject( 
'CacheHandler' );
+
+               $cache->setCacheEnabled( $this->newId > 0 )
+                       ->setKey( ArticlePurge::newCacheId( $this->newId ) )
+                       ->set( $settings->get( 'smwgAutoRefreshOnPageMove' ) );
+
+               $cache->setCacheEnabled( $this->oldId > 0 )
+                       ->setKey( ArticlePurge::newCacheId( $this->oldId ) )
+                       ->set( $settings->get( 'smwgAutoRefreshOnPageMove' ) );
+
+               $store->changeTitle( $this->oldTitle, $this->newTitle, 
$this->oldId, $this->newId );
+
+               return true;
+       }
+
+}
diff --git a/tests/phpunit/includes/HooksTest.php 
b/tests/phpunit/includes/HooksTest.php
index 398906c..ce22329 100644
--- a/tests/phpunit/includes/HooksTest.php
+++ b/tests/phpunit/includes/HooksTest.php
@@ -525,47 +525,6 @@
        }
 
        /**
-        * @test SMWHooks::onTitleMoveComplete
-        *
-        * @since 1.9
-        */
-       public function testOnTitleMoveComplete() {
-               // For some mysterious reasons this test causes
-               // SMW\Test\ApiAskTest::testExecute ... to fail with 
DBQueryError:
-               // Query: SELECT  o_serialized AS v0  FROM 
unittest_unittest_smw_fpt_mdat
-               // WHERE s_id='5'; it seems that the temp. unittest tables are
-               // being deleted while this test runs
-               $skip = true;
-
-               if ( !$skip && method_exists( 'WikiPage', 'doEditContent' ) ) {
-                       $wikiPage = $this->newPage();
-                       $user = $this->getUser();
-
-                       $title = $wikiPage->getTitle();
-                       $newTitle = $this->getTitle();
-                       $pageid = $wikiPage->getId();
-
-                       $content = \ContentHandler::makeContent(
-                               'testing',
-                               $title,
-                               CONTENT_MODEL_WIKITEXT
-                       );
-                       $wikiPage->doEditContent( $content, "testing", 
EDIT_NEW, false, $user );
-
-                       $result = SMWHooks::onTitleMoveComplete( $title, 
$newTitle, $user, $pageid, $pageid );
-
-                       // Always make sure to clean-up
-                       if ( $wikiPage->exists() ) {
-                               $wikiPage->doDeleteArticle( "testing done." );
-                       }
-
-                       $this->assertTrue( $result );
-               } else {
-                       $this->assertTrue( $skip );
-               }
-       }
-
-       /**
         * @test SMWHooks::onBeforePageDisplay
         *
         * @since 1.9
diff --git a/tests/phpunit/includes/hooks/TitleMoveCompleteTest.php 
b/tests/phpunit/includes/hooks/TitleMoveCompleteTest.php
new file mode 100644
index 0000000..780d3da
--- /dev/null
+++ b/tests/phpunit/includes/hooks/TitleMoveCompleteTest.php
@@ -0,0 +1,153 @@
+<?php
+
+namespace SMW\Test;
+
+use SMW\SharedDependencyContainer;
+use SMW\TitleMoveComplete;
+
+use WikiPage;
+
+/**
+ * Tests for the TitleMoveComplete class
+ *
+ * @file
+ *
+ * @license GNU GPL v2+
+ * @since   1.9
+ *
+ * @author mwjames
+ */
+
+/**
+ * @covers \SMW\TitleMoveComplete
+ *
+ * @ingroup Test
+ *
+ * @group SMW
+ * @group SMWExtension
+ */
+class TitleMoveCompleteTest extends SemanticMediaWikiTestCase {
+
+       /**
+        * Returns the name of the class to be tested
+        *
+        * @return string|false
+        */
+       public function getClass() {
+               return '\SMW\TitleMoveComplete';
+       }
+
+       /**
+        * Helper method that returns a TitleMoveComplete object
+        *
+        * @since 1.9
+        *
+        * @return TitleMoveComplete
+        */
+       private function newInstance( $oldTitle = null, $newTitle = null, $user 
= null, $oldId = 0, $newId = 0, $settings = array() ) {
+
+               if ( $oldTitle === null ) {
+                       $oldTitle = $this->newMockBuilder()->newObject( 'Title' 
);
+               }
+
+               if ( $newTitle === null ) {
+                       $newTitle = $this->newMockBuilder()->newObject( 'Title' 
);
+               }
+
+               if ( $user === null ) {
+                       $user = $this->getUser();
+               }
+
+               $container = new SharedDependencyContainer();
+               $container->registerObject( 'Settings', $this->newSettings( 
$settings ) );
+
+               $instance = new TitleMoveComplete( $oldTitle, $newTitle, $user, 
$oldId, $newId );
+               $instance->setDependencyBuilder( $this->newDependencyBuilder( 
$container ) );
+
+               return $instance;
+       }
+
+       /**
+        * @test TitleMoveComplete::__construct
+        *
+        * @since 1.9
+        */
+       public function testConstructor() {
+               $this->assertInstanceOf( $this->getClass(), 
$this->newInstance() );
+       }
+
+       /**
+        * @test TitleMoveComplete::process
+        *
+        * @since 1.9
+        *
+        * @param $setup
+        * @param $expected
+        */
+       public function testProcessOnMock() {
+
+               $settings = array(
+                       'smwgCacheType'             => 'hash',
+                       'smwgAutoRefreshOnPageMove' => true,
+               );
+
+               $instance = $this->newInstance( null, null, null, 0 , 0, 
$settings );
+
+               $container = $instance->getDependencyBuilder()->getContainer();
+               $container->registerObject( 'Store', 
$this->newMockBuilder()->newObject( 'Store' ) );
+
+               $result = $instance->process();
+
+               // Post-process check
+               $this->assertTrue(
+                       $result,
+                       'Asserts that process() always returns true'
+               );
+
+       }
+
+       /**
+        * @test TitleMoveComplete::process
+        *
+        * @note Recycle the old test but for now skip this one
+        *
+        * @since 1.9
+        */
+       public function testProcessOnDB() {
+
+               // For some mysterious reasons this test causes
+               // SMW\Test\ApiAskTest::testExecute ... to fail with 
DBQueryError:
+               // Query: SELECT  o_serialized AS v0  FROM 
unittest_unittest_smw_fpt_mdat
+               // WHERE s_id='5'; it seems that the temp. unittest tables are
+               // being deleted while this test runs
+               $skip = true;
+
+               if ( !$skip && method_exists( 'WikiPage', 'doEditContent' ) ) {
+                       $wikiPage = $this->newPage();
+                       $user = $this->getUser();
+
+                       $title = $wikiPage->getTitle();
+                       $newTitle = $this->getTitle();
+                       $pageid = $wikiPage->getId();
+
+                       $content = \ContentHandler::makeContent(
+                               'testing',
+                               $title,
+                               CONTENT_MODEL_WIKITEXT
+                       );
+                       $wikiPage->doEditContent( $content, "testing", 
EDIT_NEW, false, $user );
+
+               //      $result = SMWHooks::onTitleMoveComplete( $title, 
$newTitle, $user, $pageid, $pageid );
+
+                       // Always make sure to clean-up
+                       if ( $wikiPage->exists() ) {
+                               $wikiPage->doDeleteArticle( "testing done." );
+                       }
+
+                       $this->assertTrue( $result );
+               } else {
+                       $this->assertTrue( $skip );
+               }
+       }
+
+}

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I2d8fd6dca1811cb74b41f8278bc7af0e2f262b4f
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/SemanticMediaWiki
Gerrit-Branch: master
Gerrit-Owner: Mwjames <jamesin.hongkon...@gmail.com>
Gerrit-Reviewer: Mwjames <jamesin.hongkon...@gmail.com>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to