Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / maintenance / DeleteSelfExternalsTest.php
blobb41313069472214f0a8ff498ff696d2f71213784
1 <?php
3 namespace MediaWiki\Tests\Maintenance;
5 use DeleteSelfExternals;
6 use MediaWiki\MainConfigNames;
8 /**
9 * @covers \DeleteSelfExternals
10 * @group Database
11 * @author Dreamy Jazz
13 class DeleteSelfExternalsTest extends MaintenanceBaseTestCase {
15 protected function getMaintenanceClass() {
16 return DeleteSelfExternals::class;
19 public function testExecuteForInvalidServerConfig() {
20 $this->overrideConfigValue( MainConfigNames::Server, '::::::' );
21 $this->expectOutputRegex( '/Could not parse \$wgServer/' );
22 $this->expectCallToFatalError();
23 $this->maintenance->execute();
26 /** @dataProvider provideExecute */
27 public function testExecute( $serverConfigValue, $expectedRowsAfterExecution ) {
28 // Create some self-externals (by linking https://en.wikipedia.org and later setting that as our
29 // server URL), as well as some external links which should be unmodified by the maintenance script.
30 $firstTestPage = $this->getExistingTestPage( 'TestPage1' );
31 $secondTestPage = $this->getExistingTestPage( 'TestPage2' );
32 $thirdTestPage = $this->getExistingTestPage( 'TestPage3' );
33 $this->editPage( $firstTestPage, '[https://en.wikipedia.org link 1] [https://de.wikipedia.org link 2]' );
34 $this->editPage( $secondTestPage, '[http://en.wikipedia.org link 4]' );
35 $this->editPage( $thirdTestPage, '[//en.wikipedia.org:345 link 5]' );
36 // Verify that the externallinks table is set up correctly for the test
37 $actualRowsBeforeExecution = $this->newSelectQueryBuilder()
38 ->select( 'el_to_domain_index' )
39 ->from( 'externallinks' )
40 ->fetchFieldValues();
41 $this->assertArrayEquals(
43 'https://org.wikipedia.de.', 'http://org.wikipedia.en.', 'https://org.wikipedia.en.',
44 'https://org.wikipedia.en.:345',
46 $actualRowsBeforeExecution
48 // Set wgServer to be en.wikipedia.org
49 $this->overrideConfigValue( MainConfigNames::Server, $serverConfigValue );
50 // Run the maintenance script
51 $this->maintenance->execute();
52 // Verify that the DB is as expected
53 $actualRowsAfterExecution = $this->newSelectQueryBuilder()
54 ->select( 'el_to_domain_index' )
55 ->from( 'externallinks' )
56 ->fetchFieldValues();
57 $this->assertArrayEquals( $expectedRowsAfterExecution, $actualRowsAfterExecution );
58 $expectedRowsDeleted = count( $actualRowsBeforeExecution ) - count( $actualRowsAfterExecution );
59 $this->expectOutputString(
60 "Deleting self externals from $serverConfigValue\n" .
61 "Deleting self-externals with el_id 0 to 1000\n" .
62 "Deleting self-externals with el_id 1000 to 2000\n" .
63 "done; deleted $expectedRowsDeleted rows\n"
67 public static function provideExecute() {
68 return [
69 'wgServer specifies scheme' => [
70 'https://en.wikipedia.org', [ 'https://org.wikipedia.de.', 'http://org.wikipedia.en.' ],
72 'wgServer does not specify scheme' => [ '//en.wikipedia.org', [ 'https://org.wikipedia.de.' ] ],
73 'wgServer includes port' => [
74 '//en.wikipedia.org:345',
75 [ 'https://org.wikipedia.de.', 'http://org.wikipedia.en.', 'https://org.wikipedia.en.' ],