Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / maintenance / ExportSitesImportSitesLoopTest.php
blobda4a70f719dfe8f9225983bc0543a8579d9718fe
1 <?php
3 namespace MediaWiki\Tests\Maintenance;
5 use ExportSites;
6 use ImportSites;
7 use MediaWiki\Site\MediaWikiSite;
8 use MediaWiki\Site\Site;
10 /**
11 * Tests that a XML file exported by {@link ExportSites} can be imported by {@link ImportSites}.
13 * @covers \ExportSites
14 * @covers \ImportSites
15 * @group Database
16 * @author Dreamy Jazz
18 class ExportSitesImportSitesLoopTest extends MaintenanceBaseTestCase {
20 protected function getMaintenanceClass() {
21 // No-op, as the ->maintenance property is not used. We will need to extend MaintenanceBaseTestCase to hide
22 // any output from the scripts.
23 return ExportSites::class;
26 private function setUpSitesStoreForTest() {
27 // Copied, with modification, from SiteExporter::provideRoundTrip
28 $foo = Site::newForType( Site::TYPE_UNKNOWN );
29 $foo->setGlobalId( 'Foo' );
31 $dewiki = Site::newForType( Site::TYPE_MEDIAWIKI );
32 $dewiki->setGlobalId( 'dewiki' );
33 $dewiki->setGroup( 'wikipedia' );
34 $dewiki->setForward( true );
35 $dewiki->addLocalId( Site::ID_INTERWIKI, 'wikipedia' );
36 $dewiki->addLocalId( Site::ID_EQUIVALENT, 'de' );
37 $dewiki->setPath( Site::PATH_LINK, 'http://de.wikipedia.org/w/' );
38 $dewiki->setPath( MediaWikiSite::PATH_PAGE, 'http://de.wikipedia.org/wiki/' );
39 $dewiki->setSource( 'meta.wikimedia.org' );
41 $this->getServiceContainer()->getSiteStore()->saveSites( [ $foo, $dewiki ] );
42 return $this->getServiceContainer()->getSiteLookup()->getSites();
45 public function testExportAndThenImportLoop() {
46 // Test structure inspired by SiteExporterTest::testRoundTrip
47 $sitesConfigBeforeTest = $this->setUpSitesStoreForTest();
48 // Export the site config to a file using the ExportSites maintenance script
49 $xmlFilename = $this->getNewTempFile();
50 $importSites = new ExportSites();
51 $importSites->setArg( 'file', $xmlFilename );
52 $importSites->execute();
53 // Blank the site config
54 $this->getServiceContainer()->getSiteStore()->clear();
55 $this->truncateTables( [ 'sites', 'site_identifiers' ] );
56 // Check that the site config is actually empty
57 $sitesConfigHalfWayThroughTest = $this->getServiceContainer()->getSiteLookup()->getSites();
58 $this->assertSame( 0, $sitesConfigHalfWayThroughTest->count() );
59 // Import the site config from the file using the ImportSites maintenance script
60 $importSites = new ImportSites();
61 $importSites->setArg( 'file', $xmlFilename );
62 $importSites->execute();
63 // Check that the config is now the same as at the start of the test
64 $sitesConfigAfterTest = $this->getServiceContainer()->getSiteStore()->getSites();
65 $this->assertEquals( $sitesConfigBeforeTest, $sitesConfigAfterTest );