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 array( |
35
|
|
|
array('create', array(new CreateStruct())), |
36
|
|
|
array('createDraftFromVersion', array(2, 1, 14)), |
37
|
|
|
array('copy', array(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
|
|
|
array('loadDraftsForUser', array(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
|
|
|
array('listVersions', array(2)), |
49
|
|
|
array('addRelation', array(new RelationCreateStruct())), |
50
|
|
|
array('removeRelation', array(66, APIRelation::COMMON)), |
51
|
|
|
array('loadRelations', array(2, 1, 3)), |
52
|
|
|
array('loadReverseRelations', array(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(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, array('eng-GB', 'eng-US')) |
125
|
|
|
->will( |
126
|
|
|
$this->returnValue( |
127
|
|
|
new Content( |
128
|
|
|
array( |
129
|
|
|
'fields' => array(), |
130
|
|
|
'versionInfo' => new VersionInfo( |
131
|
|
|
array( |
132
|
|
|
'versionNo' => 1, |
133
|
|
|
'contentInfo' => new ContentInfo(array('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, array('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
|
|
|
array( |
185
|
|
|
'fields' => array(), |
186
|
|
|
'versionInfo' => new VersionInfo( |
187
|
|
|
array( |
188
|
|
|
'versionNo' => 1, |
189
|
|
|
'contentInfo' => new ContentInfo(array('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(array('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(array('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 testLoadVersionInfoHasCache() |
356
|
|
|
{ |
357
|
|
|
$this->loggerMock->expects($this->never())->method($this->anything()); |
358
|
|
|
$cacheItemMock = $this->getMock(ItemInterface::class); |
359
|
|
|
$this->cacheMock |
360
|
|
|
->expects($this->once()) |
361
|
|
|
->method('getItem') |
362
|
|
|
->with('content', 'info', 2, 'versioninfo', 1) |
363
|
|
|
->will($this->returnValue($cacheItemMock)); |
364
|
|
|
|
365
|
|
|
$cacheItemMock |
366
|
|
|
->expects($this->once()) |
367
|
|
|
->method('isMiss') |
368
|
|
|
->will($this->returnValue(false)); |
369
|
|
|
|
370
|
|
|
$this->persistenceHandlerMock |
371
|
|
|
->expects($this->never()) |
372
|
|
|
->method('contentHandler'); |
373
|
|
|
|
374
|
|
|
$cacheItemMock |
375
|
|
|
->expects($this->once()) |
376
|
|
|
->method('get') |
377
|
|
|
->will( |
378
|
|
|
$this->returnValue( |
379
|
|
|
new VersionInfo(['contentInfo' => new ContentInfo(['id' => 2]), 'versionNo' => 1]) |
380
|
|
|
) |
381
|
|
|
); |
382
|
|
|
|
383
|
|
|
$cacheItemMock |
384
|
|
|
->expects($this->never()) |
385
|
|
|
->method('set'); |
386
|
|
|
|
387
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
388
|
|
|
$handler->loadVersionInfo(2, 1); |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
/** |
392
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::setStatus |
393
|
|
|
*/ |
394
|
|
View Code Duplication |
public function testSetStatus() |
395
|
|
|
{ |
396
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
397
|
|
|
|
398
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Handler'); |
399
|
|
|
$this->persistenceHandlerMock |
400
|
|
|
->expects($this->once()) |
401
|
|
|
->method('contentHandler') |
402
|
|
|
->will($this->returnValue($innerHandlerMock)); |
403
|
|
|
|
404
|
|
|
$innerHandlerMock |
405
|
|
|
->expects($this->once()) |
406
|
|
|
->method('setStatus') |
407
|
|
|
->with(2, VersionInfo::STATUS_ARCHIVED, 1) |
408
|
|
|
->will($this->returnValue(true)); |
409
|
|
|
|
410
|
|
|
$this->cacheMock |
411
|
|
|
->expects($this->at(0)) |
412
|
|
|
->method('clear') |
413
|
|
|
->with('content', 2, 1) |
414
|
|
|
->will($this->returnValue(null)); |
415
|
|
|
|
416
|
|
|
$this->cacheMock |
417
|
|
|
->expects($this->at(1)) |
418
|
|
|
->method('clear') |
419
|
|
|
->with('content', 2, ContentHandler::PUBLISHED_VERSION) |
420
|
|
|
->will($this->returnValue(null)); |
421
|
|
|
|
422
|
|
|
$this->cacheMock |
423
|
|
|
->expects($this->at(2)) |
424
|
|
|
->method('clear') |
425
|
|
|
->with('content', 'info', 2, 'versioninfo', 1) |
426
|
|
|
->will($this->returnValue(null)); |
427
|
|
|
|
428
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
429
|
|
|
$handler->setStatus(2, VersionInfo::STATUS_ARCHIVED, 1); |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
/** |
433
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::setStatus |
434
|
|
|
*/ |
435
|
|
View Code Duplication |
public function testSetStatusPublished() |
436
|
|
|
{ |
437
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
438
|
|
|
|
439
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Handler'); |
440
|
|
|
$this->persistenceHandlerMock |
441
|
|
|
->expects($this->once()) |
442
|
|
|
->method('contentHandler') |
443
|
|
|
->will($this->returnValue($innerHandlerMock)); |
444
|
|
|
|
445
|
|
|
$innerHandlerMock |
446
|
|
|
->expects($this->once()) |
447
|
|
|
->method('setStatus') |
448
|
|
|
->with(2, VersionInfo::STATUS_PUBLISHED, 1) |
449
|
|
|
->will($this->returnValue(true)); |
450
|
|
|
|
451
|
|
|
$this->cacheMock |
452
|
|
|
->expects($this->at(0)) |
453
|
|
|
->method('clear') |
454
|
|
|
->with('content', 2, 1) |
455
|
|
|
->will($this->returnValue(null)); |
456
|
|
|
|
457
|
|
|
$this->cacheMock |
458
|
|
|
->expects($this->at(1)) |
459
|
|
|
->method('clear') |
460
|
|
|
->with('content', 2, ContentHandler::PUBLISHED_VERSION) |
461
|
|
|
->will($this->returnValue(null)); |
462
|
|
|
|
463
|
|
|
$this->cacheMock |
464
|
|
|
->expects($this->at(2)) |
465
|
|
|
->method('clear') |
466
|
|
|
->with('content', 'info', 2) |
467
|
|
|
->will($this->returnValue(null)); |
468
|
|
|
|
469
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
470
|
|
|
$handler->setStatus(2, VersionInfo::STATUS_PUBLISHED, 1); |
471
|
|
|
} |
472
|
|
|
|
473
|
|
|
/** |
474
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::updateMetadata |
475
|
|
|
*/ |
476
|
|
|
public function testUpdateMetadata() |
477
|
|
|
{ |
478
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
479
|
|
|
|
480
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Handler'); |
481
|
|
|
$this->persistenceHandlerMock |
482
|
|
|
->expects($this->once()) |
483
|
|
|
->method('contentHandler') |
484
|
|
|
->will($this->returnValue($innerHandlerMock)); |
485
|
|
|
|
486
|
|
|
$innerHandlerMock |
487
|
|
|
->expects($this->once()) |
488
|
|
|
->method('updateMetadata') |
489
|
|
|
->with(2, $this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\MetadataUpdateStruct')) |
490
|
|
|
->willReturn(new ContentInfo(array('id' => 2, 'currentVersionNo' => 3, 'remoteId' => 'o34'))); |
491
|
|
|
|
492
|
|
|
$this->cacheMock |
493
|
|
|
->expects($this->at(0)) |
494
|
|
|
->method('clear') |
495
|
|
|
->with('content', 2, 3) |
496
|
|
|
->willReturn(null); |
497
|
|
|
|
498
|
|
|
$this->cacheMock |
499
|
|
|
->expects($this->at(1)) |
500
|
|
|
->method('clear') |
501
|
|
|
->with('content', 2, ContentHandler::PUBLISHED_VERSION) |
502
|
|
|
->will($this->returnValue(null)); |
503
|
|
|
|
504
|
|
|
$this->cacheMock |
505
|
|
|
->expects($this->at(2)) |
506
|
|
|
->method('clear') |
507
|
|
|
->with('content', 'info', 2) |
508
|
|
|
->willReturn(null); |
509
|
|
|
|
510
|
|
|
$this->cacheMock |
511
|
|
|
->expects($this->at(3)) |
512
|
|
|
->method('clear') |
513
|
|
|
->with('content', 'info', 'remoteId', 'o34') |
514
|
|
|
->willReturn(null); |
515
|
|
|
|
516
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
517
|
|
|
$handler->updateMetadata(2, new MetadataUpdateStruct()); |
518
|
|
|
} |
519
|
|
|
|
520
|
|
|
/** |
521
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::updateContent |
522
|
|
|
*/ |
523
|
|
|
public function testUpdateContent() |
524
|
|
|
{ |
525
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
526
|
|
|
|
527
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Handler'); |
528
|
|
|
$this->persistenceHandlerMock |
529
|
|
|
->expects($this->once()) |
530
|
|
|
->method('contentHandler') |
531
|
|
|
->will($this->returnValue($innerHandlerMock)); |
532
|
|
|
|
533
|
|
|
$innerHandlerMock |
534
|
|
|
->expects($this->once()) |
535
|
|
|
->method('updateContent') |
536
|
|
|
->with(2, 1, $this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\UpdateStruct')) |
537
|
|
|
->will( |
538
|
|
|
$this->returnValue( |
539
|
|
|
new Content( |
540
|
|
|
array( |
541
|
|
|
'fields' => array(), |
542
|
|
|
'versionInfo' => new VersionInfo( |
543
|
|
|
array( |
544
|
|
|
'versionNo' => 1, |
545
|
|
|
'contentInfo' => new ContentInfo(array('id' => 2)), |
546
|
|
|
) |
547
|
|
|
), |
548
|
|
|
) |
549
|
|
|
) |
550
|
|
|
) |
551
|
|
|
); |
552
|
|
|
|
553
|
|
|
$this->cacheMock |
554
|
|
|
->expects($this->at(0)) |
555
|
|
|
->method('clear') |
556
|
|
|
->with('content', 2, 1) |
557
|
|
|
->will($this->returnValue(null)); |
558
|
|
|
|
559
|
|
|
$this->cacheMock |
560
|
|
|
->expects($this->at(1)) |
561
|
|
|
->method('clear') |
562
|
|
|
->with('content', 2, ContentHandler::PUBLISHED_VERSION) |
563
|
|
|
->will($this->returnValue(null)); |
564
|
|
|
|
565
|
|
|
$this->cacheMock |
566
|
|
|
->expects($this->at(2)) |
567
|
|
|
->method('clear') |
568
|
|
|
->with('content', 'info', 2, 'versioninfo', 1) |
569
|
|
|
->will($this->returnValue(null)); |
570
|
|
|
|
571
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
572
|
|
|
$handler->updateContent(2, 1, new UpdateStruct()); |
573
|
|
|
} |
574
|
|
|
|
575
|
|
|
/** |
576
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::deleteContent |
577
|
|
|
*/ |
578
|
|
|
public function testDeleteContent() |
579
|
|
|
{ |
580
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
581
|
|
|
|
582
|
|
|
$innerLocationHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Location\\Handler'); |
583
|
|
|
$this->persistenceHandlerMock |
584
|
|
|
->expects($this->exactly(1)) |
585
|
|
|
->method('locationHandler') |
586
|
|
|
->will($this->returnValue($innerLocationHandlerMock)); |
587
|
|
|
|
588
|
|
|
$innerLocationHandlerMock |
589
|
|
|
->expects($this->once()) |
590
|
|
|
->method('loadLocationsByContent') |
591
|
|
|
->with(2) |
592
|
|
|
->willReturn([new Content\Location(array('id' => 58))]); |
593
|
|
|
|
594
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Handler'); |
595
|
|
|
$this->persistenceHandlerMock |
596
|
|
|
->expects($this->exactly(2)) |
597
|
|
|
->method('contentHandler') |
598
|
|
|
->will($this->returnValue($innerHandlerMock)); |
599
|
|
|
|
600
|
|
|
$innerHandlerMock |
601
|
|
|
->expects($this->once()) |
602
|
|
|
->method('loadReverseRelations') |
603
|
|
|
->with(2, APIRelation::FIELD) |
604
|
|
|
->will( |
605
|
|
|
$this->returnValue( |
606
|
|
|
array( |
607
|
|
|
new SPIRelation(array('sourceContentId' => 42)), |
608
|
|
|
) |
609
|
|
|
) |
610
|
|
|
); |
611
|
|
|
|
612
|
|
|
$innerHandlerMock |
613
|
|
|
->expects($this->once()) |
614
|
|
|
->method('deleteContent') |
615
|
|
|
->with(2) |
616
|
|
|
->will($this->returnValue(true)); |
617
|
|
|
|
618
|
|
|
$this->cacheMock |
619
|
|
|
->expects($this->at(0)) |
620
|
|
|
->method('clear') |
621
|
|
|
->with('content', 42) |
622
|
|
|
->will($this->returnValue(null)); |
623
|
|
|
|
624
|
|
|
$this->cacheMock |
625
|
|
|
->expects($this->at(1)) |
626
|
|
|
->method('clear') |
627
|
|
|
->with('content', 2) |
628
|
|
|
->will($this->returnValue(null)); |
629
|
|
|
|
630
|
|
|
$this->cacheMock |
631
|
|
|
->expects($this->at(2)) |
632
|
|
|
->method('clear') |
633
|
|
|
->with('content', 'info', 2) |
634
|
|
|
->will($this->returnValue(null)); |
635
|
|
|
|
636
|
|
|
$this->cacheMock |
637
|
|
|
->expects($this->at(3)) |
638
|
|
|
->method('clear') |
639
|
|
|
->with('content', 'info', 'remoteId') |
640
|
|
|
->will($this->returnValue(null)); |
641
|
|
|
|
642
|
|
|
$this->cacheMock |
643
|
|
|
->expects($this->at(4)) |
644
|
|
|
->method('clear') |
645
|
|
|
->with('location', 'subtree') |
646
|
|
|
->will($this->returnValue(null)); |
647
|
|
|
|
648
|
|
|
$this->cacheMock |
649
|
|
|
->expects($this->at(5)) |
650
|
|
|
->method('clear') |
651
|
|
|
->with('location', 58) |
652
|
|
|
->will($this->returnValue(null)); |
653
|
|
|
|
654
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
655
|
|
|
$handler->deleteContent(2); |
656
|
|
|
} |
657
|
|
|
|
658
|
|
|
/** |
659
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::deleteVersion |
660
|
|
|
*/ |
661
|
|
|
public function testDeleteVersion() |
662
|
|
|
{ |
663
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
664
|
|
|
|
665
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Handler'); |
666
|
|
|
$this->persistenceHandlerMock |
667
|
|
|
->expects($this->once()) |
668
|
|
|
->method('contentHandler') |
669
|
|
|
->will($this->returnValue($innerHandlerMock)); |
670
|
|
|
|
671
|
|
|
$innerHandlerMock |
672
|
|
|
->expects($this->once()) |
673
|
|
|
->method('deleteVersion') |
674
|
|
|
->with(2, 1) |
675
|
|
|
->will($this->returnValue(true)); |
676
|
|
|
|
677
|
|
|
$this->cacheMock |
678
|
|
|
->expects($this->at(0)) |
679
|
|
|
->method('clear') |
680
|
|
|
->with('content', 2, 1) |
681
|
|
|
->will($this->returnValue(null)); |
682
|
|
|
|
683
|
|
|
$this->cacheMock |
684
|
|
|
->expects($this->at(1)) |
685
|
|
|
->method('clear') |
686
|
|
|
->with('content', 2, ContentHandler::PUBLISHED_VERSION) |
687
|
|
|
->will($this->returnValue(null)); |
688
|
|
|
|
689
|
|
|
$this->cacheMock |
690
|
|
|
->expects($this->at(2)) |
691
|
|
|
->method('clear') |
692
|
|
|
->with('content', 'info', 2) |
693
|
|
|
->will($this->returnValue(null)); |
694
|
|
|
|
695
|
|
|
$this->cacheMock |
696
|
|
|
->expects($this->at(3)) |
697
|
|
|
->method('clear') |
698
|
|
|
->with('content', 'info', 'remoteId') |
699
|
|
|
->will($this->returnValue(null)); |
700
|
|
|
|
701
|
|
|
$this->cacheMock |
702
|
|
|
->expects($this->at(4)) |
703
|
|
|
->method('clear') |
704
|
|
|
->with('location', 'subtree') |
705
|
|
|
->will($this->returnValue(null)); |
706
|
|
|
|
707
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
708
|
|
|
$handler->deleteVersion(2, 1); |
709
|
|
|
} |
710
|
|
|
|
711
|
|
|
/** |
712
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::publish |
713
|
|
|
*/ |
714
|
|
|
public function testPublish() |
715
|
|
|
{ |
716
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
717
|
|
|
|
718
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Handler'); |
719
|
|
|
$this->persistenceHandlerMock |
720
|
|
|
->expects($this->once()) |
721
|
|
|
->method('contentHandler') |
722
|
|
|
->will($this->returnValue($innerHandlerMock)); |
723
|
|
|
|
724
|
|
|
$innerHandlerMock |
725
|
|
|
->expects($this->once()) |
726
|
|
|
->method('publish') |
727
|
|
|
->with(2, 1, $this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\MetadataUpdateStruct')) |
728
|
|
|
->will( |
729
|
|
|
$this->returnValue( |
730
|
|
|
new Content( |
731
|
|
|
array( |
732
|
|
|
'fields' => array(), |
733
|
|
|
'versionInfo' => new VersionInfo( |
734
|
|
|
array( |
735
|
|
|
'versionNo' => 1, |
736
|
|
|
'contentInfo' => new ContentInfo(array('id' => 2)), |
737
|
|
|
) |
738
|
|
|
), |
739
|
|
|
) |
740
|
|
|
) |
741
|
|
|
) |
742
|
|
|
); |
743
|
|
|
|
744
|
|
|
$this->cacheMock |
745
|
|
|
->expects($this->at(0)) |
746
|
|
|
->method('clear') |
747
|
|
|
->with('content', 2) |
748
|
|
|
->will($this->returnValue(true)); |
749
|
|
|
|
750
|
|
|
$this->cacheMock |
751
|
|
|
->expects($this->at(1)) |
752
|
|
|
->method('clear') |
753
|
|
|
->with('content', 'info', 2) |
754
|
|
|
->will($this->returnValue(true)); |
755
|
|
|
|
756
|
|
|
$this->cacheMock |
757
|
|
|
->expects($this->at(2)) |
758
|
|
|
->method('clear') |
759
|
|
|
->with('content', 'info', 'remoteId') |
760
|
|
|
->will($this->returnValue(true)); |
761
|
|
|
|
762
|
|
|
$this->cacheMock |
763
|
|
|
->expects($this->at(3)) |
764
|
|
|
->method('clear') |
765
|
|
|
->with('location', 'subtree') |
766
|
|
|
->will($this->returnValue(true)); |
767
|
|
|
|
768
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
769
|
|
|
$this->cacheMock |
770
|
|
|
->expects($this->at(4)) |
771
|
|
|
->method('getItem') |
772
|
|
|
->with('content', 2, 1, ContentHandler::ALL_TRANSLATIONS_KEY) |
773
|
|
|
->will($this->returnValue($cacheItemMock)); |
774
|
|
|
|
775
|
|
|
$cacheItemMock |
776
|
|
|
->expects($this->once()) |
777
|
|
|
->method('set') |
778
|
|
|
->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content')) |
779
|
|
|
->will($this->returnValue($cacheItemMock)); |
780
|
|
|
|
781
|
|
|
$cacheItemMock |
782
|
|
|
->expects($this->once()) |
783
|
|
|
->method('save') |
784
|
|
|
->with(); |
785
|
|
|
|
786
|
|
|
$cacheItemMock |
787
|
|
|
->expects($this->never()) |
788
|
|
|
->method('get'); |
789
|
|
|
|
790
|
|
|
$cacheItemMock2 = $this->getMock('Stash\Interfaces\ItemInterface'); |
791
|
|
|
$this->cacheMock |
792
|
|
|
->expects($this->at(5)) |
793
|
|
|
->method('getItem') |
794
|
|
|
->with('content', 'info', 2) |
795
|
|
|
->will($this->returnValue($cacheItemMock2)); |
796
|
|
|
|
797
|
|
|
$cacheItemMock2 |
798
|
|
|
->expects($this->once()) |
799
|
|
|
->method('set') |
800
|
|
|
->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\ContentInfo')) |
801
|
|
|
->will($this->returnValue($cacheItemMock2)); |
802
|
|
|
|
803
|
|
|
$cacheItemMock2 |
804
|
|
|
->expects($this->once()) |
805
|
|
|
->method('save') |
806
|
|
|
->with(); |
807
|
|
|
|
808
|
|
|
$cacheItemMock2 |
809
|
|
|
->expects($this->never()) |
810
|
|
|
->method('get'); |
811
|
|
|
|
812
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
813
|
|
|
$handler->publish(2, 1, new MetadataUpdateStruct()); |
814
|
|
|
} |
815
|
|
|
} |
816
|
|
|
|