File: ClearInterwikiCacheTest.php

package info (click to toggle)
mediawiki 1%3A1.43.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 417,464 kB
  • sloc: php: 1,062,949; javascript: 664,290; sql: 9,714; python: 5,458; xml: 3,489; sh: 1,131; makefile: 64
file content (54 lines) | stat: -rw-r--r-- 1,355 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php

namespace MediaWiki\Tests\Maintenance;

use ClearInterwikiCache;
use MediaWiki\Interwiki\InterwikiLookup;

/**
 * @covers \ClearInterwikiCache
 * @group Database
 * @author Dreamy Jazz
 */
class ClearInterwikiCacheTest extends MaintenanceBaseTestCase {

	protected function getMaintenanceClass() {
		return ClearInterwikiCache::class;
	}

	public function testExecute() {
		// Insert some testing interwiki table rows
		$this->getDb()->newInsertQueryBuilder()
			->insertInto( 'interwiki' )
			->rows( [
				[
					'iw_prefix' => 'en',
					'iw_url' => 'test$1',
					'iw_api' => 'testapi$1',
					'iw_wikiid' => 'enwiki',
					'iw_local' => 0,
					'iw_trans' => 0,
				],
				[
					'iw_prefix' => 'de',
					'iw_url' => 'de.test$1',
					'iw_api' => 'de.testapi$1',
					'iw_wikiid' => 'dewiki',
					'iw_local' => 0,
					'iw_trans' => 0,
				],
			] )
			->execute();
		// Mock that the InterwikiLookup::invalidateCache method is called.
		$this->setService( 'InterwikiLookup', function () {
			$mockInterwikiLookup = $this->createMock( InterwikiLookup::class );
			$mockInterwikiLookup->expects( $this->exactly( 2 ) )
				->method( 'invalidateCache' )
				->willReturnCallback( function ( $prefix ) {
					$this->assertContains( $prefix, [ 'en', 'de' ] );
				} );
			return $mockInterwikiLookup;
		} );
		$this->maintenance->execute();
	}
}