Merge "Update docs/hooks.txt for ShowSearchHitTitle"
[mediawiki.git] / tests / phpunit / includes / import / ImportLinkCacheIntegrationTest.php
blob8e06f9e968f836aeb8585ad745cd80538722df64
1 <?php
2 use MediaWiki\MediaWikiServices;
4 /**
5 * Integration test that checks import success and
6 * LinkCache integration.
8 * @group medium
9 * @group Database
11 * @author mwjames
13 class ImportLinkCacheIntegrationTest extends MediaWikiTestCase {
15 private $importStreamSource;
17 protected function setUp() {
18 parent::setUp();
20 $file = dirname( __DIR__ ) . '/../data/import/ImportLinkCacheIntegrationTest.xml';
22 $this->importStreamSource = ImportStreamSource::newFromFile( $file );
24 if ( !$this->importStreamSource->isGood() ) {
25 throw new Exception( "Import source for {$file} failed" );
29 public function testImportForImportSource() {
31 $this->doImport( $this->importStreamSource );
33 // Imported title
34 $loremIpsum = Title::newFromText( 'Lorem ipsum' );
36 $this->assertSame(
37 $loremIpsum->getArticleID(),
38 $loremIpsum->getArticleID( Title::GAID_FOR_UPDATE )
41 $categoryLoremIpsum = Title::newFromText( 'Category:Lorem ipsum' );
43 $this->assertSame(
44 $categoryLoremIpsum->getArticleID(),
45 $categoryLoremIpsum->getArticleID( Title::GAID_FOR_UPDATE )
48 $page = new WikiPage( $loremIpsum );
49 $page->doDeleteArticle( 'import test: delete page' );
51 $page = new WikiPage( $categoryLoremIpsum );
52 $page->doDeleteArticle( 'import test: delete page' );
55 /**
56 * @depends testImportForImportSource
58 public function testReImportForImportSource() {
60 $this->doImport( $this->importStreamSource );
62 // ReImported title
63 $loremIpsum = Title::newFromText( 'Lorem ipsum' );
65 $this->assertSame(
66 $loremIpsum->getArticleID(),
67 $loremIpsum->getArticleID( Title::GAID_FOR_UPDATE )
70 $categoryLoremIpsum = Title::newFromText( 'Category:Lorem ipsum' );
72 $this->assertSame(
73 $categoryLoremIpsum->getArticleID(),
74 $categoryLoremIpsum->getArticleID( Title::GAID_FOR_UPDATE )
78 private function doImport( $importStreamSource ) {
80 $importer = new WikiImporter(
81 $importStreamSource->value,
82 MediaWikiServices::getInstance()->getMainConfig()
84 $importer->setDebug( true );
86 $reporter = new ImportReporter(
87 $importer,
88 false,
89 '',
90 false
93 $reporter->setContext( new RequestContext() );
94 $reporter->open();
95 $exception = false;
97 try {
98 $importer->doImport();
99 } catch ( Exception $e ) {
100 $exception = $e;
103 $result = $reporter->close();
105 $this->assertFalse(
106 $exception
109 $this->assertTrue(
110 $result->isGood()