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