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\ContentInfo; |
16
|
|
|
use eZ\Publish\SPI\Persistence\Content\VersionInfo; |
17
|
|
|
use eZ\Publish\SPI\Persistence\Content\CreateStruct; |
18
|
|
|
use eZ\Publish\SPI\Persistence\Content\UpdateStruct; |
19
|
|
|
use eZ\Publish\SPI\Persistence\Content\MetadataUpdateStruct; |
20
|
|
|
use eZ\Publish\SPI\Persistence\Content\Relation\CreateStruct as RelationCreateStruct; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Test case for Persistence\Cache\ContentHandler. |
24
|
|
|
*/ |
25
|
|
|
class ContentHandlerTest extends HandlerTest |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @return array |
29
|
|
|
*/ |
30
|
|
|
public function providerForUnCachedMethods() |
31
|
|
|
{ |
32
|
|
|
return array( |
33
|
|
|
array('create', array(new CreateStruct())), |
34
|
|
|
array('createDraftFromVersion', array(2, 1, 14)), |
35
|
|
|
array('copy', array(2, 1)), |
36
|
|
|
//array( 'load', array( 2, 1, array( 'eng-GB' ) ) ), |
37
|
|
|
//array( 'load', array( 2, 1 ) ), |
38
|
|
|
//array( 'loadContentInfo', array( 2 ) ), |
39
|
|
|
array('loadVersionInfo', array(2, 1)), |
40
|
|
|
array('loadDraftsForUser', array(14)), |
41
|
|
|
//array( 'setStatus', array( 2, 0, 1 ) ), |
42
|
|
|
//array( 'updateMetadata', array( 2, new MetadataUpdateStruct ) ), |
43
|
|
|
//array( 'updateContent', array( 2, 1, new UpdateStruct ) ), |
44
|
|
|
//array( 'deleteContent', array( 2 ) ), |
45
|
|
|
//array( 'deleteVersion', array( 2, 1 ) ), |
46
|
|
|
array('listVersions', array(2)), |
47
|
|
|
array('addRelation', array(new RelationCreateStruct())), |
48
|
|
|
array('removeRelation', array(66, APIRelation::COMMON)), |
49
|
|
|
array('loadRelations', array(2, 1, 3)), |
50
|
|
|
array('loadReverseRelations', array(2, 3)), |
51
|
|
|
//array( 'publish', array( 2, 3, new MetadataUpdateStruct ) ), |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @dataProvider providerForUnCachedMethods |
57
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler |
58
|
|
|
*/ |
59
|
|
View Code Duplication |
public function testUnCachedMethods($method, array $arguments) |
60
|
|
|
{ |
61
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
62
|
|
|
$this->cacheMock |
63
|
|
|
->expects($this->never()) |
64
|
|
|
->method($this->anything()); |
65
|
|
|
|
66
|
|
|
$innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Handler'); |
67
|
|
|
$this->persistenceHandlerMock |
68
|
|
|
->expects($this->once()) |
69
|
|
|
->method('contentHandler') |
70
|
|
|
->will($this->returnValue($innerHandler)); |
71
|
|
|
|
72
|
|
|
$expects = $innerHandler |
73
|
|
|
->expects($this->once()) |
74
|
|
|
->method($method); |
75
|
|
|
|
76
|
|
|
if (isset($arguments[2])) { |
77
|
|
|
$expects->with($arguments[0], $arguments[1], $arguments[2]); |
78
|
|
|
} elseif (isset($arguments[1])) { |
79
|
|
|
$expects->with($arguments[0], $arguments[1]); |
80
|
|
|
} elseif (isset($arguments[0])) { |
81
|
|
|
$expects->with($arguments[0]); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
$expects->will($this->returnValue(null)); |
85
|
|
|
|
86
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
87
|
|
|
call_user_func_array(array($handler, $method), $arguments); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::load |
92
|
|
|
*/ |
93
|
|
|
public function testLoadCacheIsMiss() |
94
|
|
|
{ |
95
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
96
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
97
|
|
|
$this->cacheMock |
98
|
|
|
->expects($this->once()) |
99
|
|
|
->method('getItem') |
100
|
|
|
->with('content', 2, 1, 'eng-GB|eng-US') |
101
|
|
|
->will($this->returnValue($cacheItemMock)); |
102
|
|
|
|
103
|
|
|
$cacheItemMock |
104
|
|
|
->expects($this->once()) |
105
|
|
|
->method('get') |
106
|
|
|
->will($this->returnValue(null)); |
107
|
|
|
|
108
|
|
|
$cacheItemMock |
109
|
|
|
->expects($this->once()) |
110
|
|
|
->method('isMiss') |
111
|
|
|
->will($this->returnValue(true)); |
112
|
|
|
|
113
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Handler'); |
114
|
|
|
$this->persistenceHandlerMock |
115
|
|
|
->expects($this->once()) |
116
|
|
|
->method('contentHandler') |
117
|
|
|
->will($this->returnValue($innerHandlerMock)); |
118
|
|
|
|
119
|
|
|
$innerHandlerMock |
120
|
|
|
->expects($this->once()) |
121
|
|
|
->method('load') |
122
|
|
|
->with(2, 1, array('eng-GB', 'eng-US')) |
123
|
|
|
->will( |
124
|
|
|
$this->returnValue( |
125
|
|
|
new Content( |
126
|
|
|
array( |
127
|
|
|
'fields' => array(), |
128
|
|
|
'versionInfo' => new VersionInfo( |
129
|
|
|
array( |
130
|
|
|
'versionNo' => 1, |
131
|
|
|
'contentInfo' => new ContentInfo(array('id' => 2)), |
132
|
|
|
) |
133
|
|
|
), |
134
|
|
|
) |
135
|
|
|
) |
136
|
|
|
) |
137
|
|
|
); |
138
|
|
|
|
139
|
|
|
$cacheItemMock |
140
|
|
|
->expects($this->once()) |
141
|
|
|
->method('set') |
142
|
|
|
->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content')) |
143
|
|
|
->will($this->returnValue($cacheItemMock)); |
144
|
|
|
|
145
|
|
|
$cacheItemMock |
146
|
|
|
->expects($this->once()) |
147
|
|
|
->method('save') |
148
|
|
|
->with(); |
149
|
|
|
|
150
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
151
|
|
|
$handler->load(2, 1, array('eng-GB', 'eng-US')); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::load |
156
|
|
|
*/ |
157
|
|
|
public function testLoadHasCache() |
158
|
|
|
{ |
159
|
|
|
$this->loggerMock->expects($this->never())->method($this->anything()); |
160
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
161
|
|
|
$this->cacheMock |
162
|
|
|
->expects($this->once()) |
163
|
|
|
->method('getItem') |
164
|
|
|
->with('content', 2, 1, ContentHandler::ALL_TRANSLATIONS_KEY) |
165
|
|
|
->will($this->returnValue($cacheItemMock)); |
166
|
|
|
|
167
|
|
|
$cacheItemMock |
168
|
|
|
->expects($this->once()) |
169
|
|
|
->method('isMiss') |
170
|
|
|
->will($this->returnValue(false)); |
171
|
|
|
|
172
|
|
|
$this->persistenceHandlerMock |
173
|
|
|
->expects($this->never()) |
174
|
|
|
->method('contentHandler'); |
175
|
|
|
|
176
|
|
|
$cacheItemMock |
177
|
|
|
->expects($this->once()) |
178
|
|
|
->method('get') |
179
|
|
|
->will( |
180
|
|
|
$this->returnValue( |
181
|
|
|
new Content( |
182
|
|
|
array( |
183
|
|
|
'fields' => array(), |
184
|
|
|
'versionInfo' => new VersionInfo( |
185
|
|
|
array( |
186
|
|
|
'versionNo' => 1, |
187
|
|
|
'contentInfo' => new ContentInfo(array('id' => 2)), |
188
|
|
|
) |
189
|
|
|
), |
190
|
|
|
) |
191
|
|
|
) |
192
|
|
|
) |
193
|
|
|
); |
194
|
|
|
|
195
|
|
|
$cacheItemMock |
196
|
|
|
->expects($this->never()) |
197
|
|
|
->method('set'); |
198
|
|
|
|
199
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
200
|
|
|
$handler->load(2, 1); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::loadContentInfo |
205
|
|
|
*/ |
206
|
|
|
public function testLoadContentInfoCacheIsMiss() |
207
|
|
|
{ |
208
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
209
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
210
|
|
|
$this->cacheMock |
211
|
|
|
->expects($this->once()) |
212
|
|
|
->method('getItem') |
213
|
|
|
->with('content', 'info', 2) |
214
|
|
|
->will($this->returnValue($cacheItemMock)); |
215
|
|
|
|
216
|
|
|
$cacheItemMock |
217
|
|
|
->expects($this->once()) |
218
|
|
|
->method('get') |
219
|
|
|
->will($this->returnValue(null)); |
220
|
|
|
|
221
|
|
|
$cacheItemMock |
222
|
|
|
->expects($this->once()) |
223
|
|
|
->method('isMiss') |
224
|
|
|
->will($this->returnValue(true)); |
225
|
|
|
|
226
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Handler'); |
227
|
|
|
$this->persistenceHandlerMock |
228
|
|
|
->expects($this->once()) |
229
|
|
|
->method('contentHandler') |
230
|
|
|
->will($this->returnValue($innerHandlerMock)); |
231
|
|
|
|
232
|
|
|
$innerHandlerMock |
233
|
|
|
->expects($this->once()) |
234
|
|
|
->method('loadContentInfo') |
235
|
|
|
->with(2) |
236
|
|
|
->will( |
237
|
|
|
$this->returnValue( |
238
|
|
|
new ContentInfo(array('id' => 2)) |
239
|
|
|
) |
240
|
|
|
); |
241
|
|
|
|
242
|
|
|
$cacheItemMock |
243
|
|
|
->expects($this->once()) |
244
|
|
|
->method('set') |
245
|
|
|
->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\ContentInfo')) |
246
|
|
|
->will($this->returnValue($cacheItemMock)); |
247
|
|
|
|
248
|
|
|
$cacheItemMock |
249
|
|
|
->expects($this->once()) |
250
|
|
|
->method('save') |
251
|
|
|
->with(); |
252
|
|
|
|
253
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
254
|
|
|
$handler->loadContentInfo(2, 1); |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::loadContentInfo |
259
|
|
|
*/ |
260
|
|
|
public function testLoadContentInfoHasCache() |
261
|
|
|
{ |
262
|
|
|
$this->loggerMock->expects($this->never())->method($this->anything()); |
263
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
264
|
|
|
$this->cacheMock |
265
|
|
|
->expects($this->once()) |
266
|
|
|
->method('getItem') |
267
|
|
|
->with('content', 'info', 2) |
268
|
|
|
->will($this->returnValue($cacheItemMock)); |
269
|
|
|
|
270
|
|
|
$cacheItemMock |
271
|
|
|
->expects($this->once()) |
272
|
|
|
->method('isMiss') |
273
|
|
|
->will($this->returnValue(false)); |
274
|
|
|
|
275
|
|
|
$this->persistenceHandlerMock |
276
|
|
|
->expects($this->never()) |
277
|
|
|
->method('contentHandler'); |
278
|
|
|
|
279
|
|
|
$cacheItemMock |
280
|
|
|
->expects($this->once()) |
281
|
|
|
->method('get') |
282
|
|
|
->will( |
283
|
|
|
$this->returnValue( |
284
|
|
|
new ContentInfo(array('id' => 2)) |
285
|
|
|
) |
286
|
|
|
); |
287
|
|
|
|
288
|
|
|
$cacheItemMock |
289
|
|
|
->expects($this->never()) |
290
|
|
|
->method('set'); |
291
|
|
|
|
292
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
293
|
|
|
$handler->loadContentInfo(2); |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
/** |
297
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::setStatus |
298
|
|
|
*/ |
299
|
|
View Code Duplication |
public function testSetStatus() |
300
|
|
|
{ |
301
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
302
|
|
|
|
303
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Handler'); |
304
|
|
|
$this->persistenceHandlerMock |
305
|
|
|
->expects($this->once()) |
306
|
|
|
->method('contentHandler') |
307
|
|
|
->will($this->returnValue($innerHandlerMock)); |
308
|
|
|
|
309
|
|
|
$innerHandlerMock |
310
|
|
|
->expects($this->once()) |
311
|
|
|
->method('setStatus') |
312
|
|
|
->with(2, VersionInfo::STATUS_ARCHIVED, 1) |
313
|
|
|
->will($this->returnValue(true)); |
314
|
|
|
|
315
|
|
|
$this->cacheMock |
316
|
|
|
->expects($this->once()) |
317
|
|
|
->method('clear') |
318
|
|
|
->with('content', 2, 1) |
319
|
|
|
->will($this->returnValue(null)); |
320
|
|
|
|
321
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
322
|
|
|
$handler->setStatus(2, VersionInfo::STATUS_ARCHIVED, 1); |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
/** |
326
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::setStatus |
327
|
|
|
*/ |
328
|
|
|
public function testSetStatusPublished() |
329
|
|
|
{ |
330
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
331
|
|
|
|
332
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Handler'); |
333
|
|
|
$this->persistenceHandlerMock |
334
|
|
|
->expects($this->once()) |
335
|
|
|
->method('contentHandler') |
336
|
|
|
->will($this->returnValue($innerHandlerMock)); |
337
|
|
|
|
338
|
|
|
$innerHandlerMock |
339
|
|
|
->expects($this->once()) |
340
|
|
|
->method('setStatus') |
341
|
|
|
->with(2, VersionInfo::STATUS_PUBLISHED, 1) |
342
|
|
|
->will($this->returnValue(true)); |
343
|
|
|
|
344
|
|
|
$this->cacheMock |
345
|
|
|
->expects($this->at(0)) |
346
|
|
|
->method('clear') |
347
|
|
|
->with('content', 2, 1) |
348
|
|
|
->will($this->returnValue(null)); |
349
|
|
|
|
350
|
|
|
$this->cacheMock |
351
|
|
|
->expects($this->at(1)) |
352
|
|
|
->method('clear') |
353
|
|
|
->with('content', 'info', 2) |
354
|
|
|
->will($this->returnValue(null)); |
355
|
|
|
|
356
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
357
|
|
|
$handler->setStatus(2, VersionInfo::STATUS_PUBLISHED, 1); |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
/** |
361
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::updateMetadata |
362
|
|
|
*/ |
363
|
|
|
public function testUpdateMetadata() |
364
|
|
|
{ |
365
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
366
|
|
|
|
367
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Handler'); |
368
|
|
|
$this->persistenceHandlerMock |
369
|
|
|
->expects($this->once()) |
370
|
|
|
->method('contentHandler') |
371
|
|
|
->will($this->returnValue($innerHandlerMock)); |
372
|
|
|
|
373
|
|
|
$innerHandlerMock |
374
|
|
|
->expects($this->once()) |
375
|
|
|
->method('updateMetadata') |
376
|
|
|
->with(2, $this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\MetadataUpdateStruct')) |
377
|
|
|
->willReturn(new ContentInfo(array('id' => 2, 'currentVersionNo' => 3, 'remoteId' => 'o34'))); |
378
|
|
|
|
379
|
|
|
$this->cacheMock |
380
|
|
|
->expects($this->at(0)) |
381
|
|
|
->method('clear') |
382
|
|
|
->with('content', 2, 3) |
383
|
|
|
->willReturn(null); |
384
|
|
|
|
385
|
|
|
$this->cacheMock |
386
|
|
|
->expects($this->at(1)) |
387
|
|
|
->method('clear') |
388
|
|
|
->with('content', 'info', 2) |
389
|
|
|
->willReturn(null); |
390
|
|
|
|
391
|
|
|
$this->cacheMock |
392
|
|
|
->expects($this->at(2)) |
393
|
|
|
->method('clear') |
394
|
|
|
->with('content', 'info', 'remoteId', 'o34') |
395
|
|
|
->willReturn(null); |
396
|
|
|
|
397
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
398
|
|
|
$handler->updateMetadata(2, new MetadataUpdateStruct()); |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
/** |
402
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::updateContent |
403
|
|
|
*/ |
404
|
|
|
public function testUpdateContent() |
405
|
|
|
{ |
406
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
407
|
|
|
|
408
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Handler'); |
409
|
|
|
$this->persistenceHandlerMock |
410
|
|
|
->expects($this->once()) |
411
|
|
|
->method('contentHandler') |
412
|
|
|
->will($this->returnValue($innerHandlerMock)); |
413
|
|
|
|
414
|
|
|
$innerHandlerMock |
415
|
|
|
->expects($this->once()) |
416
|
|
|
->method('updateContent') |
417
|
|
|
->with(2, 1, $this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\UpdateStruct')) |
418
|
|
|
->will( |
419
|
|
|
$this->returnValue( |
420
|
|
|
new Content( |
421
|
|
|
array( |
422
|
|
|
'fields' => array(), |
423
|
|
|
'versionInfo' => new VersionInfo( |
424
|
|
|
array( |
425
|
|
|
'versionNo' => 1, |
426
|
|
|
'contentInfo' => new ContentInfo(array('id' => 2)), |
427
|
|
|
) |
428
|
|
|
), |
429
|
|
|
) |
430
|
|
|
) |
431
|
|
|
) |
432
|
|
|
); |
433
|
|
|
|
434
|
|
|
$this->cacheMock |
435
|
|
|
->expects($this->once()) |
436
|
|
|
->method('clear') |
437
|
|
|
->with('content', 2, 1) |
438
|
|
|
->will($this->returnValue(null)); |
439
|
|
|
|
440
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
441
|
|
|
$handler->updateContent(2, 1, new UpdateStruct()); |
442
|
|
|
} |
443
|
|
|
|
444
|
|
|
/** |
445
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::deleteContent |
446
|
|
|
*/ |
447
|
|
|
public function testDeleteContent() |
448
|
|
|
{ |
449
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
450
|
|
|
|
451
|
|
|
$innerLocationHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Location\\Handler'); |
452
|
|
|
$this->persistenceHandlerMock |
453
|
|
|
->expects($this->exactly(1)) |
454
|
|
|
->method('locationHandler') |
455
|
|
|
->will($this->returnValue($innerLocationHandlerMock)); |
456
|
|
|
|
457
|
|
|
$innerLocationHandlerMock |
458
|
|
|
->expects($this->once()) |
459
|
|
|
->method('loadLocationsByContent') |
460
|
|
|
->with(2) |
461
|
|
|
->willReturn([new Content\Location(array('id' => 58))]); |
462
|
|
|
|
463
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Handler'); |
464
|
|
|
$this->persistenceHandlerMock |
465
|
|
|
->expects($this->exactly(2)) |
466
|
|
|
->method('contentHandler') |
467
|
|
|
->will($this->returnValue($innerHandlerMock)); |
468
|
|
|
|
469
|
|
|
$innerHandlerMock |
470
|
|
|
->expects($this->once()) |
471
|
|
|
->method('loadReverseRelations') |
472
|
|
|
->with(2, APIRelation::FIELD) |
473
|
|
|
->will( |
474
|
|
|
$this->returnValue( |
475
|
|
|
array( |
476
|
|
|
new SPIRelation(array('sourceContentId' => 42)), |
477
|
|
|
) |
478
|
|
|
) |
479
|
|
|
); |
480
|
|
|
|
481
|
|
|
$innerHandlerMock |
482
|
|
|
->expects($this->once()) |
483
|
|
|
->method('deleteContent') |
484
|
|
|
->with(2) |
485
|
|
|
->will($this->returnValue(true)); |
486
|
|
|
|
487
|
|
|
$this->cacheMock |
488
|
|
|
->expects($this->at(0)) |
489
|
|
|
->method('clear') |
490
|
|
|
->with('content', 42) |
491
|
|
|
->will($this->returnValue(null)); |
492
|
|
|
|
493
|
|
|
$this->cacheMock |
494
|
|
|
->expects($this->at(1)) |
495
|
|
|
->method('clear') |
496
|
|
|
->with('content', 2) |
497
|
|
|
->will($this->returnValue(null)); |
498
|
|
|
|
499
|
|
|
$this->cacheMock |
500
|
|
|
->expects($this->at(2)) |
501
|
|
|
->method('clear') |
502
|
|
|
->with('content', 'info', 2) |
503
|
|
|
->will($this->returnValue(null)); |
504
|
|
|
|
505
|
|
|
$this->cacheMock |
506
|
|
|
->expects($this->at(3)) |
507
|
|
|
->method('clear') |
508
|
|
|
->with('content', 'info', 'remoteId') |
509
|
|
|
->will($this->returnValue(null)); |
510
|
|
|
|
511
|
|
|
$this->cacheMock |
512
|
|
|
->expects($this->at(4)) |
513
|
|
|
->method('clear') |
514
|
|
|
->with('location', 'subtree') |
515
|
|
|
->will($this->returnValue(null)); |
516
|
|
|
|
517
|
|
|
$this->cacheMock |
518
|
|
|
->expects($this->at(5)) |
519
|
|
|
->method('clear') |
520
|
|
|
->with('location', 58) |
521
|
|
|
->will($this->returnValue(null)); |
522
|
|
|
|
523
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
524
|
|
|
$handler->deleteContent(2); |
525
|
|
|
} |
526
|
|
|
|
527
|
|
|
/** |
528
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::deleteVersion |
529
|
|
|
*/ |
530
|
|
|
public function testDeleteVersion() |
531
|
|
|
{ |
532
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
533
|
|
|
|
534
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Handler'); |
535
|
|
|
$this->persistenceHandlerMock |
536
|
|
|
->expects($this->once()) |
537
|
|
|
->method('contentHandler') |
538
|
|
|
->will($this->returnValue($innerHandlerMock)); |
539
|
|
|
|
540
|
|
|
$innerHandlerMock |
541
|
|
|
->expects($this->once()) |
542
|
|
|
->method('deleteVersion') |
543
|
|
|
->with(2, 1) |
544
|
|
|
->will($this->returnValue(true)); |
545
|
|
|
|
546
|
|
|
$this->cacheMock |
547
|
|
|
->expects($this->at(0)) |
548
|
|
|
->method('clear') |
549
|
|
|
->with('content', 2, 1) |
550
|
|
|
->will($this->returnValue(null)); |
551
|
|
|
|
552
|
|
|
$this->cacheMock |
553
|
|
|
->expects($this->at(1)) |
554
|
|
|
->method('clear') |
555
|
|
|
->with('content', 'info', 2) |
556
|
|
|
->will($this->returnValue(null)); |
557
|
|
|
|
558
|
|
|
$this->cacheMock |
559
|
|
|
->expects($this->at(2)) |
560
|
|
|
->method('clear') |
561
|
|
|
->with('content', 'info', 'remoteId') |
562
|
|
|
->will($this->returnValue(null)); |
563
|
|
|
|
564
|
|
|
$this->cacheMock |
565
|
|
|
->expects($this->at(3)) |
566
|
|
|
->method('clear') |
567
|
|
|
->with('location', 'subtree') |
568
|
|
|
->will($this->returnValue(null)); |
569
|
|
|
|
570
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
571
|
|
|
$handler->deleteVersion(2, 1); |
572
|
|
|
} |
573
|
|
|
|
574
|
|
|
/** |
575
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::publish |
576
|
|
|
*/ |
577
|
|
|
public function testPublish() |
578
|
|
|
{ |
579
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
580
|
|
|
|
581
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Handler'); |
582
|
|
|
$this->persistenceHandlerMock |
583
|
|
|
->expects($this->once()) |
584
|
|
|
->method('contentHandler') |
585
|
|
|
->will($this->returnValue($innerHandlerMock)); |
586
|
|
|
|
587
|
|
|
$innerHandlerMock |
588
|
|
|
->expects($this->once()) |
589
|
|
|
->method('publish') |
590
|
|
|
->with(2, 1, $this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\MetadataUpdateStruct')) |
591
|
|
|
->will( |
592
|
|
|
$this->returnValue( |
593
|
|
|
new Content( |
594
|
|
|
array( |
595
|
|
|
'fields' => array(), |
596
|
|
|
'versionInfo' => new VersionInfo( |
597
|
|
|
array( |
598
|
|
|
'versionNo' => 1, |
599
|
|
|
'contentInfo' => new ContentInfo(array('id' => 2)), |
600
|
|
|
) |
601
|
|
|
), |
602
|
|
|
) |
603
|
|
|
) |
604
|
|
|
) |
605
|
|
|
); |
606
|
|
|
|
607
|
|
|
$this->cacheMock |
608
|
|
|
->expects($this->at(0)) |
609
|
|
|
->method('clear') |
610
|
|
|
->with('content', 2) |
611
|
|
|
->will($this->returnValue(true)); |
612
|
|
|
|
613
|
|
|
$this->cacheMock |
614
|
|
|
->expects($this->at(1)) |
615
|
|
|
->method('clear') |
616
|
|
|
->with('content', 'info', 'remoteId') |
617
|
|
|
->will($this->returnValue(true)); |
618
|
|
|
|
619
|
|
|
$this->cacheMock |
620
|
|
|
->expects($this->at(2)) |
621
|
|
|
->method('clear') |
622
|
|
|
->with('location', 'subtree') |
623
|
|
|
->will($this->returnValue(true)); |
624
|
|
|
|
625
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
626
|
|
|
$this->cacheMock |
627
|
|
|
->expects($this->at(3)) |
628
|
|
|
->method('getItem') |
629
|
|
|
->with('content', 2, 1, ContentHandler::ALL_TRANSLATIONS_KEY) |
630
|
|
|
->will($this->returnValue($cacheItemMock)); |
631
|
|
|
|
632
|
|
|
$cacheItemMock |
633
|
|
|
->expects($this->once()) |
634
|
|
|
->method('set') |
635
|
|
|
->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content')) |
636
|
|
|
->will($this->returnValue($cacheItemMock)); |
637
|
|
|
|
638
|
|
|
$cacheItemMock |
639
|
|
|
->expects($this->once()) |
640
|
|
|
->method('save') |
641
|
|
|
->with(); |
642
|
|
|
|
643
|
|
|
$cacheItemMock |
644
|
|
|
->expects($this->never()) |
645
|
|
|
->method('get'); |
646
|
|
|
|
647
|
|
|
$cacheItemMock2 = $this->getMock('Stash\Interfaces\ItemInterface'); |
648
|
|
|
$this->cacheMock |
649
|
|
|
->expects($this->at(4)) |
650
|
|
|
->method('getItem') |
651
|
|
|
->with('content', 'info', 2) |
652
|
|
|
->will($this->returnValue($cacheItemMock2)); |
653
|
|
|
|
654
|
|
|
$cacheItemMock2 |
655
|
|
|
->expects($this->once()) |
656
|
|
|
->method('set') |
657
|
|
|
->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\ContentInfo')) |
658
|
|
|
->will($this->returnValue($cacheItemMock2)); |
659
|
|
|
|
660
|
|
|
$cacheItemMock2 |
661
|
|
|
->expects($this->once()) |
662
|
|
|
->method('save') |
663
|
|
|
->with(); |
664
|
|
|
|
665
|
|
|
$cacheItemMock2 |
666
|
|
|
->expects($this->never()) |
667
|
|
|
->method('get'); |
668
|
|
|
|
669
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
670
|
|
|
$handler->publish(2, 1, new MetadataUpdateStruct()); |
671
|
|
|
} |
672
|
|
|
} |
673
|
|
|
|