2015-11-30 23:26:45 +00:00
|
|
|
<?php
|
|
|
|
|
|
2023-08-01 00:57:54 +00:00
|
|
|
use MediaWiki\Cache\LinkBatchFactory;
|
2023-11-21 21:08:14 +00:00
|
|
|
use MediaWiki\Deferred\CdnCacheUpdate;
|
|
|
|
|
use MediaWiki\Deferred\DeferredUpdates;
|
2023-03-01 20:33:26 +00:00
|
|
|
use MediaWiki\Title\Title;
|
|
|
|
|
|
deferred: Widen `@covers` annotations in unit tests
Follows-up I98d2ecc987, I7555c9b6b5, I6d845bdfbb, I69b5385868, I4c7d826c7e,
I1287f3979a, which widened the `@covers` annotations of other suites:
> We lose useful coverage and spend valuable time keeping these tags
> accurate through refactors (or worse, forget to do so).
>
> I've audited each test to confirm it is a general test of the
> subject class, where adding any called methods would be an accepted
> change, thus widening it is merely a no-op that clarifies intent
> and reduces maintenance. I am not disabling the "only track coverage
> of specified subject" benefits, nor am I claiming coverage in
> in classes outside the subject under test.
>
> Tracking tiny details per-method wastes time in keeping references
> in sync during refactors, time to realize (and fix) when people
> inevitably don't keep them in sync, time lost in finding uncovered
> code to write tests for only to realize it was already covered but
> not yet claimed, etc.
Change-Id: I133c7b707aab7ceb4f2ecd3be38bd4bd1b194143
2023-08-21 23:01:58 +00:00
|
|
|
/**
|
2023-11-21 21:08:14 +00:00
|
|
|
* @covers \MediaWiki\Deferred\CdnCacheUpdate
|
deferred: Widen `@covers` annotations in unit tests
Follows-up I98d2ecc987, I7555c9b6b5, I6d845bdfbb, I69b5385868, I4c7d826c7e,
I1287f3979a, which widened the `@covers` annotations of other suites:
> We lose useful coverage and spend valuable time keeping these tags
> accurate through refactors (or worse, forget to do so).
>
> I've audited each test to confirm it is a general test of the
> subject class, where adding any called methods would be an accepted
> change, thus widening it is merely a no-op that clarifies intent
> and reduces maintenance. I am not disabling the "only track coverage
> of specified subject" benefits, nor am I claiming coverage in
> in classes outside the subject under test.
>
> Tracking tiny details per-method wastes time in keeping references
> in sync during refactors, time to realize (and fix) when people
> inevitably don't keep them in sync, time lost in finding uncovered
> code to write tests for only to realize it was already covered but
> not yet claimed, etc.
Change-Id: I133c7b707aab7ceb4f2ecd3be38bd4bd1b194143
2023-08-21 23:01:58 +00:00
|
|
|
*/
|
2020-06-30 15:09:24 +00:00
|
|
|
class CdnCacheUpdateTest extends MediaWikiIntegrationTestCase {
|
2017-10-12 18:58:33 +00:00
|
|
|
|
2015-11-30 23:26:45 +00:00
|
|
|
public function testPurgeMergeWeb() {
|
2023-12-12 13:36:06 +00:00
|
|
|
$cleanup = DeferredUpdates::preventOpportunisticUpdates();
|
2023-08-01 00:57:54 +00:00
|
|
|
$this->setService( 'LinkBatchFactory', $this->createMock( LinkBatchFactory::class ) );
|
2015-11-30 23:26:45 +00:00
|
|
|
|
|
|
|
|
$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
|
|
|
|
2023-03-11 19:04:01 +00:00
|
|
|
$this->assertSame( 0, DeferredUpdates::pendingUpdatesCount(), 'PRESEND update run' );
|
2018-10-11 22:11:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param array $urls
|
|
|
|
|
* @return CdnCacheUpdate
|
|
|
|
|
*/
|
|
|
|
|
private function newCdnCacheUpdate( array $urls ) {
|
|
|
|
|
return $this->getMockBuilder( CdnCacheUpdate::class )
|
|
|
|
|
->setConstructorArgs( [ $urls ] )
|
2021-03-20 15:18:58 +00:00
|
|
|
->onlyMethods( [ 'doUpdate' ] )
|
2018-10-11 22:11:50 +00:00
|
|
|
->getMock();
|
2015-11-30 23:26:45 +00:00
|
|
|
}
|
|
|
|
|
}
|