From: georggi Date: Mon, 4 Jan 2016 09:59:29 +0000 (+0200) Subject: Tests: Reflect recent changes to MediaWiki import structure X-Git-Tag: 1.31.0-rc.0~8448^2 X-Git-Url: http://git.cyclocoop.org/wiki/%7B%7Bpath%7D%7Dmw-config/index.php?a=commitdiff_plain;h=bf9f4141b77593cc99452add82f06fe4b91a6573;p=lhc%2Fweb%2Fwiklou.git Tests: Reflect recent changes to MediaWiki import structure Bug: T43938 Change-Id: Id8d40d8fa0de59ac07749b3cefdd627b98fe175e --- diff --git a/tests/phpunit/includes/ImportLinkCacheIntegrationTest.php b/tests/phpunit/includes/ImportLinkCacheIntegrationTest.php deleted file mode 100644 index 1433b898d0..0000000000 --- a/tests/phpunit/includes/ImportLinkCacheIntegrationTest.php +++ /dev/null @@ -1,112 +0,0 @@ -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 index 9c224309bb..0000000000 --- a/tests/phpunit/includes/ImportTest.php +++ /dev/null @@ -1,162 +0,0 @@ - - */ -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 - - - Test - 0 - 21 - - - 20 - 2014-05-27T10:00:00Z - - Admin - 10 - - Admin moved page [[Test]] to [[Test22]] - wikitext - text/x-wiki - #REDIRECT [[Test22]] - tq456o9x3abm7r9ozi6km8yrbbc56o6 - - - -EOF - , - 'Test22' - ), - array( - <<< EOF - - - Test - 0 - 42 - - 421 - 2014-05-27T11:00:00Z - - Admin - 10 - - Abcd - n7uomjq96szt60fy5w3x7ahf7q8m8rh - wikitext - text/x-wiki - - - -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 - - - - Media - Special - - Talk - User - User talk - Portal - Portal talk - - - -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 index 0000000000..5e3c6268aa --- /dev/null +++ b/tests/phpunit/includes/import/ImportLinkCacheIntegrationTest.php @@ -0,0 +1,112 @@ +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 index 0000000000..9c224309bb --- /dev/null +++ b/tests/phpunit/includes/import/ImportTest.php @@ -0,0 +1,162 @@ + + */ +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 + + + Test + 0 + 21 + + + 20 + 2014-05-27T10:00:00Z + + Admin + 10 + + Admin moved page [[Test]] to [[Test22]] + wikitext + text/x-wiki + #REDIRECT [[Test22]] + tq456o9x3abm7r9ozi6km8yrbbc56o6 + + + +EOF + , + 'Test22' + ), + array( + <<< EOF + + + Test + 0 + 42 + + 421 + 2014-05-27T11:00:00Z + + Admin + 10 + + Abcd + n7uomjq96szt60fy5w3x7ahf7q8m8rh + wikitext + text/x-wiki + + + +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 + + + + Media + Special + + Talk + User + User talk + Portal + Portal talk + + + +EOF + , + array( + '-2' => 'Media', + '-1' => 'Special', + '0' => '', + '1' => 'Talk', + '2' => 'User', + '3' => 'User talk', + '100' => 'Portal', + '101' => 'Portal talk', + ) + ), + ); + // @codingStandardsIgnoreEnd + } + +}