MediaWiki REL1_32
CdnCacheUpdateTest.php
Go to the documentation of this file.
1<?php
2
3use Wikimedia\TestingAccessWrapper;
4
6
10 public function testPurgeMergeWeb() {
11 $this->setMwGlobals( 'wgCommandLineMode', false );
12
13 $urls1 = [];
14 $title = Title::newMainPage();
15 $urls1[] = $title->getCanonicalURL( '?x=1' );
16 $urls1[] = $title->getCanonicalURL( '?x=2' );
17 $urls1[] = $title->getCanonicalURL( '?x=3' );
18 $update1 = $this->newCdnCacheUpdate( $urls1 );
19 DeferredUpdates::addUpdate( $update1 );
20
21 $urls2 = [];
22 $urls2[] = $title->getCanonicalURL( '?x=2' );
23 $urls2[] = $title->getCanonicalURL( '?x=3' );
24 $urls2[] = $title->getCanonicalURL( '?x=4' );
25 $update2 = $this->newCdnCacheUpdate( $urls2 );
26 DeferredUpdates::addUpdate( $update2 );
27
28 $wrapper = TestingAccessWrapper::newFromObject( $update1 );
29 $this->assertEquals( array_merge( $urls1, $urls2 ), $wrapper->urls );
30
31 $update = null;
32 DeferredUpdates::clearPendingUpdates();
33 DeferredUpdates::addCallableUpdate( function () use ( $urls1, $urls2, &$update ) {
34 $update = $this->newCdnCacheUpdate( $urls1 );
35 DeferredUpdates::addUpdate( $update );
36 DeferredUpdates::addUpdate( $this->newCdnCacheUpdate( $urls2 ) );
37 DeferredUpdates::addUpdate(
38 $this->newCdnCacheUpdate( $urls2 ), DeferredUpdates::PRESEND );
39 } );
40 DeferredUpdates::doUpdates();
41
42 $wrapper = TestingAccessWrapper::newFromObject( $update );
43 $this->assertEquals( array_merge( $urls1, $urls2 ), $wrapper->urls );
44
45 $this->assertEquals( DeferredUpdates::pendingUpdatesCount(), 0, 'PRESEND update run' );
46 }
47
52 private function newCdnCacheUpdate( array $urls ) {
53 return $this->getMockBuilder( CdnCacheUpdate::class )
54 ->setConstructorArgs( [ $urls ] )
55 ->setMethods( [ 'doUpdate' ] )
56 ->getMock();
57 }
58}
testPurgeMergeWeb()
CdnCacheUpdate::merge.
newCdnCacheUpdate(array $urls)
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))