Tests: Reflect recent changes to MediaWiki import structure
authorgeorggi <bmp2558@gmail.com>
Mon, 4 Jan 2016 09:59:29 +0000 (11:59 +0200)
committergeorggi <bmp2558@gmail.com>
Tue, 5 Jan 2016 12:08:31 +0000 (14:08 +0200)
Bug: T43938
Change-Id: Id8d40d8fa0de59ac07749b3cefdd627b98fe175e

tests/phpunit/includes/ImportLinkCacheIntegrationTest.php [deleted file]
tests/phpunit/includes/ImportTest.php [deleted file]
tests/phpunit/includes/import/ImportLinkCacheIntegrationTest.php [new file with mode: 0644]
tests/phpunit/includes/import/ImportTest.php [new file with mode: 0644]

diff --git a/tests/phpunit/includes/ImportLinkCacheIntegrationTest.php b/tests/phpunit/includes/ImportLinkCacheIntegrationTest.php
deleted file mode 100644 (file)
index 1433b89..0000000
+++ /dev/null
@@ -1,112 +0,0 @@
-<?php
-/**
- * Integration test that checks import success and
- * LinkCache integration.
- *
- * @group medium
- * @group Database
- *
- * @author mwjames
- */
-class ImportLinkCacheIntegrationTest extends MediaWikiTestCase {
-
-       private $importStreamSource;
-
-       protected function setUp() {
-               parent::setUp();
-
-               $file = dirname( __DIR__ ) . '/data/import/ImportLinkCacheIntegrationTest.xml';
-
-               $this->importStreamSource = ImportStreamSource::newFromFile( $file );
-
-               if ( !$this->importStreamSource->isGood() ) {
-                       throw new Exception( "Import source for {$file} failed" );
-               }
-       }
-
-       public function testImportForImportSource() {
-
-               $this->doImport( $this->importStreamSource );
-
-               // Imported title
-               $loremIpsum = Title::newFromText( 'Lorem ipsum' );
-
-               $this->assertSame(
-                       $loremIpsum->getArticleID(),
-                       $loremIpsum->getArticleID( Title::GAID_FOR_UPDATE )
-               );
-
-               $categoryLoremIpsum = Title::newFromText( 'Category:Lorem ipsum' );
-
-               $this->assertSame(
-                       $categoryLoremIpsum->getArticleID(),
-                       $categoryLoremIpsum->getArticleID( Title::GAID_FOR_UPDATE )
-               );
-
-               $page = new WikiPage( $loremIpsum );
-               $page->doDeleteArticle( 'import test: delete page' );
-
-               $page = new WikiPage( $categoryLoremIpsum );
-               $page->doDeleteArticle( 'import test: delete page' );
-       }
-
-       /**
-        * @depends testImportForImportSource
-        */
-       public function testReImportForImportSource() {
-
-               $this->doImport( $this->importStreamSource );
-
-               // ReImported title
-               $loremIpsum = Title::newFromText( 'Lorem ipsum' );
-
-               $this->assertSame(
-                       $loremIpsum->getArticleID(),
-                       $loremIpsum->getArticleID( Title::GAID_FOR_UPDATE )
-               );
-
-               $categoryLoremIpsum = Title::newFromText( 'Category:Lorem ipsum' );
-
-               $this->assertSame(
-                       $categoryLoremIpsum->getArticleID(),
-                       $categoryLoremIpsum->getArticleID( Title::GAID_FOR_UPDATE )
-               );
-       }
-
-       private function doImport( $importStreamSource ) {
-
-               $importer = new WikiImporter(
-                       $importStreamSource->value,
-                       ConfigFactory::getDefaultInstance()->makeConfig( 'main' )
-               );
-               $importer->setDebug( true );
-
-               $reporter = new ImportReporter(
-                       $importer,
-                       false,
-                       '',
-                       false
-               );
-
-               $reporter->setContext( new RequestContext() );
-               $reporter->open();
-               $exception = false;
-
-               try {
-                       $importer->doImport();
-               } catch ( Exception $e ) {
-                       $exception = $e;
-               }
-
-               $result = $reporter->close();
-
-               $this->assertFalse(
-                       $exception
-               );
-
-               $this->assertTrue(
-                       $result->isGood()
-               );
-       }
-
-}
diff --git a/tests/phpunit/includes/ImportTest.php b/tests/phpunit/includes/ImportTest.php
deleted file mode 100644 (file)
index 9c22430..0000000
+++ /dev/null
@@ -1,162 +0,0 @@
-<?php
-
-/**
- * Test class for Import methods.
- *
- * @group Database
- *
- * @author Sebastian Brückner < sebastian.brueckner@student.hpi.uni-potsdam.de >
- */
-class ImportTest extends MediaWikiLangTestCase {
-
-       private function getDataSource( $xml ) {
-               return new ImportStringSource( $xml );
-       }
-
-       /**
-        * @covers WikiImporter::handlePage
-        * @dataProvider getRedirectXML
-        * @param string $xml
-        * @param string|null $redirectTitle
-        */
-       public function testHandlePageContainsRedirect( $xml, $redirectTitle ) {
-               $source = $this->getDataSource( $xml );
-
-               $redirect = null;
-               $callback = function ( Title $title, ForeignTitle $foreignTitle, $revCount,
-                       $sRevCount, $pageInfo ) use ( &$redirect ) {
-                       if ( array_key_exists( 'redirect', $pageInfo ) ) {
-                               $redirect = $pageInfo['redirect'];
-                       }
-               };
-
-               $importer = new WikiImporter(
-                       $source,
-                       ConfigFactory::getDefaultInstance()->makeConfig( 'main' )
-               );
-               $importer->setPageOutCallback( $callback );
-               $importer->doImport();
-
-               $this->assertEquals( $redirectTitle, $redirect );
-       }
-
-       public function getRedirectXML() {
-               // @codingStandardsIgnoreStart Generic.Files.LineLength
-               return array(
-                       array(
-                               <<< EOF
-<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.10/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.10/ http://www.mediawiki.org/xml/export-0.10.xsd" version="0.10" xml:lang="en">
-       <page>
-               <title>Test</title>
-               <ns>0</ns>
-               <id>21</id>
-               <redirect title="Test22"/>
-               <revision>
-                       <id>20</id>
-                       <timestamp>2014-05-27T10:00:00Z</timestamp>
-                       <contributor>
-                               <username>Admin</username>
-                               <id>10</id>
-                       </contributor>
-                       <comment>Admin moved page [[Test]] to [[Test22]]</comment>
-                       <model>wikitext</model>
-                       <format>text/x-wiki</format>
-                       <text xml:space="preserve" bytes="20">#REDIRECT [[Test22]]</text>
-                       <sha1>tq456o9x3abm7r9ozi6km8yrbbc56o6</sha1>
-               </revision>
-       </page>
-</mediawiki>
-EOF
-                       ,
-                               'Test22'
-                       ),
-                       array(
-                               <<< EOF
-<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.9/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.9/ http://www.mediawiki.org/xml/export-0.9.xsd" version="0.9" xml:lang="en">
-       <page>
-               <title>Test</title>
-               <ns>0</ns>
-               <id>42</id>
-               <revision>
-                       <id>421</id>
-                       <timestamp>2014-05-27T11:00:00Z</timestamp>
-                       <contributor>
-                               <username>Admin</username>
-                               <id>10</id>
-                       </contributor>
-                       <text xml:space="preserve" bytes="4">Abcd</text>
-                       <sha1>n7uomjq96szt60fy5w3x7ahf7q8m8rh</sha1>
-                       <model>wikitext</model>
-                       <format>text/x-wiki</format>
-               </revision>
-       </page>
-</mediawiki>
-EOF
-                       ,
-                               null
-                       ),
-               );
-               // @codingStandardsIgnoreEnd
-       }
-
-       /**
-        * @covers WikiImporter::handleSiteInfo
-        * @dataProvider getSiteInfoXML
-        * @param string $xml
-        * @param array|null $namespaces
-        */
-       public function testSiteInfoContainsNamespaces( $xml, $namespaces ) {
-               $source = $this->getDataSource( $xml );
-
-               $importNamespaces = null;
-               $callback = function ( array $siteinfo, $innerImporter ) use ( &$importNamespaces ) {
-                       $importNamespaces = $siteinfo['_namespaces'];
-               };
-
-               $importer = new WikiImporter(
-                       $source,
-                       ConfigFactory::getDefaultInstance()->makeConfig( 'main' )
-               );
-               $importer->setSiteInfoCallback( $callback );
-               $importer->doImport();
-
-               $this->assertEquals( $importNamespaces, $namespaces );
-       }
-
-       public function getSiteInfoXML() {
-               // @codingStandardsIgnoreStart Generic.Files.LineLength
-               return array(
-                       array(
-                               <<< EOF
-<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.10/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.10/ http://www.mediawiki.org/xml/export-0.10.xsd" version="0.10" xml:lang="en">
-  <siteinfo>
-    <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="100" case="first-letter">Portal</namespace>
-      <namespace key="101" case="first-letter">Portal talk</namespace>
-    </namespaces>
-  </siteinfo>
-</mediawiki>
-EOF
-                       ,
-                               array(
-                                       '-2' => 'Media',
-                                       '-1' => 'Special',
-                                       '0' => '',
-                                       '1' => 'Talk',
-                                       '2' => 'User',
-                                       '3' => 'User talk',
-                                       '100' => 'Portal',
-                                       '101' => 'Portal talk',
-                               )
-                       ),
-               );
-               // @codingStandardsIgnoreEnd
-       }
-
-}
diff --git a/tests/phpunit/includes/import/ImportLinkCacheIntegrationTest.php b/tests/phpunit/includes/import/ImportLinkCacheIntegrationTest.php
new file mode 100644 (file)
index 0000000..5e3c626
--- /dev/null
@@ -0,0 +1,112 @@
+<?php
+/**
+ * Integration test that checks import success and
+ * LinkCache integration.
+ *
+ * @group medium
+ * @group Database
+ *
+ * @author mwjames
+ */
+class ImportLinkCacheIntegrationTest extends MediaWikiTestCase {
+
+       private $importStreamSource;
+
+       protected function setUp() {
+               parent::setUp();
+
+               $file = dirname( __DIR__ ) . '/../data/import/ImportLinkCacheIntegrationTest.xml';
+
+               $this->importStreamSource = ImportStreamSource::newFromFile( $file );
+
+               if ( !$this->importStreamSource->isGood() ) {
+                       throw new Exception( "Import source for {$file} failed" );
+               }
+       }
+
+       public function testImportForImportSource() {
+
+               $this->doImport( $this->importStreamSource );
+
+               // Imported title
+               $loremIpsum = Title::newFromText( 'Lorem ipsum' );
+
+               $this->assertSame(
+                       $loremIpsum->getArticleID(),
+                       $loremIpsum->getArticleID( Title::GAID_FOR_UPDATE )
+               );
+
+               $categoryLoremIpsum = Title::newFromText( 'Category:Lorem ipsum' );
+
+               $this->assertSame(
+                       $categoryLoremIpsum->getArticleID(),
+                       $categoryLoremIpsum->getArticleID( Title::GAID_FOR_UPDATE )
+               );
+
+               $page = new WikiPage( $loremIpsum );
+               $page->doDeleteArticle( 'import test: delete page' );
+
+               $page = new WikiPage( $categoryLoremIpsum );
+               $page->doDeleteArticle( 'import test: delete page' );
+       }
+
+       /**
+        * @depends testImportForImportSource
+        */
+       public function testReImportForImportSource() {
+
+               $this->doImport( $this->importStreamSource );
+
+               // ReImported title
+               $loremIpsum = Title::newFromText( 'Lorem ipsum' );
+
+               $this->assertSame(
+                       $loremIpsum->getArticleID(),
+                       $loremIpsum->getArticleID( Title::GAID_FOR_UPDATE )
+               );
+
+               $categoryLoremIpsum = Title::newFromText( 'Category:Lorem ipsum' );
+
+               $this->assertSame(
+                       $categoryLoremIpsum->getArticleID(),
+                       $categoryLoremIpsum->getArticleID( Title::GAID_FOR_UPDATE )
+               );
+       }
+
+       private function doImport( $importStreamSource ) {
+
+               $importer = new WikiImporter(
+                       $importStreamSource->value,
+                       ConfigFactory::getDefaultInstance()->makeConfig( 'main' )
+               );
+               $importer->setDebug( true );
+
+               $reporter = new ImportReporter(
+                       $importer,
+                       false,
+                       '',
+                       false
+               );
+
+               $reporter->setContext( new RequestContext() );
+               $reporter->open();
+               $exception = false;
+
+               try {
+                       $importer->doImport();
+               } catch ( Exception $e ) {
+                       $exception = $e;
+               }
+
+               $result = $reporter->close();
+
+               $this->assertFalse(
+                       $exception
+               );
+
+               $this->assertTrue(
+                       $result->isGood()
+               );
+       }
+
+}
diff --git a/tests/phpunit/includes/import/ImportTest.php b/tests/phpunit/includes/import/ImportTest.php
new file mode 100644 (file)
index 0000000..9c22430
--- /dev/null
@@ -0,0 +1,162 @@
+<?php
+
+/**
+ * Test class for Import methods.
+ *
+ * @group Database
+ *
+ * @author Sebastian Brückner < sebastian.brueckner@student.hpi.uni-potsdam.de >
+ */
+class ImportTest extends MediaWikiLangTestCase {
+
+       private function getDataSource( $xml ) {
+               return new ImportStringSource( $xml );
+       }
+
+       /**
+        * @covers WikiImporter::handlePage
+        * @dataProvider getRedirectXML
+        * @param string $xml
+        * @param string|null $redirectTitle
+        */
+       public function testHandlePageContainsRedirect( $xml, $redirectTitle ) {
+               $source = $this->getDataSource( $xml );
+
+               $redirect = null;
+               $callback = function ( Title $title, ForeignTitle $foreignTitle, $revCount,
+                       $sRevCount, $pageInfo ) use ( &$redirect ) {
+                       if ( array_key_exists( 'redirect', $pageInfo ) ) {
+                               $redirect = $pageInfo['redirect'];
+                       }
+               };
+
+               $importer = new WikiImporter(
+                       $source,
+                       ConfigFactory::getDefaultInstance()->makeConfig( 'main' )
+               );
+               $importer->setPageOutCallback( $callback );
+               $importer->doImport();
+
+               $this->assertEquals( $redirectTitle, $redirect );
+       }
+
+       public function getRedirectXML() {
+               // @codingStandardsIgnoreStart Generic.Files.LineLength
+               return array(
+                       array(
+                               <<< EOF
+<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.10/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.10/ http://www.mediawiki.org/xml/export-0.10.xsd" version="0.10" xml:lang="en">
+       <page>
+               <title>Test</title>
+               <ns>0</ns>
+               <id>21</id>
+               <redirect title="Test22"/>
+               <revision>
+                       <id>20</id>
+                       <timestamp>2014-05-27T10:00:00Z</timestamp>
+                       <contributor>
+                               <username>Admin</username>
+                               <id>10</id>
+                       </contributor>
+                       <comment>Admin moved page [[Test]] to [[Test22]]</comment>
+                       <model>wikitext</model>
+                       <format>text/x-wiki</format>
+                       <text xml:space="preserve" bytes="20">#REDIRECT [[Test22]]</text>
+                       <sha1>tq456o9x3abm7r9ozi6km8yrbbc56o6</sha1>
+               </revision>
+       </page>
+</mediawiki>
+EOF
+                       ,
+                               'Test22'
+                       ),
+                       array(
+                               <<< EOF
+<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.9/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.9/ http://www.mediawiki.org/xml/export-0.9.xsd" version="0.9" xml:lang="en">
+       <page>
+               <title>Test</title>
+               <ns>0</ns>
+               <id>42</id>
+               <revision>
+                       <id>421</id>
+                       <timestamp>2014-05-27T11:00:00Z</timestamp>
+                       <contributor>
+                               <username>Admin</username>
+                               <id>10</id>
+                       </contributor>
+                       <text xml:space="preserve" bytes="4">Abcd</text>
+                       <sha1>n7uomjq96szt60fy5w3x7ahf7q8m8rh</sha1>
+                       <model>wikitext</model>
+                       <format>text/x-wiki</format>
+               </revision>
+       </page>
+</mediawiki>
+EOF
+                       ,
+                               null
+                       ),
+               );
+               // @codingStandardsIgnoreEnd
+       }
+
+       /**
+        * @covers WikiImporter::handleSiteInfo
+        * @dataProvider getSiteInfoXML
+        * @param string $xml
+        * @param array|null $namespaces
+        */
+       public function testSiteInfoContainsNamespaces( $xml, $namespaces ) {
+               $source = $this->getDataSource( $xml );
+
+               $importNamespaces = null;
+               $callback = function ( array $siteinfo, $innerImporter ) use ( &$importNamespaces ) {
+                       $importNamespaces = $siteinfo['_namespaces'];
+               };
+
+               $importer = new WikiImporter(
+                       $source,
+                       ConfigFactory::getDefaultInstance()->makeConfig( 'main' )
+               );
+               $importer->setSiteInfoCallback( $callback );
+               $importer->doImport();
+
+               $this->assertEquals( $importNamespaces, $namespaces );
+       }
+
+       public function getSiteInfoXML() {
+               // @codingStandardsIgnoreStart Generic.Files.LineLength
+               return array(
+                       array(
+                               <<< EOF
+<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.10/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.10/ http://www.mediawiki.org/xml/export-0.10.xsd" version="0.10" xml:lang="en">
+  <siteinfo>
+    <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="100" case="first-letter">Portal</namespace>
+      <namespace key="101" case="first-letter">Portal talk</namespace>
+    </namespaces>
+  </siteinfo>
+</mediawiki>
+EOF
+                       ,
+                               array(
+                                       '-2' => 'Media',
+                                       '-1' => 'Special',
+                                       '0' => '',
+                                       '1' => 'Talk',
+                                       '2' => 'User',
+                                       '3' => 'User talk',
+                                       '100' => 'Portal',
+                                       '101' => 'Portal talk',
+                               )
+                       ),
+               );
+               // @codingStandardsIgnoreEnd
+       }
+
+}