1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File contains Test class. |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
namespace eZ\Publish\Core\Persistence\Cache\Tests; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\API\Repository\Values\Content\Relation as APIRelation; |
12
|
|
|
use eZ\Publish\SPI\Persistence\Content\Relation as SPIRelation; |
13
|
|
|
use eZ\Publish\Core\Persistence\Cache\ContentHandler; |
14
|
|
|
use eZ\Publish\SPI\Persistence\Content; |
15
|
|
|
use eZ\Publish\SPI\Persistence\Content\Handler; |
16
|
|
|
use eZ\Publish\SPI\Persistence\Content\ContentInfo; |
17
|
|
|
use eZ\Publish\SPI\Persistence\Content\VersionInfo; |
18
|
|
|
use eZ\Publish\SPI\Persistence\Content\CreateStruct; |
19
|
|
|
use eZ\Publish\SPI\Persistence\Content\UpdateStruct; |
20
|
|
|
use eZ\Publish\SPI\Persistence\Content\MetadataUpdateStruct; |
21
|
|
|
use eZ\Publish\SPI\Persistence\Content\Relation\CreateStruct as RelationCreateStruct; |
22
|
|
|
use eZ\Publish\SPI\Persistence\Content\Handler as SPIContentHandler; |
23
|
|
|
use eZ\Publish\SPI\Persistence\Content\Location\Handler as SPILocationHandler; |
24
|
|
|
use Stash\Interfaces\ItemInterface; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Test case for Persistence\Cache\ContentHandler. |
28
|
|
|
*/ |
29
|
|
|
class ContentHandlerTest extends HandlerTest |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* @return array |
33
|
|
|
*/ |
34
|
|
|
public function providerForUnCachedMethods() |
35
|
|
|
{ |
36
|
|
|
return [ |
37
|
|
|
['create', [new CreateStruct()]], |
38
|
|
|
['createDraftFromVersion', [2, 1, 14]], |
39
|
|
|
['copy', [2, 1]], |
40
|
|
|
//array( 'load', array( 2, 1, array( 'eng-GB' ) ) ), |
41
|
|
|
//array( 'load', array( 2, 1 ) ), |
42
|
|
|
//array( 'loadContentInfo', array( 2 ) ), |
43
|
|
|
//array('loadVersionInfo', array(2, 1)), |
44
|
|
|
['loadDraftsForUser', [14]], |
45
|
|
|
//array( 'setStatus', array( 2, 0, 1 ) ), |
46
|
|
|
//array( 'updateMetadata', array( 2, new MetadataUpdateStruct ) ), |
47
|
|
|
//array( 'updateContent', array( 2, 1, new UpdateStruct ) ), |
48
|
|
|
//array( 'deleteContent', array( 2 ) ), |
49
|
|
|
//array( 'deleteVersion', array( 2, 1 ) ), |
50
|
|
|
['listVersions', [2]], |
51
|
|
|
['addRelation', [new RelationCreateStruct()]], |
52
|
|
|
['removeRelation', [66, APIRelation::COMMON]], |
53
|
|
|
['loadRelations', [2, 1, 3]], |
54
|
|
|
['loadReverseRelations', [2, 3]], |
55
|
|
|
//array( 'publish', array( 2, 3, new MetadataUpdateStruct ) ), |
56
|
|
|
]; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @dataProvider providerForUnCachedMethods |
61
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler |
62
|
|
|
*/ |
63
|
|
View Code Duplication |
public function testUnCachedMethods($method, array $arguments) |
64
|
|
|
{ |
65
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
66
|
|
|
$this->cacheMock |
67
|
|
|
->expects($this->never()) |
68
|
|
|
->method($this->anything()); |
69
|
|
|
|
70
|
|
|
$innerHandler = $this->createMock(SPIContentHandler::class); |
71
|
|
|
$this->persistenceHandlerMock |
72
|
|
|
->expects($this->once()) |
73
|
|
|
->method('contentHandler') |
74
|
|
|
->will($this->returnValue($innerHandler)); |
75
|
|
|
|
76
|
|
|
$expects = $innerHandler |
77
|
|
|
->expects($this->once()) |
78
|
|
|
->method($method); |
79
|
|
|
|
80
|
|
|
if (isset($arguments[2])) { |
81
|
|
|
$expects->with($arguments[0], $arguments[1], $arguments[2]); |
82
|
|
|
} elseif (isset($arguments[1])) { |
83
|
|
|
$expects->with($arguments[0], $arguments[1]); |
84
|
|
|
} elseif (isset($arguments[0])) { |
85
|
|
|
$expects->with($arguments[0]); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
$expects->will($this->returnValue(null)); |
89
|
|
|
|
90
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
91
|
|
|
call_user_func_array([$handler, $method], $arguments); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::load |
96
|
|
|
*/ |
97
|
|
|
public function testLoadCacheIsMiss() |
98
|
|
|
{ |
99
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
100
|
|
|
$cacheItemMock = $this->createMock(ItemInterface::class); |
101
|
|
|
$this->cacheMock |
102
|
|
|
->expects($this->once()) |
103
|
|
|
->method('getItem') |
104
|
|
|
->with('content', 2, 1, 'eng-GB|eng-US') |
105
|
|
|
->will($this->returnValue($cacheItemMock)); |
106
|
|
|
|
107
|
|
|
$cacheItemMock |
108
|
|
|
->expects($this->once()) |
109
|
|
|
->method('get') |
110
|
|
|
->will($this->returnValue(null)); |
111
|
|
|
|
112
|
|
|
$cacheItemMock |
113
|
|
|
->expects($this->once()) |
114
|
|
|
->method('isMiss') |
115
|
|
|
->will($this->returnValue(true)); |
116
|
|
|
|
117
|
|
|
$innerHandlerMock = $this->createMock(SPIContentHandler::class); |
118
|
|
|
$this->persistenceHandlerMock |
119
|
|
|
->expects($this->once()) |
120
|
|
|
->method('contentHandler') |
121
|
|
|
->will($this->returnValue($innerHandlerMock)); |
122
|
|
|
|
123
|
|
|
$innerHandlerMock |
124
|
|
|
->expects($this->once()) |
125
|
|
|
->method('load') |
126
|
|
|
->with(2, 1, ['eng-GB', 'eng-US']) |
127
|
|
|
->will( |
128
|
|
|
$this->returnValue( |
129
|
|
|
new Content( |
130
|
|
|
[ |
131
|
|
|
'fields' => [], |
132
|
|
|
'versionInfo' => new VersionInfo( |
133
|
|
|
[ |
134
|
|
|
'versionNo' => 1, |
135
|
|
|
'contentInfo' => new ContentInfo(['id' => 2]), |
136
|
|
|
] |
137
|
|
|
), |
138
|
|
|
] |
139
|
|
|
) |
140
|
|
|
) |
141
|
|
|
); |
142
|
|
|
|
143
|
|
|
$cacheItemMock |
144
|
|
|
->expects($this->once()) |
145
|
|
|
->method('set') |
146
|
|
|
->with($this->isInstanceOf(Content::class)) |
147
|
|
|
->will($this->returnValue($cacheItemMock)); |
148
|
|
|
|
149
|
|
|
$cacheItemMock |
150
|
|
|
->expects($this->once()) |
151
|
|
|
->method('save') |
152
|
|
|
->with(); |
153
|
|
|
|
154
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
155
|
|
|
$handler->load(2, 1, ['eng-GB', 'eng-US']); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::load |
160
|
|
|
*/ |
161
|
|
|
public function testLoadHasCache() |
162
|
|
|
{ |
163
|
|
|
$this->loggerMock->expects($this->never())->method($this->anything()); |
164
|
|
|
$cacheItemMock = $this->createMock(ItemInterface::class); |
165
|
|
|
$this->cacheMock |
166
|
|
|
->expects($this->once()) |
167
|
|
|
->method('getItem') |
168
|
|
|
->with('content', 2, 1, ContentHandler::ALL_TRANSLATIONS_KEY) |
169
|
|
|
->will($this->returnValue($cacheItemMock)); |
170
|
|
|
|
171
|
|
|
$cacheItemMock |
172
|
|
|
->expects($this->once()) |
173
|
|
|
->method('isMiss') |
174
|
|
|
->will($this->returnValue(false)); |
175
|
|
|
|
176
|
|
|
$this->persistenceHandlerMock |
177
|
|
|
->expects($this->never()) |
178
|
|
|
->method('contentHandler'); |
179
|
|
|
|
180
|
|
|
$cacheItemMock |
181
|
|
|
->expects($this->once()) |
182
|
|
|
->method('get') |
183
|
|
|
->will( |
184
|
|
|
$this->returnValue( |
185
|
|
|
new Content( |
186
|
|
|
[ |
187
|
|
|
'fields' => [], |
188
|
|
|
'versionInfo' => new VersionInfo( |
189
|
|
|
[ |
190
|
|
|
'versionNo' => 1, |
191
|
|
|
'contentInfo' => new ContentInfo(['id' => 2]), |
192
|
|
|
] |
193
|
|
|
), |
194
|
|
|
] |
195
|
|
|
) |
196
|
|
|
) |
197
|
|
|
); |
198
|
|
|
|
199
|
|
|
$cacheItemMock |
200
|
|
|
->expects($this->never()) |
201
|
|
|
->method('set'); |
202
|
|
|
|
203
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
204
|
|
|
$handler->load(2, 1); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::loadContentInfo |
209
|
|
|
*/ |
210
|
|
|
public function testLoadContentInfoCacheIsMiss() |
211
|
|
|
{ |
212
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
213
|
|
|
$cacheItemMock = $this->createMock(ItemInterface::class); |
214
|
|
|
$this->cacheMock |
215
|
|
|
->expects($this->once()) |
216
|
|
|
->method('getItem') |
217
|
|
|
->with('content', 'info', 2) |
218
|
|
|
->will($this->returnValue($cacheItemMock)); |
219
|
|
|
|
220
|
|
|
$cacheItemMock |
221
|
|
|
->expects($this->once()) |
222
|
|
|
->method('get') |
223
|
|
|
->will($this->returnValue(null)); |
224
|
|
|
|
225
|
|
|
$cacheItemMock |
226
|
|
|
->expects($this->once()) |
227
|
|
|
->method('isMiss') |
228
|
|
|
->will($this->returnValue(true)); |
229
|
|
|
|
230
|
|
|
$innerHandlerMock = $this->createMock(SPIContentHandler::class); |
231
|
|
|
$this->persistenceHandlerMock |
232
|
|
|
->expects($this->once()) |
233
|
|
|
->method('contentHandler') |
234
|
|
|
->will($this->returnValue($innerHandlerMock)); |
235
|
|
|
|
236
|
|
|
$innerHandlerMock |
237
|
|
|
->expects($this->once()) |
238
|
|
|
->method('loadContentInfo') |
239
|
|
|
->with(2) |
240
|
|
|
->will( |
241
|
|
|
$this->returnValue( |
242
|
|
|
new ContentInfo(['id' => 2]) |
243
|
|
|
) |
244
|
|
|
); |
245
|
|
|
|
246
|
|
|
$cacheItemMock |
247
|
|
|
->expects($this->once()) |
248
|
|
|
->method('set') |
249
|
|
|
->with($this->isInstanceOf(ContentInfo::class)) |
250
|
|
|
->will($this->returnValue($cacheItemMock)); |
251
|
|
|
|
252
|
|
|
$cacheItemMock |
253
|
|
|
->expects($this->once()) |
254
|
|
|
->method('save') |
255
|
|
|
->with(); |
256
|
|
|
|
257
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
258
|
|
|
$handler->loadContentInfo(2, 1); |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::loadContentInfo |
263
|
|
|
*/ |
264
|
|
|
public function testLoadContentInfoHasCache() |
265
|
|
|
{ |
266
|
|
|
$this->loggerMock->expects($this->never())->method($this->anything()); |
267
|
|
|
$cacheItemMock = $this->createMock(ItemInterface::class); |
268
|
|
|
$this->cacheMock |
269
|
|
|
->expects($this->once()) |
270
|
|
|
->method('getItem') |
271
|
|
|
->with('content', 'info', 2) |
272
|
|
|
->will($this->returnValue($cacheItemMock)); |
273
|
|
|
|
274
|
|
|
$cacheItemMock |
275
|
|
|
->expects($this->once()) |
276
|
|
|
->method('isMiss') |
277
|
|
|
->will($this->returnValue(false)); |
278
|
|
|
|
279
|
|
|
$this->persistenceHandlerMock |
280
|
|
|
->expects($this->never()) |
281
|
|
|
->method('contentHandler'); |
282
|
|
|
|
283
|
|
|
$cacheItemMock |
284
|
|
|
->expects($this->once()) |
285
|
|
|
->method('get') |
286
|
|
|
->will( |
287
|
|
|
$this->returnValue( |
288
|
|
|
new ContentInfo(['id' => 2]) |
289
|
|
|
) |
290
|
|
|
); |
291
|
|
|
|
292
|
|
|
$cacheItemMock |
293
|
|
|
->expects($this->never()) |
294
|
|
|
->method('set'); |
295
|
|
|
|
296
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
297
|
|
|
$handler->loadContentInfo(2); |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
/** |
301
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::loadVersionInfo |
302
|
|
|
*/ |
303
|
|
|
public function testLoadVersionInfoCacheIsMiss() |
304
|
|
|
{ |
305
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
306
|
|
|
$cacheItemMock = $this->createMock(ItemInterface::class); |
307
|
|
|
$this->cacheMock |
308
|
|
|
->expects($this->once()) |
309
|
|
|
->method('getItem') |
310
|
|
|
->with('content', 'info', 2, 'versioninfo', 1) |
311
|
|
|
->will($this->returnValue($cacheItemMock)); |
312
|
|
|
|
313
|
|
|
$cacheItemMock |
314
|
|
|
->expects($this->once()) |
315
|
|
|
->method('get') |
316
|
|
|
->will($this->returnValue(null)); |
317
|
|
|
|
318
|
|
|
$cacheItemMock |
319
|
|
|
->expects($this->once()) |
320
|
|
|
->method('isMiss') |
321
|
|
|
->will($this->returnValue(true)); |
322
|
|
|
|
323
|
|
|
$innerHandlerMock = $this->createMock(Handler::class); |
324
|
|
|
$this->persistenceHandlerMock |
325
|
|
|
->expects($this->once()) |
326
|
|
|
->method('contentHandler') |
327
|
|
|
->will($this->returnValue($innerHandlerMock)); |
328
|
|
|
|
329
|
|
|
$innerHandlerMock |
330
|
|
|
->expects($this->once()) |
331
|
|
|
->method('loadVersionInfo') |
332
|
|
|
->with(2, 1) |
333
|
|
|
->will( |
334
|
|
|
$this->returnValue( |
335
|
|
|
new VersionInfo(['contentInfo' => new ContentInfo(['id' => 2]), 'versionNo' => 1]) |
336
|
|
|
) |
337
|
|
|
); |
338
|
|
|
|
339
|
|
|
$cacheItemMock |
340
|
|
|
->expects($this->once()) |
341
|
|
|
->method('set') |
342
|
|
|
->with($this->isInstanceOf(VersionInfo::class)) |
343
|
|
|
->will($this->returnValue($cacheItemMock)); |
344
|
|
|
|
345
|
|
|
$cacheItemMock |
346
|
|
|
->expects($this->once()) |
347
|
|
|
->method('save') |
348
|
|
|
->with(); |
349
|
|
|
|
350
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
351
|
|
|
$handler->loadVersionInfo(2, 1); |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::loadVersionInfo |
356
|
|
|
*/ |
357
|
|
|
public function testLoadVersionInfoWithoutVersionNumberCacheIsMiss() |
358
|
|
|
{ |
359
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
360
|
|
|
$cacheItemMock = $this->getMock(ItemInterface::class); |
|
|
|
|
361
|
|
|
$this->cacheMock |
362
|
|
|
->expects($this->once()) |
363
|
|
|
->method('getItem') |
364
|
|
|
->with('content', 'info', 2, 'versioninfo', ContentHandler::PUBLISHED_VERSION) |
365
|
|
|
->willReturn($cacheItemMock); |
366
|
|
|
|
367
|
|
|
$cacheItemMock |
368
|
|
|
->expects($this->once()) |
369
|
|
|
->method('get') |
370
|
|
|
->willReturn(null); |
371
|
|
|
|
372
|
|
|
$cacheItemMock |
373
|
|
|
->expects($this->once()) |
374
|
|
|
->method('isMiss') |
375
|
|
|
->willReturn(true); |
376
|
|
|
|
377
|
|
|
$innerHandlerMock = $this->getMock(Handler::class); |
|
|
|
|
378
|
|
|
$this->persistenceHandlerMock |
379
|
|
|
->expects($this->once()) |
380
|
|
|
->method('contentHandler') |
381
|
|
|
->willReturn($innerHandlerMock); |
382
|
|
|
|
383
|
|
|
$innerHandlerMock |
384
|
|
|
->expects($this->once()) |
385
|
|
|
->method('loadVersionInfo') |
386
|
|
|
->with(2, 0) |
387
|
|
|
->willReturn(new VersionInfo(['contentInfo' => new ContentInfo(['id' => 2]), 'versionNo' => 1])); |
388
|
|
|
|
389
|
|
|
$cacheItemMock |
390
|
|
|
->expects($this->once()) |
391
|
|
|
->method('set') |
392
|
|
|
->with($this->isInstanceOf(VersionInfo::class)) |
393
|
|
|
->willReturn($cacheItemMock); |
394
|
|
|
|
395
|
|
|
$cacheItemMock |
396
|
|
|
->expects($this->once()) |
397
|
|
|
->method('save') |
398
|
|
|
->with(); |
399
|
|
|
|
400
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
401
|
|
|
$handler->loadVersionInfo(2, null); |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
/** |
405
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::loadVersionInfo |
406
|
|
|
*/ |
407
|
|
|
public function testLoadVersionInfoHasCache() |
408
|
|
|
{ |
409
|
|
|
$this->loggerMock->expects($this->never())->method($this->anything()); |
410
|
|
|
$cacheItemMock = $this->createMock(ItemInterface::class); |
411
|
|
|
$this->cacheMock |
412
|
|
|
->expects($this->once()) |
413
|
|
|
->method('getItem') |
414
|
|
|
->with('content', 'info', 2, 'versioninfo', 1) |
415
|
|
|
->will($this->returnValue($cacheItemMock)); |
416
|
|
|
|
417
|
|
|
$cacheItemMock |
418
|
|
|
->expects($this->once()) |
419
|
|
|
->method('isMiss') |
420
|
|
|
->will($this->returnValue(false)); |
421
|
|
|
|
422
|
|
|
$this->persistenceHandlerMock |
423
|
|
|
->expects($this->never()) |
424
|
|
|
->method('contentHandler'); |
425
|
|
|
|
426
|
|
|
$cacheItemMock |
427
|
|
|
->expects($this->once()) |
428
|
|
|
->method('get') |
429
|
|
|
->will( |
430
|
|
|
$this->returnValue( |
431
|
|
|
new VersionInfo(['contentInfo' => new ContentInfo(['id' => 2]), 'versionNo' => 1]) |
432
|
|
|
) |
433
|
|
|
); |
434
|
|
|
|
435
|
|
|
$cacheItemMock |
436
|
|
|
->expects($this->never()) |
437
|
|
|
->method('set'); |
438
|
|
|
|
439
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
440
|
|
|
$handler->loadVersionInfo(2, 1); |
441
|
|
|
} |
442
|
|
|
|
443
|
|
|
/** |
444
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::setStatus |
445
|
|
|
*/ |
446
|
|
View Code Duplication |
public function testSetStatus() |
447
|
|
|
{ |
448
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
449
|
|
|
|
450
|
|
|
$innerHandlerMock = $this->createMock(SPIContentHandler::class); |
451
|
|
|
$this->persistenceHandlerMock |
452
|
|
|
->expects($this->once()) |
453
|
|
|
->method('contentHandler') |
454
|
|
|
->will($this->returnValue($innerHandlerMock)); |
455
|
|
|
|
456
|
|
|
$innerHandlerMock |
457
|
|
|
->expects($this->once()) |
458
|
|
|
->method('setStatus') |
459
|
|
|
->with(2, VersionInfo::STATUS_ARCHIVED, 1) |
460
|
|
|
->will($this->returnValue(true)); |
461
|
|
|
|
462
|
|
|
$this->cacheMock |
463
|
|
|
->expects($this->at(0)) |
464
|
|
|
->method('clear') |
465
|
|
|
->with('content', 2, 1) |
466
|
|
|
->will($this->returnValue(null)); |
467
|
|
|
|
468
|
|
|
$this->cacheMock |
469
|
|
|
->expects($this->at(1)) |
470
|
|
|
->method('clear') |
471
|
|
|
->with('content', 2, ContentHandler::PUBLISHED_VERSION) |
472
|
|
|
->will($this->returnValue(null)); |
473
|
|
|
|
474
|
|
|
$this->cacheMock |
475
|
|
|
->expects($this->at(2)) |
476
|
|
|
->method('clear') |
477
|
|
|
->with('content', 'info', 2, 'versioninfo', 1) |
478
|
|
|
->will($this->returnValue(null)); |
479
|
|
|
|
480
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
481
|
|
|
$handler->setStatus(2, VersionInfo::STATUS_ARCHIVED, 1); |
482
|
|
|
} |
483
|
|
|
|
484
|
|
|
/** |
485
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::setStatus |
486
|
|
|
*/ |
487
|
|
View Code Duplication |
public function testSetStatusPublished() |
488
|
|
|
{ |
489
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
490
|
|
|
|
491
|
|
|
$innerHandlerMock = $this->createMock(SPIContentHandler::class); |
492
|
|
|
$this->persistenceHandlerMock |
493
|
|
|
->expects($this->once()) |
494
|
|
|
->method('contentHandler') |
495
|
|
|
->will($this->returnValue($innerHandlerMock)); |
496
|
|
|
|
497
|
|
|
$innerHandlerMock |
498
|
|
|
->expects($this->once()) |
499
|
|
|
->method('setStatus') |
500
|
|
|
->with(2, VersionInfo::STATUS_PUBLISHED, 1) |
501
|
|
|
->will($this->returnValue(true)); |
502
|
|
|
|
503
|
|
|
$this->cacheMock |
504
|
|
|
->expects($this->at(0)) |
505
|
|
|
->method('clear') |
506
|
|
|
->with('content', 2, 1) |
507
|
|
|
->will($this->returnValue(null)); |
508
|
|
|
|
509
|
|
|
$this->cacheMock |
510
|
|
|
->expects($this->at(1)) |
511
|
|
|
->method('clear') |
512
|
|
|
->with('content', 2, ContentHandler::PUBLISHED_VERSION) |
513
|
|
|
->will($this->returnValue(null)); |
514
|
|
|
|
515
|
|
|
$this->cacheMock |
516
|
|
|
->expects($this->at(2)) |
517
|
|
|
->method('clear') |
518
|
|
|
->with('content', 'info', 2) |
519
|
|
|
->will($this->returnValue(null)); |
520
|
|
|
|
521
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
522
|
|
|
$handler->setStatus(2, VersionInfo::STATUS_PUBLISHED, 1); |
523
|
|
|
} |
524
|
|
|
|
525
|
|
|
/** |
526
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::updateMetadata |
527
|
|
|
*/ |
528
|
|
|
public function testUpdateMetadata() |
529
|
|
|
{ |
530
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
531
|
|
|
|
532
|
|
|
$innerHandlerMock = $this->createMock(SPIContentHandler::class); |
533
|
|
|
$this->persistenceHandlerMock |
534
|
|
|
->expects($this->once()) |
535
|
|
|
->method('contentHandler') |
536
|
|
|
->will($this->returnValue($innerHandlerMock)); |
537
|
|
|
|
538
|
|
|
$innerHandlerMock |
539
|
|
|
->expects($this->once()) |
540
|
|
|
->method('updateMetadata') |
541
|
|
|
->with(2, $this->isInstanceOf(MetadataUpdateStruct::class)) |
542
|
|
|
->willReturn(new ContentInfo(['id' => 2, 'currentVersionNo' => 3, 'remoteId' => 'o34'])); |
543
|
|
|
|
544
|
|
|
$this->cacheMock |
545
|
|
|
->expects($this->at(0)) |
546
|
|
|
->method('clear') |
547
|
|
|
->with('content', 2, 3) |
548
|
|
|
->willReturn(null); |
549
|
|
|
|
550
|
|
|
$this->cacheMock |
551
|
|
|
->expects($this->at(1)) |
552
|
|
|
->method('clear') |
553
|
|
|
->with('content', 2, ContentHandler::PUBLISHED_VERSION) |
554
|
|
|
->will($this->returnValue(null)); |
555
|
|
|
|
556
|
|
|
$this->cacheMock |
557
|
|
|
->expects($this->at(2)) |
558
|
|
|
->method('clear') |
559
|
|
|
->with('content', 'info', 2) |
560
|
|
|
->willReturn(null); |
561
|
|
|
|
562
|
|
|
$this->cacheMock |
563
|
|
|
->expects($this->at(3)) |
564
|
|
|
->method('clear') |
565
|
|
|
->with('content', 'info', 'remoteId', 'o34') |
566
|
|
|
->willReturn(null); |
567
|
|
|
|
568
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
569
|
|
|
$handler->updateMetadata(2, new MetadataUpdateStruct()); |
570
|
|
|
} |
571
|
|
|
|
572
|
|
|
/** |
573
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::updateContent |
574
|
|
|
*/ |
575
|
|
|
public function testUpdateContent() |
576
|
|
|
{ |
577
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
578
|
|
|
|
579
|
|
|
$innerHandlerMock = $this->createMock(SPIContentHandler::class); |
580
|
|
|
$this->persistenceHandlerMock |
581
|
|
|
->expects($this->once()) |
582
|
|
|
->method('contentHandler') |
583
|
|
|
->will($this->returnValue($innerHandlerMock)); |
584
|
|
|
|
585
|
|
|
$innerHandlerMock |
586
|
|
|
->expects($this->once()) |
587
|
|
|
->method('updateContent') |
588
|
|
|
->with(2, 1, $this->isInstanceOf(UpdateStruct::class)) |
589
|
|
|
->will( |
590
|
|
|
$this->returnValue( |
591
|
|
|
new Content( |
592
|
|
|
[ |
593
|
|
|
'fields' => [], |
594
|
|
|
'versionInfo' => new VersionInfo( |
595
|
|
|
[ |
596
|
|
|
'versionNo' => 1, |
597
|
|
|
'contentInfo' => new ContentInfo(['id' => 2]), |
598
|
|
|
] |
599
|
|
|
), |
600
|
|
|
] |
601
|
|
|
) |
602
|
|
|
) |
603
|
|
|
); |
604
|
|
|
|
605
|
|
|
$this->cacheMock |
606
|
|
|
->expects($this->at(0)) |
607
|
|
|
->method('clear') |
608
|
|
|
->with('content', 2, 1) |
609
|
|
|
->will($this->returnValue(null)); |
610
|
|
|
|
611
|
|
|
$this->cacheMock |
612
|
|
|
->expects($this->at(1)) |
613
|
|
|
->method('clear') |
614
|
|
|
->with('content', 2, ContentHandler::PUBLISHED_VERSION) |
615
|
|
|
->will($this->returnValue(null)); |
616
|
|
|
|
617
|
|
|
$this->cacheMock |
618
|
|
|
->expects($this->at(2)) |
619
|
|
|
->method('clear') |
620
|
|
|
->with('content', 'info', 2, 'versioninfo', 1) |
621
|
|
|
->will($this->returnValue(null)); |
622
|
|
|
|
623
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
624
|
|
|
$handler->updateContent(2, 1, new UpdateStruct()); |
625
|
|
|
} |
626
|
|
|
|
627
|
|
|
/** |
628
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::deleteContent |
629
|
|
|
*/ |
630
|
|
|
public function testDeleteContent() |
631
|
|
|
{ |
632
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
633
|
|
|
|
634
|
|
|
$innerLocationHandlerMock = $this->createMock(SPILocationHandler::class); |
635
|
|
|
$this->persistenceHandlerMock |
636
|
|
|
->expects($this->exactly(1)) |
637
|
|
|
->method('locationHandler') |
638
|
|
|
->will($this->returnValue($innerLocationHandlerMock)); |
639
|
|
|
|
640
|
|
|
$innerLocationHandlerMock |
641
|
|
|
->expects($this->once()) |
642
|
|
|
->method('loadLocationsByContent') |
643
|
|
|
->with(2) |
644
|
|
|
->willReturn([new Content\Location(['id' => 58])]); |
645
|
|
|
|
646
|
|
|
$innerHandlerMock = $this->createMock(SPIContentHandler::class); |
647
|
|
|
$this->persistenceHandlerMock |
648
|
|
|
->expects($this->exactly(2)) |
649
|
|
|
->method('contentHandler') |
650
|
|
|
->will($this->returnValue($innerHandlerMock)); |
651
|
|
|
|
652
|
|
|
$innerHandlerMock |
653
|
|
|
->expects($this->once()) |
654
|
|
|
->method('loadReverseRelations') |
655
|
|
|
->with(2, APIRelation::FIELD) |
656
|
|
|
->will( |
657
|
|
|
$this->returnValue( |
658
|
|
|
[ |
659
|
|
|
new SPIRelation(['sourceContentId' => 42]), |
660
|
|
|
] |
661
|
|
|
) |
662
|
|
|
); |
663
|
|
|
|
664
|
|
|
$innerHandlerMock |
665
|
|
|
->expects($this->once()) |
666
|
|
|
->method('deleteContent') |
667
|
|
|
->with(2) |
668
|
|
|
->will($this->returnValue(true)); |
669
|
|
|
|
670
|
|
|
$this->cacheMock |
671
|
|
|
->expects($this->at(0)) |
672
|
|
|
->method('clear') |
673
|
|
|
->with('content', 42) |
674
|
|
|
->will($this->returnValue(null)); |
675
|
|
|
|
676
|
|
|
$this->cacheMock |
677
|
|
|
->expects($this->at(1)) |
678
|
|
|
->method('clear') |
679
|
|
|
->with('content', 2) |
680
|
|
|
->will($this->returnValue(null)); |
681
|
|
|
|
682
|
|
|
$this->cacheMock |
683
|
|
|
->expects($this->at(2)) |
684
|
|
|
->method('clear') |
685
|
|
|
->with('content', 'info', 2) |
686
|
|
|
->will($this->returnValue(null)); |
687
|
|
|
|
688
|
|
|
$this->cacheMock |
689
|
|
|
->expects($this->at(3)) |
690
|
|
|
->method('clear') |
691
|
|
|
->with('content', 'info', 'remoteId') |
692
|
|
|
->will($this->returnValue(null)); |
693
|
|
|
|
694
|
|
|
$this->cacheMock |
695
|
|
|
->expects($this->at(4)) |
696
|
|
|
->method('clear') |
697
|
|
|
->with('location', 'subtree') |
698
|
|
|
->will($this->returnValue(null)); |
699
|
|
|
|
700
|
|
|
$this->cacheMock |
701
|
|
|
->expects($this->at(5)) |
702
|
|
|
->method('clear') |
703
|
|
|
->with('location', 58) |
704
|
|
|
->will($this->returnValue(null)); |
705
|
|
|
|
706
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
707
|
|
|
$handler->deleteContent(2); |
708
|
|
|
} |
709
|
|
|
|
710
|
|
|
/** |
711
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::deleteVersion |
712
|
|
|
*/ |
713
|
|
|
public function testDeleteVersion() |
714
|
|
|
{ |
715
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
716
|
|
|
|
717
|
|
|
$innerHandlerMock = $this->createMock(SPIContentHandler::class); |
718
|
|
|
$this->persistenceHandlerMock |
719
|
|
|
->expects($this->once()) |
720
|
|
|
->method('contentHandler') |
721
|
|
|
->will($this->returnValue($innerHandlerMock)); |
722
|
|
|
|
723
|
|
|
$innerHandlerMock |
724
|
|
|
->expects($this->once()) |
725
|
|
|
->method('deleteVersion') |
726
|
|
|
->with(2, 1) |
727
|
|
|
->will($this->returnValue(true)); |
728
|
|
|
|
729
|
|
|
$this->cacheMock |
730
|
|
|
->expects($this->at(0)) |
731
|
|
|
->method('clear') |
732
|
|
|
->with('content', 2, 1) |
733
|
|
|
->will($this->returnValue(null)); |
734
|
|
|
|
735
|
|
|
$this->cacheMock |
736
|
|
|
->expects($this->at(1)) |
737
|
|
|
->method('clear') |
738
|
|
|
->with('content', 2, ContentHandler::PUBLISHED_VERSION) |
739
|
|
|
->will($this->returnValue(null)); |
740
|
|
|
|
741
|
|
|
$this->cacheMock |
742
|
|
|
->expects($this->at(2)) |
743
|
|
|
->method('clear') |
744
|
|
|
->with('content', 'info', 2) |
745
|
|
|
->will($this->returnValue(null)); |
746
|
|
|
|
747
|
|
|
$this->cacheMock |
748
|
|
|
->expects($this->at(3)) |
749
|
|
|
->method('clear') |
750
|
|
|
->with('content', 'info', 'remoteId') |
751
|
|
|
->will($this->returnValue(null)); |
752
|
|
|
|
753
|
|
|
$this->cacheMock |
754
|
|
|
->expects($this->at(4)) |
755
|
|
|
->method('clear') |
756
|
|
|
->with('location', 'subtree') |
757
|
|
|
->will($this->returnValue(null)); |
758
|
|
|
|
759
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
760
|
|
|
$handler->deleteVersion(2, 1); |
761
|
|
|
} |
762
|
|
|
|
763
|
|
|
/** |
764
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::publish |
765
|
|
|
*/ |
766
|
|
|
public function testPublish() |
767
|
|
|
{ |
768
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
769
|
|
|
|
770
|
|
|
$innerHandlerMock = $this->createMock(SPIContentHandler::class); |
771
|
|
|
$this->persistenceHandlerMock |
772
|
|
|
->expects($this->once()) |
773
|
|
|
->method('contentHandler') |
774
|
|
|
->will($this->returnValue($innerHandlerMock)); |
775
|
|
|
|
776
|
|
|
$innerHandlerMock |
777
|
|
|
->expects($this->once()) |
778
|
|
|
->method('publish') |
779
|
|
|
->with(2, 1, $this->isInstanceOf(MetadataUpdateStruct::class)) |
780
|
|
|
->will( |
781
|
|
|
$this->returnValue( |
782
|
|
|
new Content( |
783
|
|
|
[ |
784
|
|
|
'fields' => [], |
785
|
|
|
'versionInfo' => new VersionInfo( |
786
|
|
|
[ |
787
|
|
|
'versionNo' => 1, |
788
|
|
|
'contentInfo' => new ContentInfo(['id' => 2]), |
789
|
|
|
] |
790
|
|
|
), |
791
|
|
|
] |
792
|
|
|
) |
793
|
|
|
) |
794
|
|
|
); |
795
|
|
|
|
796
|
|
|
$this->cacheMock |
797
|
|
|
->expects($this->at(0)) |
798
|
|
|
->method('clear') |
799
|
|
|
->with('content', 2) |
800
|
|
|
->will($this->returnValue(true)); |
801
|
|
|
|
802
|
|
|
$this->cacheMock |
803
|
|
|
->expects($this->at(1)) |
804
|
|
|
->method('clear') |
805
|
|
|
->with('content', 'info', 2) |
806
|
|
|
->will($this->returnValue(true)); |
807
|
|
|
|
808
|
|
|
$this->cacheMock |
809
|
|
|
->expects($this->at(2)) |
810
|
|
|
->method('clear') |
811
|
|
|
->with('content', 'info', 'remoteId') |
812
|
|
|
->will($this->returnValue(true)); |
813
|
|
|
|
814
|
|
|
$this->cacheMock |
815
|
|
|
->expects($this->at(3)) |
816
|
|
|
->method('clear') |
817
|
|
|
->with('location', 'subtree') |
818
|
|
|
->will($this->returnValue(true)); |
819
|
|
|
|
820
|
|
|
$cacheItemMock = $this->createMock(ItemInterface::class); |
821
|
|
|
$this->cacheMock |
822
|
|
|
->expects($this->at(4)) |
823
|
|
|
->method('getItem') |
824
|
|
|
->with('content', 2, 1, ContentHandler::ALL_TRANSLATIONS_KEY) |
825
|
|
|
->will($this->returnValue($cacheItemMock)); |
826
|
|
|
|
827
|
|
|
$cacheItemMock |
828
|
|
|
->expects($this->once()) |
829
|
|
|
->method('set') |
830
|
|
|
->with($this->isInstanceOf(Content::class)) |
831
|
|
|
->will($this->returnValue($cacheItemMock)); |
832
|
|
|
|
833
|
|
|
$cacheItemMock |
834
|
|
|
->expects($this->once()) |
835
|
|
|
->method('save') |
836
|
|
|
->with(); |
837
|
|
|
|
838
|
|
|
$cacheItemMock |
839
|
|
|
->expects($this->never()) |
840
|
|
|
->method('get'); |
841
|
|
|
|
842
|
|
|
$cacheItemMock2 = $this->createMock(ItemInterface::class); |
843
|
|
|
$this->cacheMock |
844
|
|
|
->expects($this->at(5)) |
845
|
|
|
->method('getItem') |
846
|
|
|
->with('content', 'info', 2) |
847
|
|
|
->will($this->returnValue($cacheItemMock2)); |
848
|
|
|
|
849
|
|
|
$cacheItemMock2 |
850
|
|
|
->expects($this->once()) |
851
|
|
|
->method('set') |
852
|
|
|
->with($this->isInstanceOf(ContentInfo::class)) |
853
|
|
|
->will($this->returnValue($cacheItemMock2)); |
854
|
|
|
|
855
|
|
|
$cacheItemMock2 |
856
|
|
|
->expects($this->once()) |
857
|
|
|
->method('save') |
858
|
|
|
->with(); |
859
|
|
|
|
860
|
|
|
$cacheItemMock2 |
861
|
|
|
->expects($this->never()) |
862
|
|
|
->method('get'); |
863
|
|
|
|
864
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
865
|
|
|
$handler->publish(2, 1, new MetadataUpdateStruct()); |
866
|
|
|
} |
867
|
|
|
} |
868
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.