The class was already documented as "given a list of URLs or Title instances", this makes that work. Title objects will have ->getCdnUrls() called when the update is resolved, which avoids problems like those encountered in T240083 where that was being called too early. Bug: T240083 Change-Id: I30b29a7359a8f393fb19ffc199211a421d3ea4d9
59 lines
1.8 KiB
PHP
59 lines
1.8 KiB
PHP
<?php
|
|
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
class CdnCacheUpdateTest extends MediaWikiTestCase {
|
|
|
|
/**
|
|
* @covers CdnCacheUpdate::merge
|
|
*/
|
|
public function testPurgeMergeWeb() {
|
|
$this->setMwGlobals( 'wgCommandLineMode', false );
|
|
|
|
$urls1 = [];
|
|
$title = Title::newMainPage();
|
|
$urls1[] = $title->getCanonicalURL( '?x=1' );
|
|
$urls1[] = $title->getCanonicalURL( '?x=2' );
|
|
$urls1[] = $title->getCanonicalURL( '?x=3' );
|
|
$update1 = $this->newCdnCacheUpdate( $urls1 );
|
|
DeferredUpdates::addUpdate( $update1 );
|
|
|
|
$urls2 = [];
|
|
$urls2[] = $title->getCanonicalURL( '?x=2' );
|
|
$urls2[] = $title->getCanonicalURL( '?x=3' );
|
|
$urls2[] = $title->getCanonicalURL( '?x=4' );
|
|
$urls2[] = $title;
|
|
$update2 = $this->newCdnCacheUpdate( $urls2 );
|
|
DeferredUpdates::addUpdate( $update2 );
|
|
|
|
$wrapper = TestingAccessWrapper::newFromObject( $update1 );
|
|
$this->assertEquals( array_merge( $urls1, $urls2 ), $wrapper->urls );
|
|
|
|
$update = null;
|
|
DeferredUpdates::clearPendingUpdates();
|
|
DeferredUpdates::addCallableUpdate( function () use ( $urls1, $urls2, &$update ) {
|
|
$update = $this->newCdnCacheUpdate( $urls1 );
|
|
DeferredUpdates::addUpdate( $update );
|
|
DeferredUpdates::addUpdate( $this->newCdnCacheUpdate( $urls2 ) );
|
|
DeferredUpdates::addUpdate(
|
|
$this->newCdnCacheUpdate( $urls2 ), DeferredUpdates::PRESEND );
|
|
} );
|
|
DeferredUpdates::doUpdates();
|
|
|
|
$wrapper = TestingAccessWrapper::newFromObject( $update );
|
|
$this->assertEquals( array_merge( $urls1, $urls2 ), $wrapper->urls );
|
|
|
|
$this->assertEquals( DeferredUpdates::pendingUpdatesCount(), 0, 'PRESEND update run' );
|
|
}
|
|
|
|
/**
|
|
* @param array $urls
|
|
* @return CdnCacheUpdate
|
|
*/
|
|
private function newCdnCacheUpdate( array $urls ) {
|
|
return $this->getMockBuilder( CdnCacheUpdate::class )
|
|
->setConstructorArgs( [ $urls ] )
|
|
->setMethods( [ 'doUpdate' ] )
|
|
->getMock();
|
|
}
|
|
}
|