Merge "Rewrite logstash key conflict warning from I6677dbf6"
[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 medium
9 * @group Database
10 *
11 * @author mwjames
12 */
13 class ImportLinkCacheIntegrationTest extends MediaWikiTestCase {
14
15 private $importStreamSource;
16
17 protected function setUp() {
18 parent::setUp();
19
20 $file = dirname( __DIR__ ) . '/../data/import/ImportLinkCacheIntegrationTest.xml';
21
22 $this->importStreamSource = ImportStreamSource::newFromFile( $file );
23
24 if ( !$this->importStreamSource->isGood() ) {
25 throw new Exception( "Import source for {$file} failed" );
26 }
27 }
28
29 public function testImportForImportSource() {
30
31 $this->doImport( $this->importStreamSource );
32
33 // Imported title
34 $loremIpsum = Title::newFromText( 'Lorem ipsum' );
35
36 $this->assertSame(
37 $loremIpsum->getArticleID(),
38 $loremIpsum->getArticleID( Title::GAID_FOR_UPDATE )
39 );
40
41 $categoryLoremIpsum = Title::newFromText( 'Category:Lorem ipsum' );
42
43 $this->assertSame(
44 $categoryLoremIpsum->getArticleID(),
45 $categoryLoremIpsum->getArticleID( Title::GAID_FOR_UPDATE )
46 );
47
48 $page = new WikiPage( $loremIpsum );
49 $page->doDeleteArticle( 'import test: delete page' );
50
51 $page = new WikiPage( $categoryLoremIpsum );
52 $page->doDeleteArticle( 'import test: delete page' );
53 }
54
55 /**
56 * @depends testImportForImportSource
57 */
58 public function testReImportForImportSource() {
59
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
80 $importer = new WikiImporter(
81 $importStreamSource->value,
82 MediaWikiServices::getInstance()->getMainConfig()
83 );
84 $importer->setDebug( true );
85
86 $reporter = new ImportReporter(
87 $importer,
88 false,
89 '',
90 false
91 );
92
93 $reporter->setContext( new RequestContext() );
94 $reporter->open();
95 $exception = false;
96
97 try {
98 $importer->doImport();
99 } catch ( Exception $e ) {
100 $exception = $e;
101 }
102
103 $result = $reporter->close();
104
105 $this->assertFalse(
106 $exception
107 );
108
109 $this->assertTrue(
110 $result->isGood()
111 );
112 }
113
114 }