Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / maintenance / AddSiteTest.php
blobd45f30a992e5f38c9e41e6d513ec0009a29e065f
1 <?php
3 namespace MediaWiki\Tests\Maintenance;
5 use AddSite;
6 use MediaWiki\Site\HashSiteStore;
7 use MediaWiki\Site\MediaWikiSite;
8 use MediaWiki\Site\Site;
10 /**
11 * @covers \AddSite
12 * @author Dreamy Jazz
14 class AddSiteTest extends MaintenanceBaseTestCase {
16 protected function setUp(): void {
17 parent::setUp();
18 // Avoid needing to write to the DB for the tests.
19 $this->setService( 'SiteStore', new HashSiteStore() );
22 protected function getMaintenanceClass() {
23 return AddSite::class;
26 /** @dataProvider provideExecuteForFatalError */
27 public function testExecuteForFatalError( $globalId, $group, $expectedOutputRegex ) {
28 $this->expectCallToFatalError();
29 $this->maintenance->setArg( 'globalid', $globalId );
30 $this->maintenance->setArg( 'group', $group );
31 $this->expectOutputRegex( $expectedOutputRegex );
32 $this->maintenance->execute();
35 public static function provideExecuteForFatalError() {
36 return [
37 'Global ID is not a string' => [ null, 'test', '/Arguments globalid and group need to be strings/' ],
38 'Group is not a string' => [ 'test', null, '/Arguments globalid and group need to be strings/' ],
42 public function testExecuteWhenSiteAlreadyExists() {
43 $foo = Site::newForType( Site::TYPE_UNKNOWN );
44 $foo->setGlobalId( 'Foo' );
45 $this->getServiceContainer()->getSiteStore()->saveSite( $foo );
47 $this->testExecuteForFatalError(
48 $foo->getGlobalId(), 'wikipedia', "/Site with global id {$foo->getGlobalId()} already exists/"
52 public function testExecute() {
53 // Set up the arguments for the script and then run it.
54 $this->maintenance->setArg( 'globalid', 'enwiki' );
55 $this->maintenance->setArg( 'group', 'wikipedia' );
56 $this->maintenance->setOption( 'language', 'en' );
57 $this->maintenance->setOption( 'interwiki-id', 'en' );
58 $this->maintenance->setOption( 'navigation-id', 'en' );
59 $this->maintenance->setOption( 'pagepath', 'http://en.wikipedia.org/wiki/' );
60 $this->maintenance->setOption( 'filepath', 'http://en.wikipedia.org/w/' );
61 $this->expectOutputRegex( "/Done/" );
62 $this->maintenance->execute();
63 // Check that that the sitestore contains the expected data.
64 $actualSite = $this->getServiceContainer()->getSiteStore()->getSite( 'enwiki' );
65 $this->assertNotNull( $actualSite );
66 $this->assertSame( 'wikipedia', $actualSite->getGroup() );
67 $this->assertSame( 'en', $actualSite->getLanguageCode() );
68 $this->assertArrayEquals( [ 'en' ], $actualSite->getInterwikiIds() );
69 $this->assertArrayEquals( [ 'en' ], $actualSite->getNavigationIds() );
70 $this->assertSame( 'http://en.wikipedia.org/w/', $actualSite->getPath( MediaWikiSite::PATH_FILE ) );
71 $this->assertSame( 'http://en.wikipedia.org/wiki/', $actualSite->getPath( MediaWikiSite::PATH_PAGE ) );