ImportLinkCacheIntegrationTest.php 2.3 KB

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