This is moderately messy. Process was principally: * xargs rg --files-with-matches '^use Title;' | grep 'php$' | \ xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1' * rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \ xargs rg --files-with-matches 'Title\b' | \ xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1' * composer fix Then manual fix-ups for a few files that don't have any use statements. Bug: T166010 Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
70 lines
2 KiB
PHP
70 lines
2 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Title\Title;
|
|
|
|
class CdnCacheUpdateTest extends MediaWikiIntegrationTestCase {
|
|
|
|
/**
|
|
* @covers CdnCacheUpdate::merge
|
|
*/
|
|
public function testPurgeMergeWeb() {
|
|
$this->setMwGlobals( 'wgCommandLineMode', false );
|
|
|
|
$title = Title::newMainPage();
|
|
|
|
$urls1 = [];
|
|
$urls1[] = $title->getCanonicalURL( '?x=1' );
|
|
$urls1[] = $title->getCanonicalURL( '?x=2' );
|
|
$urls1[] = $title->getCanonicalURL( '?x=3' );
|
|
$update1 = $this->newCdnCacheUpdate( $urls1 );
|
|
|
|
$urls2 = [];
|
|
$urls2[] = $title->getCanonicalURL( '?x=2' );
|
|
$urls2[] = $title->getCanonicalURL( '?x=3' );
|
|
$urls2[] = $title->getCanonicalURL( '?x=4' );
|
|
$urls2[] = $title;
|
|
$update2 = $this->newCdnCacheUpdate( $urls2 );
|
|
|
|
$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 );
|
|
DeferredUpdates::addUpdate( $update2 );
|
|
|
|
$this->assertEquals( $expected, $update1->getUrls() );
|
|
|
|
/** @var CdnCacheUpdate $update */
|
|
$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();
|
|
|
|
$this->assertEquals( $expected, $update->getUrls() );
|
|
|
|
$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 ] )
|
|
->onlyMethods( [ 'doUpdate' ] )
|
|
->getMock();
|
|
}
|
|
}
|