2015-02-12 00:24:23 +00:00
|
|
|
<?php
|
2019-05-28 14:04:23 +00:00
|
|
|
|
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
|
|
|
|
|
*/
|
2020-06-30 15:09:24 +00:00
|
|
|
class ImportLinkCacheIntegrationTest extends MediaWikiIntegrationTestCase {
|
2015-02-12 00:24:23 +00:00
|
|
|
|
|
|
|
|
private $importStreamSource;
|
|
|
|
|
|
2021-07-22 03:11:47 +00:00
|
|
|
protected function setUp(): void {
|
2015-02-12 00:24:23 +00:00
|
|
|
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
|
2022-07-05 22:21:30 +00:00
|
|
|
$loremIpsum = Title::makeTitle( NS_MAIN, 'Lorem ipsum' );
|
2015-02-12 00:24:23 +00:00
|
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
$loremIpsum->getArticleID(),
|
2023-04-21 09:33:11 +00:00
|
|
|
$loremIpsum->getArticleID( Title::READ_LATEST )
|
2015-02-12 00:24:23 +00:00
|
|
|
);
|
|
|
|
|
|
2022-07-05 22:21:30 +00:00
|
|
|
$categoryLoremIpsum = Title::makeTitle( NS_CATEGORY, 'Lorem ipsum' );
|
2015-02-12 00:24:23 +00:00
|
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
$categoryLoremIpsum->getArticleID(),
|
2023-04-21 09:33:11 +00:00
|
|
|
$categoryLoremIpsum->getArticleID( Title::READ_LATEST )
|
2015-02-12 00:24:23 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @depends testImportForImportSource
|
|
|
|
|
*/
|
|
|
|
|
public function testReImportForImportSource() {
|
|
|
|
|
$this->doImport( $this->importStreamSource );
|
|
|
|
|
|
|
|
|
|
// ReImported title
|
2022-07-05 22:21:30 +00:00
|
|
|
$loremIpsum = Title::makeTitle( NS_MAIN, 'Lorem ipsum' );
|
2015-02-12 00:24:23 +00:00
|
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
$loremIpsum->getArticleID(),
|
2023-04-21 09:33:11 +00:00
|
|
|
$loremIpsum->getArticleID( Title::READ_LATEST )
|
2015-02-12 00:24:23 +00:00
|
|
|
);
|
|
|
|
|
|
2022-07-05 22:21:30 +00:00
|
|
|
$categoryLoremIpsum = Title::makeTitle( NS_CATEGORY, 'Lorem ipsum' );
|
2015-02-12 00:24:23 +00:00
|
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
$categoryLoremIpsum->getArticleID(),
|
2023-04-21 09:33:11 +00:00
|
|
|
$categoryLoremIpsum->getArticleID( Title::READ_LATEST )
|
2015-02-12 00:24:23 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function doImport( $importStreamSource ) {
|
2021-05-14 23:16:34 +00:00
|
|
|
$importer = $this->getServiceContainer()
|
|
|
|
|
->getWikiImporterFactory()
|
|
|
|
|
->getWikiImporter( $importStreamSource->value );
|
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()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|