Merge "Align "What's this" vertically"
[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 $this->doImport( $this->importStreamSource );
31
32 // Imported title
33 $loremIpsum = Title::newFromText( 'Lorem ipsum' );
34
35 $this->assertSame(
36 $loremIpsum->getArticleID(),
37 $loremIpsum->getArticleID( Title::GAID_FOR_UPDATE )
38 );
39
40 $categoryLoremIpsum = Title::newFromText( 'Category:Lorem ipsum' );
41
42 $this->assertSame(
43 $categoryLoremIpsum->getArticleID(),
44 $categoryLoremIpsum->getArticleID( Title::GAID_FOR_UPDATE )
45 );
46
47 $page = new WikiPage( $loremIpsum );
48 $page->doDeleteArticle( 'import test: delete page' );
49
50 $page = new WikiPage( $categoryLoremIpsum );
51 $page->doDeleteArticle( 'import test: delete page' );
52 }
53
54 /**
55 * @depends testImportForImportSource
56 */
57 public function testReImportForImportSource() {
58 $this->doImport( $this->importStreamSource );
59
60 // ReImported title
61 $loremIpsum = Title::newFromText( 'Lorem ipsum' );
62
63 $this->assertSame(
64 $loremIpsum->getArticleID(),
65 $loremIpsum->getArticleID( Title::GAID_FOR_UPDATE )
66 );
67
68 $categoryLoremIpsum = Title::newFromText( 'Category:Lorem ipsum' );
69
70 $this->assertSame(
71 $categoryLoremIpsum->getArticleID(),
72 $categoryLoremIpsum->getArticleID( Title::GAID_FOR_UPDATE )
73 );
74 }
75
76 private function doImport( $importStreamSource ) {
77 $importer = new WikiImporter(
78 $importStreamSource->value,
79 MediaWikiServices::getInstance()->getMainConfig()
80 );
81 $importer->setDebug( true );
82
83 $reporter = new ImportReporter(
84 $importer,
85 false,
86 '',
87 false
88 );
89
90 $reporter->setContext( new RequestContext() );
91 $reporter->open();
92 $exception = false;
93
94 try {
95 $importer->doImport();
96 } catch ( Exception $e ) {
97 $exception = $e;
98 }
99
100 $result = $reporter->close();
101
102 $this->assertFalse(
103 $exception
104 );
105
106 $this->assertTrue(
107 $result->isGood()
108 );
109 }
110
111 }