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