Improve return types in class MagicWordArray
[lhc/web/wiklou.git] / tests / phpunit / includes / import / ImportLinkCacheIntegrationTest.php
1 <?php
2 use MediaWiki\MediaWikiServices;
3
4 /**
5 * Integration test that checks import success and
6 * LinkCache integration.
7 *
8 * @group large
9 * @group Database
10 * @covers ImportStreamSource
11 * @covers ImportReporter
12 *
13 * @author mwjames
14 */
15 class ImportLinkCacheIntegrationTest extends MediaWikiTestCase {
16
17 private $importStreamSource;
18
19 protected function setUp() {
20 parent::setUp();
21
22 $file = dirname( __DIR__ ) . '/../data/import/ImportLinkCacheIntegrationTest.xml';
23
24 $this->importStreamSource = ImportStreamSource::newFromFile( $file );
25
26 if ( !$this->importStreamSource->isGood() ) {
27 throw new Exception( "Import source for {$file} failed" );
28 }
29 }
30
31 public function testImportForImportSource() {
32 $this->doImport( $this->importStreamSource );
33
34 // Imported title
35 $loremIpsum = Title::newFromText( 'Lorem ipsum' );
36
37 $this->assertSame(
38 $loremIpsum->getArticleID(),
39 $loremIpsum->getArticleID( Title::GAID_FOR_UPDATE )
40 );
41
42 $categoryLoremIpsum = Title::newFromText( 'Category:Lorem ipsum' );
43
44 $this->assertSame(
45 $categoryLoremIpsum->getArticleID(),
46 $categoryLoremIpsum->getArticleID( Title::GAID_FOR_UPDATE )
47 );
48
49 $page = new WikiPage( $loremIpsum );
50 $page->doDeleteArticle( 'import test: delete page' );
51
52 $page = new WikiPage( $categoryLoremIpsum );
53 $page->doDeleteArticle( 'import test: delete page' );
54 }
55
56 /**
57 * @depends testImportForImportSource
58 */
59 public function testReImportForImportSource() {
60 $this->doImport( $this->importStreamSource );
61
62 // ReImported title
63 $loremIpsum = Title::newFromText( 'Lorem ipsum' );
64
65 $this->assertSame(
66 $loremIpsum->getArticleID(),
67 $loremIpsum->getArticleID( Title::GAID_FOR_UPDATE )
68 );
69
70 $categoryLoremIpsum = Title::newFromText( 'Category:Lorem ipsum' );
71
72 $this->assertSame(
73 $categoryLoremIpsum->getArticleID(),
74 $categoryLoremIpsum->getArticleID( Title::GAID_FOR_UPDATE )
75 );
76 }
77
78 private function doImport( $importStreamSource ) {
79 $importer = new WikiImporter(
80 $importStreamSource->value,
81 MediaWikiServices::getInstance()->getMainConfig()
82 );
83 $importer->setDebug( true );
84
85 $reporter = new ImportReporter(
86 $importer,
87 false,
88 '',
89 false
90 );
91
92 $reporter->setContext( new RequestContext() );
93 $reporter->open();
94
95 $importer->doImport();
96
97 $result = $reporter->close();
98
99 $this->assertTrue(
100 $result->isGood()
101 );
102 }
103
104 }