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