Import: Handle uploads with sha1 starting with 0 properly
[mediawiki.git] / tests / phpunit / includes / ImportLinkCacheIntegrationTest.php
blob1433b898d097bb62c2e2bc56ef019aec4cd0174b
1 <?php
2 /**
3 * Integration test that checks import success and
4 * LinkCache integration.
6 * @group medium
7 * @group Database
9 * @author mwjames
11 class ImportLinkCacheIntegrationTest extends MediaWikiTestCase {
13 private $importStreamSource;
15 protected function setUp() {
16 parent::setUp();
18 $file = dirname( __DIR__ ) . '/data/import/ImportLinkCacheIntegrationTest.xml';
20 $this->importStreamSource = ImportStreamSource::newFromFile( $file );
22 if ( !$this->importStreamSource->isGood() ) {
23 throw new Exception( "Import source for {$file} failed" );
27 public function testImportForImportSource() {
29 $this->doImport( $this->importStreamSource );
31 // Imported title
32 $loremIpsum = Title::newFromText( 'Lorem ipsum' );
34 $this->assertSame(
35 $loremIpsum->getArticleID(),
36 $loremIpsum->getArticleID( Title::GAID_FOR_UPDATE )
39 $categoryLoremIpsum = Title::newFromText( 'Category:Lorem ipsum' );
41 $this->assertSame(
42 $categoryLoremIpsum->getArticleID(),
43 $categoryLoremIpsum->getArticleID( Title::GAID_FOR_UPDATE )
46 $page = new WikiPage( $loremIpsum );
47 $page->doDeleteArticle( 'import test: delete page' );
49 $page = new WikiPage( $categoryLoremIpsum );
50 $page->doDeleteArticle( 'import test: delete page' );
53 /**
54 * @depends testImportForImportSource
56 public function testReImportForImportSource() {
58 $this->doImport( $this->importStreamSource );
60 // ReImported title
61 $loremIpsum = Title::newFromText( 'Lorem ipsum' );
63 $this->assertSame(
64 $loremIpsum->getArticleID(),
65 $loremIpsum->getArticleID( Title::GAID_FOR_UPDATE )
68 $categoryLoremIpsum = Title::newFromText( 'Category:Lorem ipsum' );
70 $this->assertSame(
71 $categoryLoremIpsum->getArticleID(),
72 $categoryLoremIpsum->getArticleID( Title::GAID_FOR_UPDATE )
76 private function doImport( $importStreamSource ) {
78 $importer = new WikiImporter(
79 $importStreamSource->value,
80 ConfigFactory::getDefaultInstance()->makeConfig( 'main' )
82 $importer->setDebug( true );
84 $reporter = new ImportReporter(
85 $importer,
86 false,
87 '',
88 false
91 $reporter->setContext( new RequestContext() );
92 $reporter->open();
93 $exception = false;
95 try {
96 $importer->doImport();
97 } catch ( Exception $e ) {
98 $exception = $e;
101 $result = $reporter->close();
103 $this->assertFalse(
104 $exception
107 $this->assertTrue(
108 $result->isGood()