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
|
|
|
* @version //autogentag// |
10
|
|
|
*/ |
11
|
|
|
namespace eZ\Publish\Core\Persistence\Cache\Tests; |
12
|
|
|
|
13
|
|
|
use eZ\Publish\API\Repository\Values\Content\Relation as APIRelation; |
14
|
|
|
use eZ\Publish\SPI\Persistence\Content\Relation as SPIRelation; |
15
|
|
|
use eZ\Publish\Core\Persistence\Cache\ContentHandler; |
16
|
|
|
use eZ\Publish\SPI\Persistence\Content; |
17
|
|
|
use eZ\Publish\SPI\Persistence\Content\ContentInfo; |
18
|
|
|
use eZ\Publish\SPI\Persistence\Content\VersionInfo; |
19
|
|
|
use eZ\Publish\SPI\Persistence\Content\CreateStruct; |
20
|
|
|
use eZ\Publish\SPI\Persistence\Content\UpdateStruct; |
21
|
|
|
use eZ\Publish\SPI\Persistence\Content\MetadataUpdateStruct; |
22
|
|
|
use eZ\Publish\SPI\Persistence\Content\Relation\CreateStruct as RelationCreateStruct; |
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::setStatus |
300
|
|
|
*/ |
301
|
|
View Code Duplication |
public function testSetStatus() |
302
|
|
|
{ |
303
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
304
|
|
|
|
305
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Handler'); |
306
|
|
|
$this->persistenceHandlerMock |
307
|
|
|
->expects($this->once()) |
308
|
|
|
->method('contentHandler') |
309
|
|
|
->will($this->returnValue($innerHandlerMock)); |
310
|
|
|
|
311
|
|
|
$innerHandlerMock |
312
|
|
|
->expects($this->once()) |
313
|
|
|
->method('setStatus') |
314
|
|
|
->with(2, VersionInfo::STATUS_ARCHIVED, 1) |
315
|
|
|
->will($this->returnValue(true)); |
316
|
|
|
|
317
|
|
|
$this->cacheMock |
318
|
|
|
->expects($this->once()) |
319
|
|
|
->method('clear') |
320
|
|
|
->with('content', 2, 1) |
321
|
|
|
->will($this->returnValue(null)); |
322
|
|
|
|
323
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
324
|
|
|
$handler->setStatus(2, VersionInfo::STATUS_ARCHIVED, 1); |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
/** |
328
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\ContentHandler::setStatus |
329
|
|
|
*/ |
330
|
|
|
public function testSetStatusPublished() |
331
|
|
|
{ |
332
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
333
|
|
|
|
334
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Handler'); |
335
|
|
|
$this->persistenceHandlerMock |
336
|
|
|
->expects($this->once()) |
337
|
|
|
->method('contentHandler') |
338
|
|
|
->will($this->returnValue($innerHandlerMock)); |
339
|
|
|
|
340
|
|
|
$innerHandlerMock |
341
|
|
|
->expects($this->once()) |
342
|
|
|
->method('setStatus') |
343
|
|
|
->with(2, VersionInfo::STATUS_PUBLISHED, 1) |
344
|
|
|
->will($this->returnValue(true)); |
345
|
|
|
|
346
|
|
|
$this->cacheMock |
347
|
|
|
->expects($this->at(0)) |
348
|
|
|
->method('clear') |
349
|
|
|
->with('content', 2, 1) |
350
|
|
|
->will($this->returnValue(null)); |
351
|
|
|
|
352
|
|
|
$this->cacheMock |
353
|
|
|
->expects($this->at(1)) |
354
|
|
|
->method('clear') |
355
|
|
|
->with('content', 'info', 2) |
356
|
|
|
->will($this->returnValue(null)); |
357
|
|
|
|
358
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
359
|
|
|
$handler->setStatus(2, VersionInfo::STATUS_PUBLISHED, 1); |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
/** |
363
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\ContentHandler::updateMetadata |
364
|
|
|
*/ |
365
|
|
|
public function testUpdateMetadata() |
366
|
|
|
{ |
367
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
368
|
|
|
|
369
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Handler'); |
370
|
|
|
$this->persistenceHandlerMock |
371
|
|
|
->expects($this->once()) |
372
|
|
|
->method('contentHandler') |
373
|
|
|
->will($this->returnValue($innerHandlerMock)); |
374
|
|
|
|
375
|
|
|
$innerHandlerMock |
376
|
|
|
->expects($this->once()) |
377
|
|
|
->method('updateMetadata') |
378
|
|
|
->with(2, $this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\MetadataUpdateStruct')) |
379
|
|
|
->will($this->returnValue(new ContentInfo(array('id' => 2)))); |
380
|
|
|
|
381
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
382
|
|
|
$this->cacheMock |
383
|
|
|
->expects($this->once()) |
384
|
|
|
->method('getItem') |
385
|
|
|
->with('content', 'info', 2) |
386
|
|
|
->will($this->returnValue($cacheItemMock)); |
387
|
|
|
|
388
|
|
|
$cacheItemMock |
389
|
|
|
->expects($this->once()) |
390
|
|
|
->method('set') |
391
|
|
|
->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\ContentInfo')) |
392
|
|
|
->will($this->returnValue($cacheItemMock)); |
393
|
|
|
|
394
|
|
|
$cacheItemMock |
395
|
|
|
->expects($this->once()) |
396
|
|
|
->method('save') |
397
|
|
|
->with(); |
398
|
|
|
|
399
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
400
|
|
|
$handler->updateMetadata(2, new MetadataUpdateStruct()); |
401
|
|
|
} |
402
|
|
|
|
403
|
|
|
/** |
404
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\ContentHandler::updateContent |
405
|
|
|
*/ |
406
|
|
|
public function testUpdateContent() |
407
|
|
|
{ |
408
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
409
|
|
|
|
410
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Handler'); |
411
|
|
|
$this->persistenceHandlerMock |
412
|
|
|
->expects($this->once()) |
413
|
|
|
->method('contentHandler') |
414
|
|
|
->will($this->returnValue($innerHandlerMock)); |
415
|
|
|
|
416
|
|
|
$innerHandlerMock |
417
|
|
|
->expects($this->once()) |
418
|
|
|
->method('updateContent') |
419
|
|
|
->with(2, 1, $this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\UpdateStruct')) |
420
|
|
|
->will( |
421
|
|
|
$this->returnValue( |
422
|
|
|
new Content( |
423
|
|
|
array( |
424
|
|
|
'fields' => array(), |
425
|
|
|
'versionInfo' => new VersionInfo( |
426
|
|
|
array( |
427
|
|
|
'versionNo' => 1, |
428
|
|
|
'contentInfo' => new ContentInfo(array('id' => 2)), |
429
|
|
|
) |
430
|
|
|
), |
431
|
|
|
) |
432
|
|
|
) |
433
|
|
|
) |
434
|
|
|
); |
435
|
|
|
|
436
|
|
|
$this->cacheMock |
437
|
|
|
->expects($this->once()) |
438
|
|
|
->method('clear') |
439
|
|
|
->with('content', 2, 1) |
440
|
|
|
->will($this->returnValue(null)); |
441
|
|
|
|
442
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
443
|
|
|
$this->cacheMock |
444
|
|
|
->expects($this->once()) |
445
|
|
|
->method('getItem') |
446
|
|
|
->with('content', 2, 1, ContentHandler::ALL_TRANSLATIONS_KEY) |
447
|
|
|
->will($this->returnValue($cacheItemMock)); |
448
|
|
|
|
449
|
|
|
$cacheItemMock |
450
|
|
|
->expects($this->once()) |
451
|
|
|
->method('set') |
452
|
|
|
->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content')) |
453
|
|
|
->will($this->returnValue($cacheItemMock)); |
454
|
|
|
|
455
|
|
|
$cacheItemMock |
456
|
|
|
->expects($this->once()) |
457
|
|
|
->method('save') |
458
|
|
|
->with(); |
459
|
|
|
|
460
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
461
|
|
|
$handler->updateContent(2, 1, new UpdateStruct()); |
462
|
|
|
} |
463
|
|
|
|
464
|
|
|
/** |
465
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\ContentHandler::deleteContent |
466
|
|
|
*/ |
467
|
|
|
public function testDeleteContent() |
468
|
|
|
{ |
469
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
470
|
|
|
|
471
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Handler'); |
472
|
|
|
$this->persistenceHandlerMock |
473
|
|
|
->expects($this->exactly(2)) |
474
|
|
|
->method('contentHandler') |
475
|
|
|
->will($this->returnValue($innerHandlerMock)); |
476
|
|
|
|
477
|
|
|
$innerHandlerMock |
478
|
|
|
->expects($this->once()) |
479
|
|
|
->method('loadReverseRelations') |
480
|
|
|
->with(2, APIRelation::FIELD) |
481
|
|
|
->will( |
482
|
|
|
$this->returnValue( |
483
|
|
|
array( |
484
|
|
|
new SPIRelation(array('sourceContentId' => 42)), |
485
|
|
|
) |
486
|
|
|
) |
487
|
|
|
); |
488
|
|
|
|
489
|
|
|
$innerHandlerMock |
490
|
|
|
->expects($this->once()) |
491
|
|
|
->method('deleteContent') |
492
|
|
|
->with(2) |
493
|
|
|
->will($this->returnValue(true)); |
494
|
|
|
|
495
|
|
|
$this->cacheMock |
496
|
|
|
->expects($this->at(0)) |
497
|
|
|
->method('clear') |
498
|
|
|
->with('content', 42) |
499
|
|
|
->will($this->returnValue(null)); |
500
|
|
|
|
501
|
|
|
$this->cacheMock |
502
|
|
|
->expects($this->at(1)) |
503
|
|
|
->method('clear') |
504
|
|
|
->with('content', 2) |
505
|
|
|
->will($this->returnValue(null)); |
506
|
|
|
|
507
|
|
|
$this->cacheMock |
508
|
|
|
->expects($this->at(2)) |
509
|
|
|
->method('clear') |
510
|
|
|
->with('content', 'info', 2) |
511
|
|
|
->will($this->returnValue(null)); |
512
|
|
|
|
513
|
|
|
$this->cacheMock |
514
|
|
|
->expects($this->at(3)) |
515
|
|
|
->method('clear') |
516
|
|
|
->with('content', 'info', 'remoteId') |
517
|
|
|
->will($this->returnValue(null)); |
518
|
|
|
|
519
|
|
|
$this->cacheMock |
520
|
|
|
->expects($this->at(4)) |
521
|
|
|
->method('clear') |
522
|
|
|
->with('location', 'subtree') |
523
|
|
|
->will($this->returnValue(null)); |
524
|
|
|
|
525
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
526
|
|
|
$handler->deleteContent(2); |
527
|
|
|
} |
528
|
|
|
|
529
|
|
|
/** |
530
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\ContentHandler::deleteVersion |
531
|
|
|
*/ |
532
|
|
|
public function testDeleteVersion() |
533
|
|
|
{ |
534
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
535
|
|
|
|
536
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Handler'); |
537
|
|
|
$this->persistenceHandlerMock |
538
|
|
|
->expects($this->once()) |
539
|
|
|
->method('contentHandler') |
540
|
|
|
->will($this->returnValue($innerHandlerMock)); |
541
|
|
|
|
542
|
|
|
$innerHandlerMock |
543
|
|
|
->expects($this->once()) |
544
|
|
|
->method('deleteVersion') |
545
|
|
|
->with(2, 1) |
546
|
|
|
->will($this->returnValue(true)); |
547
|
|
|
|
548
|
|
|
$this->cacheMock |
549
|
|
|
->expects($this->at(0)) |
550
|
|
|
->method('clear') |
551
|
|
|
->with('content', 2, 1) |
552
|
|
|
->will($this->returnValue(null)); |
553
|
|
|
|
554
|
|
|
$this->cacheMock |
555
|
|
|
->expects($this->at(1)) |
556
|
|
|
->method('clear') |
557
|
|
|
->with('content', 'info', 2) |
558
|
|
|
->will($this->returnValue(null)); |
559
|
|
|
|
560
|
|
|
$this->cacheMock |
561
|
|
|
->expects($this->at(2)) |
562
|
|
|
->method('clear') |
563
|
|
|
->with('content', 'info', 'remoteId') |
564
|
|
|
->will($this->returnValue(null)); |
565
|
|
|
|
566
|
|
|
$this->cacheMock |
567
|
|
|
->expects($this->at(3)) |
568
|
|
|
->method('clear') |
569
|
|
|
->with('location', 'subtree') |
570
|
|
|
->will($this->returnValue(null)); |
571
|
|
|
|
572
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
573
|
|
|
$handler->deleteVersion(2, 1); |
574
|
|
|
} |
575
|
|
|
|
576
|
|
|
/** |
577
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\ContentHandler::publish |
578
|
|
|
*/ |
579
|
|
|
public function testPublish() |
580
|
|
|
{ |
581
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
582
|
|
|
|
583
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Handler'); |
584
|
|
|
$this->persistenceHandlerMock |
585
|
|
|
->expects($this->once()) |
586
|
|
|
->method('contentHandler') |
587
|
|
|
->will($this->returnValue($innerHandlerMock)); |
588
|
|
|
|
589
|
|
|
$innerHandlerMock |
590
|
|
|
->expects($this->once()) |
591
|
|
|
->method('publish') |
592
|
|
|
->with(2, 1, $this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\MetadataUpdateStruct')) |
593
|
|
|
->will( |
594
|
|
|
$this->returnValue( |
595
|
|
|
new Content( |
596
|
|
|
array( |
597
|
|
|
'fields' => array(), |
598
|
|
|
'versionInfo' => new VersionInfo( |
599
|
|
|
array( |
600
|
|
|
'versionNo' => 1, |
601
|
|
|
'contentInfo' => new ContentInfo(array('id' => 2)), |
602
|
|
|
) |
603
|
|
|
), |
604
|
|
|
) |
605
|
|
|
) |
606
|
|
|
) |
607
|
|
|
); |
608
|
|
|
|
609
|
|
|
$this->cacheMock |
610
|
|
|
->expects($this->at(0)) |
611
|
|
|
->method('clear') |
612
|
|
|
->with('content', 2) |
613
|
|
|
->will($this->returnValue(true)); |
614
|
|
|
|
615
|
|
|
$this->cacheMock |
616
|
|
|
->expects($this->at(1)) |
617
|
|
|
->method('clear') |
618
|
|
|
->with('content', 'info', 'remoteId') |
619
|
|
|
->will($this->returnValue(true)); |
620
|
|
|
|
621
|
|
|
$this->cacheMock |
622
|
|
|
->expects($this->at(2)) |
623
|
|
|
->method('clear') |
624
|
|
|
->with('location', 'subtree') |
625
|
|
|
->will($this->returnValue(true)); |
626
|
|
|
|
627
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
628
|
|
|
$this->cacheMock |
629
|
|
|
->expects($this->at(3)) |
630
|
|
|
->method('getItem') |
631
|
|
|
->with('content', 2, 1, ContentHandler::ALL_TRANSLATIONS_KEY) |
632
|
|
|
->will($this->returnValue($cacheItemMock)); |
633
|
|
|
|
634
|
|
|
$cacheItemMock |
635
|
|
|
->expects($this->once()) |
636
|
|
|
->method('set') |
637
|
|
|
->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content')) |
638
|
|
|
->will($this->returnValue($cacheItemMock)); |
639
|
|
|
|
640
|
|
|
$cacheItemMock |
641
|
|
|
->expects($this->once()) |
642
|
|
|
->method('save') |
643
|
|
|
->with(); |
644
|
|
|
|
645
|
|
|
$cacheItemMock |
646
|
|
|
->expects($this->never()) |
647
|
|
|
->method('get'); |
648
|
|
|
|
649
|
|
|
$cacheItemMock2 = $this->getMock('Stash\Interfaces\ItemInterface'); |
650
|
|
|
$this->cacheMock |
651
|
|
|
->expects($this->at(4)) |
652
|
|
|
->method('getItem') |
653
|
|
|
->with('content', 'info', 2) |
654
|
|
|
->will($this->returnValue($cacheItemMock2)); |
655
|
|
|
|
656
|
|
|
$cacheItemMock2 |
657
|
|
|
->expects($this->once()) |
658
|
|
|
->method('set') |
659
|
|
|
->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\ContentInfo')) |
660
|
|
|
->will($this->returnValue($cacheItemMock2)); |
661
|
|
|
|
662
|
|
|
$cacheItemMock2 |
663
|
|
|
->expects($this->once()) |
664
|
|
|
->method('save') |
665
|
|
|
->with(); |
666
|
|
|
|
667
|
|
|
$cacheItemMock2 |
668
|
|
|
->expects($this->never()) |
669
|
|
|
->method('get'); |
670
|
|
|
|
671
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
672
|
|
|
$handler->publish(2, 1, new MetadataUpdateStruct()); |
673
|
|
|
} |
674
|
|
|
} |
675
|
|
|
|