| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Context\RequestContext; |
| 4 |
use MediaWiki\Status\Status; |
| 5 |
use MediaWiki\Title\Title; |
| 6 |
use Wikimedia\Rdbms\IDBAccessObject; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
class ImportLinkCacheIntegrationTest extends MediaWikiIntegrationTestCase { |
| 20 |
|
| 21 |
|
| 22 |
private $importStreamSource; |
| 23 |
|
| 24 |
protected function setUp(): void { |
| 25 |
parent::setUp(); |
| 26 |
|
| 27 |
$file = dirname( __DIR__ ) . '/../data/import/ImportLinkCacheIntegrationTest.xml'; |
| 28 |
|
| 29 |
$this->importStreamSource = ImportStreamSource::newFromFile( $file ); |
| 30 |
|
| 31 |
if ( !$this->importStreamSource->isGood() ) { |
| 32 |
$this->fail( "Import source for {$file} failed" ); |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
public function testImportForImportSource() { |
| 37 |
$this->doImport( $this->importStreamSource ); |
| 38 |
|
| 39 |
|
| 40 |
$loremIpsum = Title::makeTitle( NS_MAIN, 'Lorem ipsum' ); |
| 41 |
|
| 42 |
$this->assertSame( |
| 43 |
$loremIpsum->getArticleID(), |
| 44 |
$loremIpsum->getArticleID( IDBAccessObject::READ_LATEST ) |
| 45 |
); |
| 46 |
|
| 47 |
$categoryLoremIpsum = Title::makeTitle( NS_CATEGORY, 'Lorem ipsum' ); |
| 48 |
|
| 49 |
$this->assertSame( |
| 50 |
$categoryLoremIpsum->getArticleID(), |
| 51 |
$categoryLoremIpsum->getArticleID( IDBAccessObject::READ_LATEST ) |
| 52 |
); |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
public function testReImportForImportSource() { |
| 59 |
$this->doImport( $this->importStreamSource ); |
| 60 |
|
| 61 |
|
| 62 |
$loremIpsum = Title::makeTitle( NS_MAIN, 'Lorem ipsum' ); |
| 63 |
|
| 64 |
$this->assertSame( |
| 65 |
$loremIpsum->getArticleID(), |
| 66 |
$loremIpsum->getArticleID( IDBAccessObject::READ_LATEST ) |
| 67 |
); |
| 68 |
|
| 69 |
$categoryLoremIpsum = Title::makeTitle( NS_CATEGORY, 'Lorem ipsum' ); |
| 70 |
|
| 71 |
$this->assertSame( |
| 72 |
$categoryLoremIpsum->getArticleID(), |
| 73 |
$categoryLoremIpsum->getArticleID( IDBAccessObject::READ_LATEST ) |
| 74 |
); |
| 75 |
} |
| 76 |
|
| 77 |
private function doImport( $importStreamSource ) { |
| 78 |
$importer = $this->getServiceContainer() |
| 79 |
->getWikiImporterFactory() |
| 80 |
->getWikiImporter( $importStreamSource->value, $this->getTestSysop()->getAuthority() ); |
| 81 |
$importer->setDebug( true ); |
| 82 |
|
| 83 |
$context = RequestContext::getMain(); |
| 84 |
$context->setUser( $this->getTestUser()->getUser() ); |
| 85 |
$reporter = new ImportReporter( |
| 86 |
$importer, |
| 87 |
false, |
| 88 |
'', |
| 89 |
false, |
| 90 |
$context |
| 91 |
); |
| 92 |
|
| 93 |
$reporter->open(); |
| 94 |
$importer->doImport(); |
| 95 |
$this->assertStatusGood( $reporter->close() ); |
| 96 |
} |
| 97 |
|
| 98 |
} |