3use Wikimedia\TestingAccessWrapper;
11 use MediaWikiCoversValidator;
17 $this->wanCache = $this->getMockBuilder( WANObjectCache::class )
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;
34 return WANObjectCache::PURGE_VAL_PREFIX . $ts .
':0';
39 $blobStore = $this->getMockBuilder( MessageBlobStore::class )
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(
66 ResourceLoader::class,
67 $blobStore->getResourceLoader()
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' ] );
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' );
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' );
118 $rl->register( $module->getName(), $module );
120 $blobStore = $this->
makeBlobStore( [
'fetchMessage' ], $rl );
121 $blobStore->expects( $this->once() )
122 ->method(
'fetchMessage' )
123 ->will( $this->returnValue(
'First' ) );
126 $blob = $blobStore->getBlob( $module,
'en' );
127 $this->assertEquals(
'{"example":"First"}',
$blob,
'Generated blob' );
129 $blobStore = $this->
makeBlobStore( [
'fetchMessage' ], $rl );
130 $blobStore->expects( $this->never() )
131 ->method(
'fetchMessage' )
132 ->will( $this->returnValue(
'Second' ) );
135 $blob = $blobStore->getBlob( $module,
'en' );
136 $this->assertEquals(
'{"example":"First"}',
$blob,
'Cache hit' );
142 $rl->register( $module->getName(), $module );
143 $blobStore = $this->
makeBlobStore( [
'fetchMessage' ], $rl );
144 $blobStore->expects( $this->once() )
145 ->method(
'fetchMessage' )
146 ->will( $this->returnValue(
'First' ) );
148 $blob = $blobStore->getBlob( $module,
'en' );
149 $this->assertEquals(
'{"example":"First"}',
$blob,
'Generated blob' );
151 $blobStore->updateMessage(
'example' );
155 $rl->register( $module->getName(), $module );
156 $blobStore = $this->
makeBlobStore( [
'fetchMessage' ], $rl );
157 $blobStore->expects( $this->once() )
158 ->method(
'fetchMessage' )
159 ->will( $this->returnValue(
'Second' ) );
161 $blob = $blobStore->getBlob( $module,
'en' );
162 $this->assertEquals(
'{"example":"Second"}',
$blob,
'Updated blob' );
168 $rl->register( $module->getName(), $module );
170 $blobStore = $this->
makeBlobStore( [
'fetchMessage' ], $rl );
171 $blobStore->expects( $this->once() )
172 ->method(
'fetchMessage' )
173 ->will( $this->returnValueMap( [
174 [
'foo',
'en',
'Hello' ],
177 $blob = $blobStore->getBlob( $module,
'en' );
178 $this->assertEquals(
'{"foo":"Hello"}',
$blob,
'Generated blob' );
184 $module = $this->
makeModule( [
'foo',
'bar' ] );
186 $rl->register( $module->getName(), $module );
188 $blobStore = $this->
makeBlobStore( [
'fetchMessage' ], $rl );
189 $blobStore->expects( $this->exactly( 2 ) )
190 ->method(
'fetchMessage' )
191 ->will( $this->returnValueMap( [
192 [
'foo',
'en',
'Hello' ],
193 [
'bar',
'en',
'World' ],
196 $blob = $blobStore->getBlob( $module,
'en' );
197 $this->assertEquals(
'{"foo":"Hello","bar":"World"}',
$blob,
'Updated blob' );
203 $rl->register( $module->getName(), $module );
204 $blobStore = $this->
makeBlobStore( [
'fetchMessage' ], $rl );
205 $blobStore->expects( $this->exactly( 2 ) )
206 ->method(
'fetchMessage' )
207 ->will( $this->onConsecutiveCalls(
'First',
'Second' ) );
209 $now = microtime(
true );
210 $this->wanCache->setMockTime( $now );
212 $blob = $blobStore->getBlob( $module,
'en' );
213 $this->assertEquals(
'{"example":"First"}',
$blob,
'Generated blob' );
215 $blob = $blobStore->getBlob( $module,
'en' );
216 $this->assertEquals(
'{"example":"First"}',
$blob,
'Cache-hit' );
221 $blob = $blobStore->getBlob( $module,
'en' );
222 $this->assertEquals(
'{"example":"Second"}',
$blob,
'Updated blob' );
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
No-op class for publishing messages into a PubSub system.
Simple store for keeping values in an associative array for the current process.
testGetBlobCached()
Seems to fail sometimes (T176097).
testSetLogger()
MessageBlobStore::setLogger.
makeModule(array $messages)
testFetchMessageFail()
MessageBlobStore::fetchMessage.
makeBlobStore( $methods=null, $rl=null)
testGetResourceLoader()
MessageBlobStore::getResourceLoader.
testFetchMessage()
MessageBlobStore::fetchMessage.
Dynamic JavaScript and CSS resource loading system.