Mwjames has uploaded a new change for review.

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


Change subject: (Bug 56663) Add PageAnnotationImportIntegrationTest
......................................................................

(Bug 56663) Add PageAnnotationImportIntegrationTest

Load a XML file to simulate a Special:Import in order to verify necessary
components are integrated and working

Foo-1-19-7.xml contains an export from MW 1.19.7

Change-Id: Ie790be6879b818fda0992a97175d8b955d85e546
---
M SemanticMediaWiki.hooks.php
A tests/phpunit/integration/import/Foo-1-19-7.xml
A tests/phpunit/integration/import/PageAnnotationImportIntegrationTest.php
3 files changed, 189 insertions(+), 1 deletion(-)


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

diff --git a/SemanticMediaWiki.hooks.php b/SemanticMediaWiki.hooks.php
index 768e231..0860243 100644
--- a/SemanticMediaWiki.hooks.php
+++ b/SemanticMediaWiki.hooks.php
@@ -271,7 +271,7 @@
        * @return boolean
        */
        public static function registerUnitTests( array &$files ) {
-               $directoryIterator = new RecursiveDirectoryIterator( __DIR__ . 
'/tests/phpunit/includes/' );
+               $directoryIterator = new RecursiveDirectoryIterator( __DIR__ . 
'/tests/phpunit/' );
 
                /**
                 * @var SplFileInfo $fileInfo
diff --git a/tests/phpunit/integration/import/Foo-1-19-7.xml 
b/tests/phpunit/integration/import/Foo-1-19-7.xml
new file mode 100644
index 0000000..355e9a4
--- /dev/null
+++ b/tests/phpunit/integration/import/Foo-1-19-7.xml
@@ -0,0 +1,49 @@
+<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.6/"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.6/ 
http://www.mediawiki.org/xml/export-0.6.xsd"; version="0.6" xml:lang="en-gb">
+  <siteinfo>
+    <sitename>MW-19</sitename>
+    <base>http://localhost:8080/mw-19/index.php/Main_Page</base>
+    <generator>MediaWiki 1.19.7</generator>
+    <case>first-letter</case>
+    <namespaces>
+      <namespace key="-2" case="first-letter">Media</namespace>
+      <namespace key="-1" case="first-letter">Special</namespace>
+      <namespace key="0" case="first-letter" />
+      <namespace key="1" case="first-letter">Talk</namespace>
+      <namespace key="2" case="first-letter">User</namespace>
+      <namespace key="3" case="first-letter">User talk</namespace>
+      <namespace key="4" case="first-letter">MW-19</namespace>
+      <namespace key="5" case="first-letter">MW-19 talk</namespace>
+      <namespace key="6" case="first-letter">File</namespace>
+      <namespace key="7" case="first-letter">File talk</namespace>
+      <namespace key="8" case="first-letter">MediaWiki</namespace>
+      <namespace key="9" case="first-letter">MediaWiki talk</namespace>
+      <namespace key="10" case="first-letter">Template</namespace>
+      <namespace key="11" case="first-letter">Template talk</namespace>
+      <namespace key="12" case="first-letter">Help</namespace>
+      <namespace key="13" case="first-letter">Help talk</namespace>
+      <namespace key="14" case="first-letter">Category</namespace>
+      <namespace key="15" case="first-letter">Category talk</namespace>
+      <namespace key="102" case="first-letter">Property</namespace>
+      <namespace key="103" case="first-letter">Property talk</namespace>
+      <namespace key="108" case="first-letter">Concept</namespace>
+      <namespace key="109" case="first-letter">Concept talk</namespace>
+      <namespace key="160" case="first-letter">Foo</namespace>
+      <namespace key="161" case="first-letter">Foo talk</namespace>
+    </namespaces>
+  </siteinfo>
+  <page>
+    <title>Foo-1-19-7</title>
+    <ns>0</ns>
+    <id>158</id>
+      <sha1>9wpxa9p7kacx4vbfdqfjo7nx3pz9yr6</sha1>
+    <revision>
+      <id>389</id>
+      <timestamp>2013-11-07T14:49:58Z</timestamp>
+      <contributor>
+        <ip>127.0.0.1</ip>
+      </contributor>
+      <comment>Created page with &quot;[[Foo::bar]], {{#subobject:|Qeey=bam}}, 
{{#show: Foo-1-19-7|?Foo}} , {{#ask: [[Modification date::+]]|?Modification 
date}}&quot;</comment>
+      <text xml:space="preserve" bytes="122">[[Foo::bar]], 
{{#subobject:|Qeey=bam}}, {{#show: Foo-1-19-7|?Foo}} , {{#ask: [[Modification 
date::+]]|?Modification date}}</text>
+    </revision>
+  </page>
+</mediawiki>
diff --git 
a/tests/phpunit/integration/import/PageAnnotationImportIntegrationTest.php 
b/tests/phpunit/integration/import/PageAnnotationImportIntegrationTest.php
new file mode 100644
index 0000000..6703876
--- /dev/null
+++ b/tests/phpunit/integration/import/PageAnnotationImportIntegrationTest.php
@@ -0,0 +1,139 @@
+<?php
+
+namespace SMW\Test\Integration;
+
+use SMW\StoreFactory;
+use SMW\SemanticData;
+use SMW\DIWikiPage;
+
+use ImportStreamSource;
+use ImportReporter;
+use WikiImporter;
+use MWException;
+use RequestContext;
+use Title;
+
+/**
+ * This test is to run a sanity check to allows to verify that necessary 
components
+ * (hooks, extensions etc.) do act according to their specification when 
content is
+ * imported
+ *
+ * @ingroup Test
+ *
+ * @group SMW
+ * @group SMWExtension
+ * @group Database
+ * @group medium
+ *
+ * @licence GNU GPL v2+
+ * @since 1.9
+ *
+ * @author mwjames
+ */
+class PageAnnotationImportIntegrationTest extends \MediaWikiTestCase {
+
+       /**
+        * @since 1.9
+        */
+       public function runImporter( $file ) {
+
+               $source = ImportStreamSource::newFromFile( $file );
+
+               $this->assertTrue(
+                       $source->isGood(),
+                       'Assert that the source was available'
+               );
+
+               $importer = new WikiImporter( $source->value );
+
+               $reporter = new ImportReporter(
+                       $importer,
+                       false,
+                       '',
+                       false
+               );
+
+               $reporter->setContext( new RequestContext() );
+               $exception = false;
+
+               $reporter->open();
+
+               try {
+                       $importer->doImport();
+               } catch ( MWException $e ) {
+                       $exception = $e;
+               }
+
+               $result = $reporter->close();
+
+               $this->assertTrue(
+                       $result->isGood(),
+                       'Asserts that the import was successful'
+               );
+
+               return true;
+       }
+
+       /**
+        * @dataProvider importProvider
+        *
+        * @since 1.9
+        */
+       public function testImportRunner( $setup, $expected ) {
+
+               $this->assertFalse(
+                       $setup['title']->exists(),
+                       'Asserts that the Title does not exist prior the import'
+               );
+
+               $this->assertTrue( $this->runImporter( $setup['file'] ) );
+
+               $this->assertTrue(
+                       $setup['title']->exists(),
+                       'Asserts that the Title does exist after the import'
+               );
+
+       }
+
+       /**
+        * @since  1.9
+        */
+       protected function assertProperties( SemanticData $semanticData, array 
$expected ) {
+
+               $properties = $semanticData->getProperties();
+
+               foreach ( $properties as $key => $diproperty ) {
+
+                       $this->assertInstanceOf( '\SMW\DIProperty', $diproperty 
);
+
+                       $this->assertContains(
+                               $diproperty->getKey(),
+                               $expected['propertyKey'],
+                               'Asserts that a specific property key is known'
+                       );
+
+               }
+       }
+
+       /**
+        * @return array
+        */
+       public function importProvider() {
+
+               $provider = array();
+
+               $provider[] = array(
+                       array(
+                               'file'  => __DIR__ . '/' . 'Foo-1-19-7.xml',
+                               'title' => Title::newFromText( 'Foo-1-19-7' )
+                       ),
+                       array(
+                               'propertyKey' => array( 'Foo', '_ASK', '_LEDT', 
'_MDAT', '_SKEY', '_SOBJ' ),
+                       ),
+               );
+
+               return $provider;
+
+       }
+
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie790be6879b818fda0992a97175d8b955d85e546
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