| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Maintenance; |
| 4 |
|
| 5 |
use ClearInterwikiCache; |
| 6 |
use MediaWiki\Interwiki\InterwikiLookup; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
class ClearInterwikiCacheTest extends MaintenanceBaseTestCase { |
| 14 |
|
| 15 |
protected function getMaintenanceClass() { |
| 16 |
return ClearInterwikiCache::class; |
| 17 |
} |
| 18 |
|
| 19 |
public function testExecute() { |
| 20 |
|
| 21 |
$this->getDb()->newInsertQueryBuilder() |
| 22 |
->insertInto( 'interwiki' ) |
| 23 |
->rows( [ |
| 24 |
[ |
| 25 |
'iw_prefix' => 'en', |
| 26 |
'iw_url' => 'test$1', |
| 27 |
'iw_api' => 'testapi$1', |
| 28 |
'iw_wikiid' => 'enwiki', |
| 29 |
'iw_local' => 0, |
| 30 |
'iw_trans' => 0, |
| 31 |
], |
| 32 |
[ |
| 33 |
'iw_prefix' => 'de', |
| 34 |
'iw_url' => 'de.test$1', |
| 35 |
'iw_api' => 'de.testapi$1', |
| 36 |
'iw_wikiid' => 'dewiki', |
| 37 |
'iw_local' => 0, |
| 38 |
'iw_trans' => 0, |
| 39 |
], |
| 40 |
] ) |
| 41 |
->execute(); |
| 42 |
|
| 43 |
$this->setService( 'InterwikiLookup', function () { |
| 44 |
$mockInterwikiLookup = $this->createMock( InterwikiLookup::class ); |
| 45 |
$mockInterwikiLookup->expects( $this->exactly( 2 ) ) |
| 46 |
->method( 'invalidateCache' ) |
| 47 |
->willReturnCallback( function ( $prefix ) { |
| 48 |
$this->assertContains( $prefix, [ 'en', 'de' ] ); |
| 49 |
} ); |
| 50 |
return $mockInterwikiLookup; |
| 51 |
} ); |
| 52 |
$this->maintenance->execute(); |
| 53 |
} |
| 54 |
} |