3use Wikimedia\TestingAccessWrapper;
15 $this->wanCache = $this->getMockBuilder(
'WANObjectCache' )
16 ->setConstructorArgs( [ [
21 ->setMethods( [
'makePurgeValue' ] )
24 $this->wanCache->expects( $this->
any() )
25 ->method(
'makePurgeValue' )
26 ->will( $this->returnCallback(
function ( $timestamp, $holdoff ) {
28 return WANObjectCache::PURGE_VAL_PREFIX . (float)$timestamp .
':0';
33 $blobStore = $this->getMockBuilder(
'MessageBlobStore' )
34 ->setConstructorArgs( [ $rl ] )
35 ->setMethods( $methods )
38 $access = TestingAccessWrapper::newFromObject( $blobStore );
39 $access->wanCache = $this->wanCache;
45 $module->setName(
'test.blobstore' );
52 $this->assertSame(
null, $blobStore->setLogger(
new Psr\Log\NullLogger() ) );
58 $blobStore = TestingAccessWrapper::newFromObject( $this->
makeBlobStore() );
59 $this->assertInstanceOf(
60 ResourceLoader::class,
61 $blobStore->getResourceLoader()
69 $rl->register( $module->getName(), $module );
72 $blob = $blobStore->getBlob( $module,
'en' );
74 $this->assertEquals(
'{"mainpage":"Main Page"}',
$blob,
'Generated blob' );
79 $module = $this->
makeModule( [
'i-dont-exist' ] );
81 $rl->register( $module->getName(), $module );
84 $blob = $blobStore->getBlob( $module,
'en' );
86 $this->assertEquals(
'{"i-dont-exist":"\u29fci-dont-exist\u29fd"}',
$blob,
'Generated blob' );
92 $rl->register( $module->getName(), $module );
95 $blobStore->expects( $this->once() )
96 ->method(
'fetchMessage' )
97 ->will( $this->returnValue(
'Example' ) );
99 $blob = $blobStore->getBlob( $module,
'en' );
101 $this->assertEquals(
'{"foo":"Example"}',
$blob,
'Generated blob' );
112 $rl->register( $module->getName(), $module );
114 $blobStore = $this->
makeBlobStore( [
'fetchMessage' ], $rl );
115 $blobStore->expects( $this->once() )
116 ->method(
'fetchMessage' )
117 ->will( $this->returnValue(
'First' ) );
120 $blob = $blobStore->getBlob( $module,
'en' );
121 $this->assertEquals(
'{"example":"First"}',
$blob,
'Generated blob' );
123 $blobStore = $this->
makeBlobStore( [
'fetchMessage' ], $rl );
124 $blobStore->expects( $this->never() )
125 ->method(
'fetchMessage' )
126 ->will( $this->returnValue(
'Second' ) );
129 $blob = $blobStore->getBlob( $module,
'en' );
130 $this->assertEquals(
'{"example":"First"}',
$blob,
'Cache hit' );
136 $rl->register( $module->getName(), $module );
137 $blobStore = $this->
makeBlobStore( [
'fetchMessage' ], $rl );
138 $blobStore->expects( $this->once() )
139 ->method(
'fetchMessage' )
140 ->will( $this->returnValue(
'First' ) );
142 $blob = $blobStore->getBlob( $module,
'en' );
143 $this->assertEquals(
'{"example":"First"}',
$blob,
'Generated blob' );
145 $blobStore->updateMessage(
'example' );
149 $rl->register( $module->getName(), $module );
150 $blobStore = $this->
makeBlobStore( [
'fetchMessage' ], $rl );
151 $blobStore->expects( $this->once() )
152 ->method(
'fetchMessage' )
153 ->will( $this->returnValue(
'Second' ) );
155 $blob = $blobStore->getBlob( $module,
'en' );
156 $this->assertEquals(
'{"example":"Second"}',
$blob,
'Updated blob' );
162 $rl->register( $module->getName(), $module );
164 $blobStore = $this->
makeBlobStore( [
'fetchMessage' ], $rl );
165 $blobStore->expects( $this->once() )
166 ->method(
'fetchMessage' )
167 ->will( $this->returnValueMap( [
168 [
'foo',
'en',
'Hello' ],
171 $blob = $blobStore->getBlob( $module,
'en' );
172 $this->assertEquals(
'{"foo":"Hello"}',
$blob,
'Generated blob' );
178 $module = $this->
makeModule( [
'foo',
'bar' ] );
180 $rl->register( $module->getName(), $module );
182 $blobStore = $this->
makeBlobStore( [
'fetchMessage' ], $rl );
183 $blobStore->expects( $this->exactly( 2 ) )
184 ->method(
'fetchMessage' )
185 ->will( $this->returnValueMap( [
186 [
'foo',
'en',
'Hello' ],
187 [
'bar',
'en',
'World' ],
190 $blob = $blobStore->getBlob( $module,
'en' );
191 $this->assertEquals(
'{"foo":"Hello","bar":"World"}',
$blob,
'Updated blob' );
197 $rl->register( $module->getName(), $module );
198 $blobStore = $this->
makeBlobStore( [
'fetchMessage' ], $rl );
199 $blobStore->expects( $this->exactly( 2 ) )
200 ->method(
'fetchMessage' )
201 ->will( $this->onConsecutiveCalls(
'First',
'Second' ) );
203 $blob = $blobStore->getBlob( $module,
'en' );
204 $this->assertEquals(
'{"example":"First"}',
$blob,
'Generated blob' );
206 $blob = $blobStore->getBlob( $module,
'en' );
207 $this->assertEquals(
'{"example":"First"}',
$blob,
'Cache-hit' );
211 $blob = $blobStore->getBlob( $module,
'en' );
212 $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.