| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Cache\LinkBatchFactory; |
| 4 |
use MediaWiki\Deferred\CdnCacheUpdate; |
| 5 |
use MediaWiki\Deferred\DeferredUpdates; |
| 6 |
use MediaWiki\Title\Title; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
class CdnCacheUpdateTest extends MediaWikiIntegrationTestCase { |
| 12 |
|
| 13 |
public function testPurgeMergeWeb() { |
| 14 |
$cleanup = DeferredUpdates::preventOpportunisticUpdates(); |
| 15 |
$this->setService( 'LinkBatchFactory', $this->createMock( LinkBatchFactory::class ) ); |
| 16 |
|
| 17 |
$title = Title::newMainPage(); |
| 18 |
|
| 19 |
$urls1 = []; |
| 20 |
$urls1[] = $title->getCanonicalURL( '?x=1' ); |
| 21 |
$urls1[] = $title->getCanonicalURL( '?x=2' ); |
| 22 |
$urls1[] = $title->getCanonicalURL( '?x=3' ); |
| 23 |
$update1 = $this->newCdnCacheUpdate( $urls1 ); |
| 24 |
|
| 25 |
$urls2 = []; |
| 26 |
$urls2[] = $title->getCanonicalURL( '?x=2' ); |
| 27 |
$urls2[] = $title->getCanonicalURL( '?x=3' ); |
| 28 |
$urls2[] = $title->getCanonicalURL( '?x=4' ); |
| 29 |
$urls2[] = $title; |
| 30 |
$update2 = $this->newCdnCacheUpdate( $urls2 ); |
| 31 |
|
| 32 |
$expected = [ |
| 33 |
$title->getInternalURL(), |
| 34 |
$title->getInternalURL( 'action=history' ), |
| 35 |
$title->getCanonicalURL( '?x=1' ), |
| 36 |
$title->getCanonicalURL( '?x=2' ), |
| 37 |
$title->getCanonicalURL( '?x=3' ), |
| 38 |
$title->getCanonicalURL( '?x=4' ), |
| 39 |
]; |
| 40 |
DeferredUpdates::addUpdate( $update1 ); |
| 41 |
DeferredUpdates::addUpdate( $update2 ); |
| 42 |
|
| 43 |
$this->assertEquals( $expected, $update1->getUrls() ); |
| 44 |
|
| 45 |
|
| 46 |
$update = null; |
| 47 |
DeferredUpdates::clearPendingUpdates(); |
| 48 |
DeferredUpdates::addCallableUpdate( function () use ( $urls1, $urls2, &$update ) { |
| 49 |
$update = $this->newCdnCacheUpdate( $urls1 ); |
| 50 |
DeferredUpdates::addUpdate( $update ); |
| 51 |
DeferredUpdates::addUpdate( $this->newCdnCacheUpdate( $urls2 ) ); |
| 52 |
DeferredUpdates::addUpdate( |
| 53 |
$this->newCdnCacheUpdate( $urls2 ), |
| 54 |
DeferredUpdates::PRESEND |
| 55 |
); |
| 56 |
} ); |
| 57 |
DeferredUpdates::doUpdates(); |
| 58 |
|
| 59 |
$this->assertEquals( $expected, $update->getUrls() ); |
| 60 |
|
| 61 |
$this->assertSame( 0, DeferredUpdates::pendingUpdatesCount(), 'PRESEND update run' ); |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
private function newCdnCacheUpdate( array $urls ) { |
| 69 |
return $this->getMockBuilder( CdnCacheUpdate::class ) |
| 70 |
->setConstructorArgs( [ $urls ] ) |
| 71 |
->onlyMethods( [ 'doUpdate' ] ) |
| 72 |
->getMock(); |
| 73 |
} |
| 74 |
} |