Mwjames has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/90736


Change subject: Add FunctionHookIntegrationTest
......................................................................

Add FunctionHookIntegrationTest

Change-Id: I23e0840909a9561e5928590b2728716812608dbd
---
A tests/phpunit/includes/parserhooks/FunctionHookIntegrationTest.php
1 file changed, 171 insertions(+), 0 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticMediaWiki 
refs/changes/36/90736/1

diff --git a/tests/phpunit/includes/parserhooks/FunctionHookIntegrationTest.php 
b/tests/phpunit/includes/parserhooks/FunctionHookIntegrationTest.php
new file mode 100644
index 0000000..80dde77
--- /dev/null
+++ b/tests/phpunit/includes/parserhooks/FunctionHookIntegrationTest.php
@@ -0,0 +1,171 @@
+<?php
+
+namespace SMW\Test;
+
+use SMW\NewRevisionFromEditComplete;
+use SMW\OutputPageParserOutput;
+use SMW\ArticlePurge;
+use SMW\BaseContext;
+
+use WikiPage;
+use Title;
+
+/**
+ * @covers \SMW\FunctionHook
+ *
+ * @ingroup Test
+ *
+ * @group SMW
+ * @group SMWExtension
+ * @group Database
+ *
+ * @licence GNU GPL v2+
+ * @since 1.9
+ *
+ * @author mwjames
+ */
+class FunctionHookIntegrationTest extends \MediaWikiTestCase {
+
+       /**
+        * @return string|false
+        */
+       public function getClass() {
+               return false;
+       }
+
+       /**
+        * @since 1.9
+        */
+       public function newWikiPage( $text = 'Foo' ) {
+
+               if ( !method_exists( 'WikiPage', 'doEditContent' ) ) {
+                       $this->markTestSkipped(
+                               'Skipped test due to missing method (probably 
MW 1.19 or lower).'
+                       );
+               }
+
+               $wikiPage = new WikiPage( Title::newFromText( $text ) );
+               $user = new MockSuperUser();
+
+               $content = \ContentHandler::makeContent(
+                       'testing',
+                       $wikiPage->getTitle(),
+                       CONTENT_MODEL_WIKITEXT
+               );
+
+               $wikiPage->doEditContent( $content, "testing " . __METHOD__, 
EDIT_NEW, false, $user );
+
+               return $wikiPage;
+       }
+
+       /**
+        * @since 1.9
+        */
+       public function testOnArticlePurgeOnDatabase() {
+
+               $wikiPage = $this->newWikiPage();
+
+               $instance = new ArticlePurge( $wikiPage );
+               $instance->invokeContext( new BaseContext() );
+
+               $this->assertTrue( $instance->process() );
+
+               // Always make sure to clean-up
+               if ( $wikiPage->exists() ) {
+                       $wikiPage->doDeleteArticle( "testing done on " . 
__METHOD__ );
+               }
+
+       }
+
+       /**
+        * @since 1.9
+        */
+       public function testOnNewRevisionFromEditCompleteOnDatabase() {
+
+               $wikiPage = $this->newWikiPage( 'Bam' );
+
+               $this->assertTrue( $wikiPage->getId() > 0, "WikiPage should 
have new page id" );
+               $revision = $wikiPage->getRevision();
+
+               $instance = new NewRevisionFromEditComplete( $wikiPage, 
$revision, $wikiPage->getId(), $user );
+               $instance->invokeContext( new BaseContext() );
+
+               $this->assertTrue( $instance->process() );
+
+               // Always make sure the clean-up
+               if ( $wikiPage->exists() ) {
+                       $wikiPage->doDeleteArticle( "testing done on " . 
__METHOD__ );
+               }
+
+       }
+
+       /**
+        * @since 1.9
+        */
+       public function testOnOutputPageParserOutputeOnDatabase() {
+
+               $text = __METHOD__;
+               $wikiPage = $this->newWikiPage( 'Bar' );
+
+               $title = $wikiPage->getTitle();
+
+               $parserOutput = new \ParserOutput();
+               $parserOutput->setTitleText( $title->getPrefixedText() );
+
+               $context = new \RequestContext();
+               $context->setTitle( $title );
+               $outputPage = new \OutputPage( $context );
+
+               $instance = new OutputPageParserOutput( $outputPage, 
$parserOutput );
+               $instance->invokeContext( new BaseContext() );
+
+               $this->assertTrue( $instance->process() );
+
+               // Always make sure the clean-up
+               if ( $wikiPage->exists() ) {
+                       $wikiPage->doDeleteArticle( "testing done on " . 
__METHOD__ );
+               }
+
+       }
+
+       /**
+        * @since 1.9
+        */
+       public function testTitleMoveCompleteOnDatabase() {
+
+               // 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/90736
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I23e0840909a9561e5928590b2728716812608dbd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticMediaWiki
Gerrit-Branch: master
Gerrit-Owner: Mwjames <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to