2015-02-12 00:24:23 +00:00
|
|
|
<?php
|
2016-11-22 23:39:22 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
|
|
2015-02-12 00:24:23 +00:00
|
|
|
/**
|
|
|
|
|
* Integration test that checks import success and
|
|
|
|
|
* LinkCache integration.
|
|
|
|
|
*
|
2018-03-29 19:53:10 +00:00
|
|
|
* @group large
|
2015-02-12 00:24:23 +00:00
|
|
|
* @group Database
|
2018-03-20 16:14:34 +00:00
|
|
|
* @covers ImportStreamSource
|
|
|
|
|
* @covers ImportReporter
|
2015-02-12 00:24:23 +00:00
|
|
|
*
|
|
|
|
|
* @author mwjames
|
|
|
|
|
*/
|
|
|
|
|
class ImportLinkCacheIntegrationTest extends MediaWikiTestCase {
|
|
|
|
|
|
|
|
|
|
private $importStreamSource;
|
|
|
|
|
|
|
|
|
|
protected function setUp() {
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
2016-01-04 09:59:29 +00:00
|
|
|
$file = dirname( __DIR__ ) . '/../data/import/ImportLinkCacheIntegrationTest.xml';
|
2015-02-12 00:24:23 +00:00
|
|
|
|
|
|
|
|
$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,
|
2016-11-22 23:39:22 +00:00
|
|
|
MediaWikiServices::getInstance()->getMainConfig()
|
2015-02-12 00:24:23 +00:00
|
|
|
);
|
|
|
|
|
$importer->setDebug( true );
|
|
|
|
|
|
|
|
|
|
$reporter = new ImportReporter(
|
|
|
|
|
$importer,
|
|
|
|
|
false,
|
|
|
|
|
'',
|
|
|
|
|
false
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$reporter->setContext( new RequestContext() );
|
|
|
|
|
$reporter->open();
|
|
|
|
|
|
2018-03-13 19:32:18 +00:00
|
|
|
$importer->doImport();
|
2015-02-12 00:24:23 +00:00
|
|
|
|
|
|
|
|
$result = $reporter->close();
|
|
|
|
|
|
|
|
|
|
$this->assertTrue(
|
|
|
|
|
$result->isGood()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|