2015-11-30 23:26:45 +00:00
|
|
|
<?php
|
|
|
|
|
|
2015-12-09 18:05:59 +00:00
|
|
|
class CdnCacheUpdateTest extends MediaWikiTestCase {
|
2017-10-12 18:58:33 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers CdnCacheUpdate::merge
|
|
|
|
|
*/
|
2015-11-30 23:26:45 +00:00
|
|
|
public function testPurgeMergeWeb() {
|
|
|
|
|
$this->setMwGlobals( 'wgCommandLineMode', false );
|
|
|
|
|
|
|
|
|
|
$title = Title::newMainPage();
|
2019-03-15 00:23:26 +00:00
|
|
|
|
|
|
|
|
$urls1 = [];
|
2015-11-30 23:26:45 +00:00
|
|
|
$urls1[] = $title->getCanonicalURL( '?x=1' );
|
|
|
|
|
$urls1[] = $title->getCanonicalURL( '?x=2' );
|
|
|
|
|
$urls1[] = $title->getCanonicalURL( '?x=3' );
|
2018-10-11 22:11:50 +00:00
|
|
|
$update1 = $this->newCdnCacheUpdate( $urls1 );
|
2015-11-30 23:26:45 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$urls2 = [];
|
2015-11-30 23:26:45 +00:00
|
|
|
$urls2[] = $title->getCanonicalURL( '?x=2' );
|
|
|
|
|
$urls2[] = $title->getCanonicalURL( '?x=3' );
|
|
|
|
|
$urls2[] = $title->getCanonicalURL( '?x=4' );
|
2020-03-17 21:15:58 +00:00
|
|
|
$urls2[] = $title;
|
2018-10-11 22:11:50 +00:00
|
|
|
$update2 = $this->newCdnCacheUpdate( $urls2 );
|
2019-03-15 00:23:26 +00:00
|
|
|
|
|
|
|
|
$expected = [
|
|
|
|
|
$title->getInternalURL(),
|
|
|
|
|
$title->getInternalURL( 'action=history' ),
|
|
|
|
|
$title->getCanonicalURL( '?x=1' ),
|
|
|
|
|
$title->getCanonicalURL( '?x=2' ),
|
|
|
|
|
$title->getCanonicalURL( '?x=3' ),
|
|
|
|
|
$title->getCanonicalURL( '?x=4' ),
|
|
|
|
|
];
|
|
|
|
|
DeferredUpdates::addUpdate( $update1 );
|
2015-11-30 23:26:45 +00:00
|
|
|
DeferredUpdates::addUpdate( $update2 );
|
|
|
|
|
|
2019-03-15 00:23:26 +00:00
|
|
|
$this->assertEquals( $expected, $update1->getUrls() );
|
2018-10-11 22:11:50 +00:00
|
|
|
|
2019-03-15 00:23:26 +00:00
|
|
|
/** @var CdnCacheUpdate $update */
|
2018-10-11 22:11:50 +00:00
|
|
|
$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(
|
2019-03-15 00:23:26 +00:00
|
|
|
$this->newCdnCacheUpdate( $urls2 ),
|
|
|
|
|
DeferredUpdates::PRESEND
|
|
|
|
|
);
|
2018-10-11 22:11:50 +00:00
|
|
|
} );
|
|
|
|
|
DeferredUpdates::doUpdates();
|
|
|
|
|
|
2019-03-15 00:23:26 +00:00
|
|
|
$this->assertEquals( $expected, $update->getUrls() );
|
2018-10-11 22:11:50 +00:00
|
|
|
|
|
|
|
|
$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();
|
2015-11-30 23:26:45 +00:00
|
|
|
}
|
|
|
|
|
}
|