3 use Wikimedia\TestingAccessWrapper;
11 use MediaWikiCoversValidator;
18 ->setConstructorArgs( [ [
23 ->setMethods( [
'makePurgeValue' ] )
26 $this->wanCache->expects( $this->
any() )
27 ->method(
'makePurgeValue' )
28 ->will( $this->returnCallback(
function ( $timestamp, $holdoff ) {
32 $ts = (float)$timestamp - 0.0001;
40 ->setConstructorArgs( [ $rl ] )
41 ->setMethods( $methods )
44 $access = TestingAccessWrapper::newFromObject( $blobStore );
45 $access->wanCache = $this->wanCache;
51 $module->setName(
'test.blobstore' );
58 $this->assertSame(
null, $blobStore->setLogger(
new Psr\Log\NullLogger() ) );
64 $blobStore = TestingAccessWrapper::newFromObject( $this->
makeBlobStore() );
65 $this->assertInstanceOf(
67 $blobStore->getResourceLoader()
74 $rl =
new ResourceLoader();
75 $rl->register( $module->getName(), $module );
78 $blob = $blobStore->getBlob( $module,
'en' );
80 $this->assertEquals(
'{"mainpage":"Main Page"}',
$blob,
'Generated blob' );
85 $module = $this->
makeModule( [
'i-dont-exist' ] );
86 $rl =
new ResourceLoader();
87 $rl->register( $module->getName(), $module );
90 $blob = $blobStore->getBlob( $module,
'en' );
92 $this->assertEquals(
'{"i-dont-exist":"\u29fci-dont-exist\u29fd"}',
$blob,
'Generated blob' );
97 $rl =
new ResourceLoader();
98 $rl->register( $module->getName(), $module );
100 $blobStore = $this->
makeBlobStore( [
'fetchMessage' ], $rl );
101 $blobStore->expects( $this->once() )
102 ->method(
'fetchMessage' )
103 ->will( $this->returnValue(
'Example' ) );
105 $blob = $blobStore->getBlob( $module,
'en' );
107 $this->assertEquals(
'{"foo":"Example"}',
$blob,
'Generated blob' );
112 $rl =
new ResourceLoader();
113 $rl->register( $module->getName(), $module );
115 $blobStore = $this->
makeBlobStore( [
'fetchMessage' ], $rl );
116 $blobStore->expects( $this->once() )
117 ->method(
'fetchMessage' )
118 ->will( $this->returnValue(
'First' ) );
121 $blob = $blobStore->getBlob( $module,
'en' );
122 $this->assertEquals(
'{"example":"First"}',
$blob,
'Generated blob' );
124 $blobStore = $this->
makeBlobStore( [
'fetchMessage' ], $rl );
125 $blobStore->expects( $this->never() )
126 ->method(
'fetchMessage' )
127 ->will( $this->returnValue(
'Second' ) );
130 $blob = $blobStore->getBlob( $module,
'en' );
131 $this->assertEquals(
'{"example":"First"}',
$blob,
'Cache hit' );
136 $rl =
new ResourceLoader();
137 $rl->register( $module->getName(), $module );
138 $blobStore = $this->
makeBlobStore( [
'fetchMessage' ], $rl );
139 $blobStore->expects( $this->once() )
140 ->method(
'fetchMessage' )
141 ->will( $this->returnValue(
'First' ) );
143 $blob = $blobStore->getBlob( $module,
'en' );
144 $this->assertEquals(
'{"example":"First"}',
$blob,
'Generated blob' );
146 $blobStore->updateMessage(
'example' );
149 $rl =
new ResourceLoader();
150 $rl->register( $module->getName(), $module );
151 $blobStore = $this->
makeBlobStore( [
'fetchMessage' ], $rl );
152 $blobStore->expects( $this->once() )
153 ->method(
'fetchMessage' )
154 ->will( $this->returnValue(
'Second' ) );
156 $blob = $blobStore->getBlob( $module,
'en' );
157 $this->assertEquals(
'{"example":"Second"}',
$blob,
'Updated blob' );
162 $rl =
new ResourceLoader();
163 $rl->register( $module->getName(), $module );
165 $blobStore = $this->
makeBlobStore( [
'fetchMessage' ], $rl );
166 $blobStore->expects( $this->once() )
167 ->method(
'fetchMessage' )
168 ->will( $this->returnValueMap( [
169 [
'foo',
'en',
'Hello' ],
172 $blob = $blobStore->getBlob( $module,
'en' );
173 $this->assertEquals(
'{"foo":"Hello"}',
$blob,
'Generated blob' );
179 $module = $this->
makeModule( [
'foo',
'bar' ] );
180 $rl =
new ResourceLoader();
181 $rl->register( $module->getName(), $module );
183 $blobStore = $this->
makeBlobStore( [
'fetchMessage' ], $rl );
184 $blobStore->expects( $this->exactly( 2 ) )
185 ->method(
'fetchMessage' )
186 ->will( $this->returnValueMap( [
187 [
'foo',
'en',
'Hello' ],
188 [
'bar',
'en',
'World' ],
191 $blob = $blobStore->getBlob( $module,
'en' );
192 $this->assertEquals(
'{"foo":"Hello","bar":"World"}',
$blob,
'Updated blob' );
197 $rl =
new ResourceLoader();
198 $rl->register( $module->getName(), $module );
199 $blobStore = $this->
makeBlobStore( [
'fetchMessage' ], $rl );
200 $blobStore->expects( $this->exactly( 2 ) )
201 ->method(
'fetchMessage' )
202 ->will( $this->onConsecutiveCalls(
'First',
'Second' ) );
204 $now = microtime(
true );
205 $this->wanCache->setMockTime( $now );
207 $blob = $blobStore->getBlob( $module,
'en' );
208 $this->assertEquals(
'{"example":"First"}',
$blob,
'Generated blob' );
210 $blob = $blobStore->getBlob( $module,
'en' );
211 $this->assertEquals(
'{"example":"First"}',
$blob,
'Cache-hit' );
216 $blob = $blobStore->getBlob( $module,
'en' );
217 $this->assertEquals(
'{"example":"Second"}',
$blob,
'Updated blob' );