1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the ObjectStateServiceTest 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\API\Repository\Tests; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroupCreateStruct; |
12
|
|
|
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroupUpdateStruct; |
13
|
|
|
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup; |
14
|
|
|
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateCreateStruct; |
15
|
|
|
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateUpdateStruct; |
16
|
|
|
use eZ\Publish\API\Repository\Values\ObjectState\ObjectState; |
17
|
|
|
use eZ\Publish\API\Repository\Exceptions\NotFoundException; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Test case for operations in the ObjectStateService using in memory storage. |
21
|
|
|
* |
22
|
|
|
* @see eZ\Publish\API\Repository\ObjectStateService |
23
|
|
|
* @group object-state |
24
|
|
|
*/ |
25
|
|
|
class ObjectStateServiceTest extends BaseTest |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* Test for the newObjectStateGroupCreateStruct() method. |
29
|
|
|
* |
30
|
|
|
* |
31
|
|
|
* @see \eZ\Publish\API\Repository\ObjectStateService::newObjectStateGroupCreateStruct() |
32
|
|
|
*/ |
33
|
|
|
public function testNewObjectStateGroupCreateStruct() |
34
|
|
|
{ |
35
|
|
|
$repository = $this->getRepository(); |
36
|
|
|
|
37
|
|
|
/* BEGIN: Use Case */ |
38
|
|
|
$objectStateService = $repository->getObjectStateService(); |
39
|
|
|
|
40
|
|
|
$objectStateGroupCreate = $objectStateService->newObjectStateGroupCreateStruct( |
41
|
|
|
'publishing' |
42
|
|
|
); |
43
|
|
|
/* END: Use Case */ |
44
|
|
|
|
45
|
|
|
$this->assertInstanceOf( |
46
|
|
|
'\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectStateGroupCreateStruct', |
47
|
|
|
$objectStateGroupCreate |
48
|
|
|
); |
49
|
|
|
|
50
|
|
|
return $objectStateGroupCreate; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* testNewObjectStateGroupCreateStructValues. |
55
|
|
|
* |
56
|
|
|
* @param \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroupCreateStruct $objectStateGroupCreate |
57
|
|
|
* |
58
|
|
|
* |
59
|
|
|
* @depends testNewObjectStateGroupCreateStruct |
60
|
|
|
*/ |
61
|
|
|
public function testNewObjectStateGroupCreateStructValues(ObjectStateGroupCreateStruct $objectStateGroupCreate) |
62
|
|
|
{ |
63
|
|
|
$this->assertPropertiesCorrect( |
64
|
|
|
array( |
65
|
|
|
'identifier' => 'publishing', |
66
|
|
|
'defaultLanguageCode' => null, |
67
|
|
|
'names' => null, |
68
|
|
|
'descriptions' => null, |
69
|
|
|
), |
70
|
|
|
$objectStateGroupCreate |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Test for the newObjectStateGroupUpdateStruct() method. |
76
|
|
|
* |
77
|
|
|
* |
78
|
|
|
* @see \eZ\Publish\API\Repository\ObjectStateService::newObjectStateGroupUpdateStruct() |
79
|
|
|
*/ |
80
|
|
|
public function testNewObjectStateGroupUpdateStruct() |
81
|
|
|
{ |
82
|
|
|
$repository = $this->getRepository(); |
83
|
|
|
|
84
|
|
|
/* BEGIN: Use Case */ |
85
|
|
|
$objectStateService = $repository->getObjectStateService(); |
86
|
|
|
|
87
|
|
|
$objectStateGroupUpdate = $objectStateService->newObjectStateGroupUpdateStruct(); |
88
|
|
|
/* END: Use Case */ |
89
|
|
|
|
90
|
|
|
$this->assertInstanceOf( |
91
|
|
|
'\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectStateGroupUpdateStruct', |
92
|
|
|
$objectStateGroupUpdate |
93
|
|
|
); |
94
|
|
|
|
95
|
|
|
return $objectStateGroupUpdate; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* testNewObjectStateGroupUpdateStructValues. |
100
|
|
|
* |
101
|
|
|
* @param \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroupUpdateStruct $objectStateGroupUpdate |
102
|
|
|
* |
103
|
|
|
* |
104
|
|
|
* @depends testNewObjectStateGroupUpdateStruct |
105
|
|
|
*/ |
106
|
|
|
public function testNewObjectStateGroupUpdateStructValues(ObjectStateGroupUpdateStruct $objectStateGroupUpdate) |
107
|
|
|
{ |
108
|
|
|
$this->assertPropertiesCorrect( |
109
|
|
|
array( |
110
|
|
|
'identifier' => null, |
111
|
|
|
'defaultLanguageCode' => null, |
112
|
|
|
'names' => null, |
113
|
|
|
'descriptions' => null, |
114
|
|
|
), |
115
|
|
|
$objectStateGroupUpdate |
116
|
|
|
); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Test for the newObjectStateCreateStruct() method. |
121
|
|
|
* |
122
|
|
|
* |
123
|
|
|
* @see \eZ\Publish\API\Repository\ObjectStateService::newObjectStateCreateStruct() |
124
|
|
|
*/ |
125
|
|
|
public function testNewObjectStateCreateStruct() |
126
|
|
|
{ |
127
|
|
|
$repository = $this->getRepository(); |
128
|
|
|
|
129
|
|
|
/* BEGIN: Use Case */ |
130
|
|
|
$objectStateService = $repository->getObjectStateService(); |
131
|
|
|
|
132
|
|
|
$objectStateCreate = $objectStateService->newObjectStateCreateStruct( |
133
|
|
|
'pending' |
134
|
|
|
); |
135
|
|
|
/* END: Use Case */ |
136
|
|
|
|
137
|
|
|
$this->assertInstanceOf( |
138
|
|
|
'\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectStateCreateStruct', |
139
|
|
|
$objectStateCreate |
140
|
|
|
); |
141
|
|
|
|
142
|
|
|
return $objectStateCreate; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* testNewObjectStateCreateStructValues. |
147
|
|
|
* |
148
|
|
|
* @param \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateCreateStruct $objectStateCreate |
149
|
|
|
* |
150
|
|
|
* |
151
|
|
|
* @depends testNewObjectStateCreateStruct |
152
|
|
|
*/ |
153
|
|
|
public function testNewObjectStateCreateStructValues(ObjectStateCreateStruct $objectStateCreate) |
154
|
|
|
{ |
155
|
|
|
$this->assertPropertiesCorrect( |
156
|
|
|
array( |
157
|
|
|
'identifier' => 'pending', |
158
|
|
|
'priority' => false, |
159
|
|
|
'defaultLanguageCode' => null, |
160
|
|
|
'names' => null, |
161
|
|
|
'descriptions' => null, |
162
|
|
|
), |
163
|
|
|
$objectStateCreate |
164
|
|
|
); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Test for the newObjectStateUpdateStruct() method. |
169
|
|
|
* |
170
|
|
|
* |
171
|
|
|
* @see \eZ\Publish\API\Repository\ObjectStateService::newObjectStateUpdateStruct() |
172
|
|
|
*/ |
173
|
|
|
public function testNewObjectStateUpdateStruct() |
174
|
|
|
{ |
175
|
|
|
$repository = $this->getRepository(); |
176
|
|
|
|
177
|
|
|
/* BEGIN: Use Case */ |
178
|
|
|
$objectStateService = $repository->getObjectStateService(); |
179
|
|
|
|
180
|
|
|
$objectStateUpdate = $objectStateService->newObjectStateUpdateStruct(); |
181
|
|
|
/* END: Use Case */ |
182
|
|
|
|
183
|
|
|
$this->assertInstanceOf( |
184
|
|
|
'\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectStateUpdateStruct', |
185
|
|
|
$objectStateUpdate |
186
|
|
|
); |
187
|
|
|
|
188
|
|
|
return $objectStateUpdate; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* testNewObjectStateUpdateStructValues. |
193
|
|
|
* |
194
|
|
|
* @param \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateUpdateStruct $objectStateUpdate |
195
|
|
|
* |
196
|
|
|
* |
197
|
|
|
* @depends testNewObjectStateUpdateStruct |
198
|
|
|
*/ |
199
|
|
|
public function testNewObjectStateUpdateStructValues(ObjectStateUpdateStruct $objectStateUpdate) |
200
|
|
|
{ |
201
|
|
|
$this->assertPropertiesCorrect( |
202
|
|
|
array( |
203
|
|
|
'identifier' => null, |
204
|
|
|
'defaultLanguageCode' => null, |
205
|
|
|
'names' => null, |
206
|
|
|
'descriptions' => null, |
207
|
|
|
), |
208
|
|
|
$objectStateUpdate |
209
|
|
|
); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* Test for the createObjectStateGroup() method. |
214
|
|
|
* |
215
|
|
|
* |
216
|
|
|
* @see \eZ\Publish\API\Repository\ObjectStateService::createObjectStateGroup() |
217
|
|
|
* @depends testNewObjectStateGroupCreateStructValues |
218
|
|
|
*/ |
219
|
|
|
public function testCreateObjectStateGroup() |
220
|
|
|
{ |
221
|
|
|
$repository = $this->getRepository(); |
222
|
|
|
|
223
|
|
|
/* BEGIN: Use Case */ |
224
|
|
|
$objectStateService = $repository->getObjectStateService(); |
225
|
|
|
|
226
|
|
|
$objectStateGroupCreate = $objectStateService->newObjectStateGroupCreateStruct( |
227
|
|
|
'publishing' |
228
|
|
|
); |
229
|
|
|
$objectStateGroupCreate->defaultLanguageCode = 'eng-US'; |
230
|
|
|
$objectStateGroupCreate->names = array( |
|
|
|
|
231
|
|
|
'eng-US' => 'Publishing', |
232
|
|
|
'eng-GB' => 'Sindelfingen', |
233
|
|
|
); |
234
|
|
|
$objectStateGroupCreate->descriptions = array( |
|
|
|
|
235
|
|
|
'eng-US' => 'Put something online', |
236
|
|
|
'eng-GB' => 'Put something ton Sindelfingen.', |
237
|
|
|
); |
238
|
|
|
|
239
|
|
|
$createdObjectStateGroup = $objectStateService->createObjectStateGroup( |
240
|
|
|
$objectStateGroupCreate |
241
|
|
|
); |
242
|
|
|
/* END: Use Case */ |
243
|
|
|
|
244
|
|
|
$this->assertInstanceOf( |
245
|
|
|
'\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectStateGroup', |
246
|
|
|
$createdObjectStateGroup |
247
|
|
|
); |
248
|
|
|
|
249
|
|
|
return $createdObjectStateGroup; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* testCreateObjectStateGroupStructValues. |
254
|
|
|
* |
255
|
|
|
* @param \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup $createdObjectStateGroup |
256
|
|
|
* |
257
|
|
|
* |
258
|
|
|
* @depends testCreateObjectStateGroup |
259
|
|
|
*/ |
260
|
|
|
public function testCreateObjectStateGroupStructValues(ObjectStateGroup $createdObjectStateGroup) |
261
|
|
|
{ |
262
|
|
|
$this->assertPropertiesCorrect( |
263
|
|
|
array( |
264
|
|
|
'identifier' => 'publishing', |
265
|
|
|
'defaultLanguageCode' => 'eng-US', |
266
|
|
|
'languageCodes' => array('eng-US', 'eng-GB'), |
267
|
|
|
'names' => array( |
268
|
|
|
'eng-US' => 'Publishing', |
269
|
|
|
'eng-GB' => 'Sindelfingen', |
270
|
|
|
), |
271
|
|
|
'descriptions' => array( |
272
|
|
|
'eng-US' => 'Put something online', |
273
|
|
|
'eng-GB' => 'Put something ton Sindelfingen.', |
274
|
|
|
), |
275
|
|
|
), |
276
|
|
|
$createdObjectStateGroup |
277
|
|
|
); |
278
|
|
|
$this->assertNotNull($createdObjectStateGroup->id); |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
/** |
282
|
|
|
* Test for the createObjectStateGroup() method. |
283
|
|
|
* |
284
|
|
|
* |
285
|
|
|
* @see \eZ\Publish\API\Repository\ObjectStateService::createObjectStateGroup() |
286
|
|
|
* @depends testCreateObjectStateGroup |
287
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
288
|
|
|
*/ |
289
|
|
|
public function testCreateObjectStateGroupThrowsInvalidArgumentException() |
290
|
|
|
{ |
291
|
|
|
$repository = $this->getRepository(); |
292
|
|
|
|
293
|
|
|
$objectStateService = $repository->getObjectStateService(); |
294
|
|
|
|
295
|
|
|
$objectStateGroupCreate = $objectStateService->newObjectStateGroupCreateStruct( |
296
|
|
|
// 'ez_lock' is already existing identifier |
297
|
|
|
'ez_lock' |
298
|
|
|
); |
299
|
|
|
$objectStateGroupCreate->defaultLanguageCode = 'eng-US'; |
300
|
|
|
$objectStateGroupCreate->names = array( |
|
|
|
|
301
|
|
|
'eng-US' => 'Publishing', |
302
|
|
|
'eng-GB' => 'Sindelfingen', |
303
|
|
|
); |
304
|
|
|
$objectStateGroupCreate->descriptions = array( |
|
|
|
|
305
|
|
|
'eng-US' => 'Put something online', |
306
|
|
|
'eng-GB' => 'Put something ton Sindelfingen.', |
307
|
|
|
); |
308
|
|
|
|
309
|
|
|
// This call will fail because group with 'ez_lock' identifier already exists |
310
|
|
|
$objectStateService->createObjectStateGroup( |
311
|
|
|
$objectStateGroupCreate |
312
|
|
|
); |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* Test for the loadObjectStateGroup() method. |
317
|
|
|
* |
318
|
|
|
* @covers \eZ\Publish\API\Repository\ObjectStateService::loadObjectStateGroup |
319
|
|
|
*/ |
320
|
|
|
public function testLoadObjectStateGroup() |
321
|
|
|
{ |
322
|
|
|
$repository = $this->getRepository(); |
323
|
|
|
|
324
|
|
|
$objectStateGroupId = $this->generateId('objectstategroup', 2); |
325
|
|
|
/* BEGIN: Use Case */ |
326
|
|
|
// $objectStateGroupId contains the ID of the standard object state |
327
|
|
|
// group ez_lock. |
328
|
|
|
$objectStateService = $repository->getObjectStateService(); |
329
|
|
|
|
330
|
|
|
$loadedObjectStateGroup = $objectStateService->loadObjectStateGroup( |
331
|
|
|
$objectStateGroupId |
332
|
|
|
); |
333
|
|
|
/* END: Use Case */ |
334
|
|
|
|
335
|
|
|
$this->assertInstanceOf( |
336
|
|
|
ObjectStateGroup::class, |
337
|
|
|
$loadedObjectStateGroup |
338
|
|
|
); |
339
|
|
|
|
340
|
|
|
$this->assertPropertiesCorrect( |
341
|
|
|
[ |
342
|
|
|
'id' => 2, |
343
|
|
|
'identifier' => 'ez_lock', |
344
|
|
|
'defaultLanguageCode' => 'eng-US', |
345
|
|
|
'languageCodes' => ['eng-US'], |
346
|
|
|
'names' => ['eng-US' => 'Lock'], |
347
|
|
|
'descriptions' => ['eng-US' => ''], |
348
|
|
|
], |
349
|
|
|
$loadedObjectStateGroup |
350
|
|
|
); |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
/** |
354
|
|
|
* Test for the loadObjectStateGroup() method. |
355
|
|
|
* |
356
|
|
|
* |
357
|
|
|
* @see \eZ\Publish\API\Repository\ObjectStateService::loadObjectStateGroup() |
358
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
359
|
|
|
* @depends testLoadObjectStateGroup |
360
|
|
|
*/ |
361
|
|
|
public function testLoadObjectStateGroupThrowsNotFoundException() |
362
|
|
|
{ |
363
|
|
|
$repository = $this->getRepository(); |
364
|
|
|
|
365
|
|
|
$nonExistentObjectStateGroupId = $this->generateId('objectstategroup', self::DB_INT_MAX); |
366
|
|
|
/* BEGIN: Use Case */ |
367
|
|
|
// $nonExistentObjectStateGroupId contains an ID for an object state |
368
|
|
|
// that does not exist |
369
|
|
|
$objectStateService = $repository->getObjectStateService(); |
370
|
|
|
|
371
|
|
|
// Throws a not found exception |
372
|
|
|
$loadedObjectStateGroup = $objectStateService->loadObjectStateGroup( |
|
|
|
|
373
|
|
|
$nonExistentObjectStateGroupId |
374
|
|
|
); |
375
|
|
|
/* END: Use Case */ |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
/** |
379
|
|
|
* Test for the loadObjectStateGroups() method. |
380
|
|
|
* |
381
|
|
|
* |
382
|
|
|
* @see \eZ\Publish\API\Repository\ObjectStateService::loadObjectStateGroups() |
383
|
|
|
* @depends testLoadObjectStateGroup |
384
|
|
|
*/ |
385
|
|
|
public function testLoadObjectStateGroups() |
386
|
|
|
{ |
387
|
|
|
$repository = $this->getRepository(); |
388
|
|
|
|
389
|
|
|
$expectedGroupIdentifiers = $this->getGroupIdentifierMap($this->createObjectStateGroups()); |
390
|
|
|
$expectedGroupIdentifiers['ez_lock'] = true; |
391
|
|
|
|
392
|
|
|
/* BEGIN: Use Case */ |
393
|
|
|
$objectStateService = $repository->getObjectStateService(); |
394
|
|
|
|
395
|
|
|
$loadedObjectStateGroups = $objectStateService->loadObjectStateGroups(); |
396
|
|
|
/* END: Use Case */ |
397
|
|
|
|
398
|
|
|
$this->assertInternalType('array', $loadedObjectStateGroups); |
399
|
|
|
|
400
|
|
|
$this->assertObjectsLoadedByIdentifiers( |
401
|
|
|
$expectedGroupIdentifiers, |
402
|
|
|
$loadedObjectStateGroups, |
403
|
|
|
'ObjectStateGroup' |
404
|
|
|
); |
405
|
|
|
} |
406
|
|
|
|
407
|
|
|
/** |
408
|
|
|
* Creates a set of object state groups and returns an array of all |
409
|
|
|
* existing group identifiers after creation. |
410
|
|
|
* |
411
|
|
|
* @return bool[] |
412
|
|
|
*/ |
413
|
|
|
protected function createObjectStateGroups() |
414
|
|
|
{ |
415
|
|
|
$repository = $this->getRepository(); |
416
|
|
|
$objectStateService = $repository->getObjectStateService(); |
417
|
|
|
|
418
|
|
|
$identifiersToCreate = array( |
419
|
|
|
'first', |
420
|
|
|
'second', |
421
|
|
|
'third', |
422
|
|
|
); |
423
|
|
|
|
424
|
|
|
$createdStateGroups = array(); |
425
|
|
|
|
426
|
|
|
$groupCreateStruct = $objectStateService->newObjectStateGroupCreateStruct('dummy'); |
427
|
|
|
|
428
|
|
|
$groupCreateStruct->defaultLanguageCode = 'eng-US'; |
429
|
|
|
$groupCreateStruct->names = array('eng-US' => 'Foo'); |
|
|
|
|
430
|
|
|
$groupCreateStruct->descriptions = array('eng-US' => 'Foo Bar'); |
|
|
|
|
431
|
|
|
|
432
|
|
|
foreach ($identifiersToCreate as $identifier) { |
433
|
|
|
$groupCreateStruct->identifier = $identifier; |
434
|
|
|
$createdStateGroups[] = $objectStateService->createObjectStateGroup($groupCreateStruct); |
435
|
|
|
} |
436
|
|
|
|
437
|
|
|
return $createdStateGroups; |
438
|
|
|
} |
439
|
|
|
|
440
|
|
|
/** |
441
|
|
|
* Assert object identifiers. |
442
|
|
|
* |
443
|
|
|
* @param array $expectedIdentifiers |
444
|
|
|
* @param array $loadedObjects |
445
|
|
|
* @param string $class |
446
|
|
|
*/ |
447
|
|
|
protected function assertObjectsLoadedByIdentifiers(array $expectedIdentifiers, array $loadedObjects, $class) |
448
|
|
|
{ |
449
|
|
|
foreach ($loadedObjects as $loadedObject) { |
450
|
|
|
if (!isset($expectedIdentifiers[$loadedObject->identifier])) { |
451
|
|
|
$this->fail( |
452
|
|
|
sprintf( |
453
|
|
|
'Loaded not expected %s with identifier "%s"', |
454
|
|
|
$class, |
455
|
|
|
$loadedObject->identifier |
456
|
|
|
) |
457
|
|
|
); |
458
|
|
|
} |
459
|
|
|
unset($expectedIdentifiers[$loadedObject->identifier]); |
460
|
|
|
} |
461
|
|
|
|
462
|
|
|
if (!empty($expectedIdentifiers)) { |
463
|
|
|
$this->fail( |
464
|
|
|
sprintf( |
465
|
|
|
'Expected %ss with identifiers "%s" not loaded.', |
466
|
|
|
$class, |
467
|
|
|
implode('", "', $expectedIdentifiers) |
468
|
|
|
) |
469
|
|
|
); |
470
|
|
|
} |
471
|
|
|
} |
472
|
|
|
|
473
|
|
|
/** |
474
|
|
|
* Test for the loadObjectStateGroups() method. |
475
|
|
|
* |
476
|
|
|
* |
477
|
|
|
* @see \eZ\Publish\API\Repository\ObjectStateService::loadObjectStateGroups($offset) |
478
|
|
|
* @depends testLoadObjectStateGroups |
479
|
|
|
*/ |
480
|
|
View Code Duplication |
public function testLoadObjectStateGroupsWithOffset() |
481
|
|
|
{ |
482
|
|
|
$repository = $this->getRepository(); |
483
|
|
|
$objectStateService = $repository->getObjectStateService(); |
484
|
|
|
|
485
|
|
|
$this->createObjectStateGroups(); |
486
|
|
|
|
487
|
|
|
$allObjectStateGroups = $objectStateService->loadObjectStateGroups(); |
488
|
|
|
|
489
|
|
|
$existingGroupIdentifiers = $this->getGroupIdentifierMap($allObjectStateGroups); |
490
|
|
|
|
491
|
|
|
/* BEGIN: Use Case */ |
492
|
|
|
$objectStateService = $repository->getObjectStateService(); |
493
|
|
|
|
494
|
|
|
$loadedObjectStateGroups = $objectStateService->loadObjectStateGroups(2); |
495
|
|
|
/* END: Use Case */ |
496
|
|
|
|
497
|
|
|
$this->assertInternalType('array', $loadedObjectStateGroups); |
498
|
|
|
|
499
|
|
|
$this->assertObjectsLoadedByIdentifiers( |
500
|
|
|
array_slice($existingGroupIdentifiers, 2), |
501
|
|
|
$loadedObjectStateGroups, |
502
|
|
|
'ObjectStateGroup' |
503
|
|
|
); |
504
|
|
|
} |
505
|
|
|
|
506
|
|
|
/** |
507
|
|
|
* Returns a map of the given object state groups. |
508
|
|
|
* |
509
|
|
|
* @param array $groups |
510
|
|
|
* @return array |
511
|
|
|
*/ |
512
|
|
|
protected function getGroupIdentifierMap(array $groups) |
513
|
|
|
{ |
514
|
|
|
$existingGroupIdentifiers = array_map( |
515
|
|
|
function ($group) { |
516
|
|
|
return $group->identifier; |
517
|
|
|
}, |
518
|
|
|
$groups |
519
|
|
|
); |
520
|
|
|
|
521
|
|
|
return array_fill_keys($existingGroupIdentifiers, true); |
522
|
|
|
} |
523
|
|
|
|
524
|
|
|
/** |
525
|
|
|
* Test for the loadObjectStateGroups() method. |
526
|
|
|
* |
527
|
|
|
* |
528
|
|
|
* @see \eZ\Publish\API\Repository\ObjectStateService::loadObjectStateGroups($offset, $limit) |
529
|
|
|
* @depends testLoadObjectStateGroupsWithOffset |
530
|
|
|
*/ |
531
|
|
View Code Duplication |
public function testLoadObjectStateGroupsWithOffsetAndLimit() |
532
|
|
|
{ |
533
|
|
|
$repository = $this->getRepository(); |
534
|
|
|
$objectStateService = $repository->getObjectStateService(); |
535
|
|
|
|
536
|
|
|
$allObjectStateGroups = $objectStateService->loadObjectStateGroups(); |
537
|
|
|
|
538
|
|
|
$existingGroupIdentifiers = $this->getGroupIdentifierMap($allObjectStateGroups); |
539
|
|
|
|
540
|
|
|
/* BEGIN: Use Case */ |
541
|
|
|
$objectStateService = $repository->getObjectStateService(); |
542
|
|
|
|
543
|
|
|
$loadedObjectStateGroups = $objectStateService->loadObjectStateGroups(1, 2); |
544
|
|
|
/* END: Use Case */ |
545
|
|
|
|
546
|
|
|
$this->assertInternalType('array', $loadedObjectStateGroups); |
547
|
|
|
|
548
|
|
|
$this->assertObjectsLoadedByIdentifiers( |
549
|
|
|
array_slice($existingGroupIdentifiers, 1, 2), |
550
|
|
|
$loadedObjectStateGroups, |
551
|
|
|
'ObjectStateGroup' |
552
|
|
|
); |
553
|
|
|
} |
554
|
|
|
|
555
|
|
|
/** |
556
|
|
|
* Test for the loadObjectStates() method. |
557
|
|
|
* |
558
|
|
|
* |
559
|
|
|
* @see \eZ\Publish\API\Repository\ObjectStateService::loadObjectStates() |
560
|
|
|
* @depends testLoadObjectStateGroup |
561
|
|
|
*/ |
562
|
|
|
public function testLoadObjectStates() |
563
|
|
|
{ |
564
|
|
|
$repository = $this->getRepository(); |
565
|
|
|
|
566
|
|
|
$objectStateGroupId = $this->generateId('objectstategroup', 2); |
567
|
|
|
/* BEGIN: Use Case */ |
568
|
|
|
// $objectStateGroupId contains the ID of the standard object state |
569
|
|
|
// group ez_lock. |
570
|
|
|
$objectStateService = $repository->getObjectStateService(); |
571
|
|
|
|
572
|
|
|
$objectStateGroup = $objectStateService->loadObjectStateGroup( |
573
|
|
|
$objectStateGroupId |
574
|
|
|
); |
575
|
|
|
|
576
|
|
|
// Loads all object states in $objectStateGroup |
577
|
|
|
$loadedObjectStates = $objectStateService->loadObjectStates($objectStateGroup); |
578
|
|
|
/* END: Use Case */ |
579
|
|
|
|
580
|
|
|
$this->assertInternalType( |
581
|
|
|
'array', |
582
|
|
|
$loadedObjectStates |
583
|
|
|
); |
584
|
|
|
$this->assertObjectsLoadedByIdentifiers( |
585
|
|
|
array('not_locked' => true, 'locked' => true), |
586
|
|
|
$loadedObjectStates, |
587
|
|
|
'ObjectState' |
588
|
|
|
); |
589
|
|
|
} |
590
|
|
|
|
591
|
|
|
/** |
592
|
|
|
* Test for the updateObjectStateGroup() method. |
593
|
|
|
* |
594
|
|
|
* @covers \eZ\Publish\API\Repository\ObjectStateService::updateObjectStateGroup |
595
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ObjectStateServiceTest::testLoadObjectStateGroup |
596
|
|
|
*/ |
597
|
|
View Code Duplication |
public function testUpdateObjectStateGroup() |
598
|
|
|
{ |
599
|
|
|
$repository = $this->getRepository(); |
600
|
|
|
|
601
|
|
|
$objectStateGroupId = $this->generateId('objectstategroup', 2); |
602
|
|
|
/* BEGIN: Use Case */ |
603
|
|
|
// $objectStateGroupId contains the ID of the standard object state |
604
|
|
|
// group ez_lock. |
605
|
|
|
$objectStateService = $repository->getObjectStateService(); |
606
|
|
|
|
607
|
|
|
$loadedObjectStateGroup = $objectStateService->loadObjectStateGroup( |
608
|
|
|
$objectStateGroupId |
609
|
|
|
); |
610
|
|
|
|
611
|
|
|
$groupUpdateStruct = $objectStateService->newObjectStateGroupUpdateStruct(); |
612
|
|
|
$groupUpdateStruct->identifier = 'sindelfingen'; |
613
|
|
|
$groupUpdateStruct->defaultLanguageCode = 'ger-DE'; |
614
|
|
|
$groupUpdateStruct->names = array( |
|
|
|
|
615
|
|
|
'ger-DE' => 'Sindelfingen', |
616
|
|
|
); |
617
|
|
|
$groupUpdateStruct->descriptions = array( |
|
|
|
|
618
|
|
|
'ger-DE' => 'Sindelfingen ist nicht nur eine Stadt', |
619
|
|
|
); |
620
|
|
|
|
621
|
|
|
// Updates the $loadObjectStateGroup with the data from |
622
|
|
|
// $groupUpdateStruct and returns the updated group |
623
|
|
|
$updatedObjectStateGroup = $objectStateService->updateObjectStateGroup( |
624
|
|
|
$loadedObjectStateGroup, |
625
|
|
|
$groupUpdateStruct |
626
|
|
|
); |
627
|
|
|
/* END: Use Case */ |
628
|
|
|
|
629
|
|
|
$this->assertInstanceOf( |
630
|
|
|
'\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectStateGroup', |
631
|
|
|
$updatedObjectStateGroup |
632
|
|
|
); |
633
|
|
|
|
634
|
|
|
return array( |
635
|
|
|
$loadedObjectStateGroup, |
636
|
|
|
$groupUpdateStruct, |
637
|
|
|
$updatedObjectStateGroup, |
638
|
|
|
); |
639
|
|
|
} |
640
|
|
|
|
641
|
|
|
/** |
642
|
|
|
* Test service method for partially updating object state group. |
643
|
|
|
* |
644
|
|
|
* @covers \eZ\Publish\API\Repository\ObjectStateService::updateObjectStateGroup |
645
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ObjectStateServiceTest::testLoadObjectStateGroup |
646
|
|
|
*/ |
647
|
|
|
public function testUpdateObjectStateGroupChosenFieldsOnly() |
648
|
|
|
{ |
649
|
|
|
$repository = $this->getRepository(); |
650
|
|
|
$objectStateService = $repository->getObjectStateService(); |
651
|
|
|
|
652
|
|
|
$groupUpdateStruct = $objectStateService->newObjectStateGroupUpdateStruct(); |
653
|
|
|
$groupUpdateStruct->defaultLanguageCode = 'eng-GB'; |
654
|
|
|
$groupUpdateStruct->names = ['eng-GB' => 'Test']; |
|
|
|
|
655
|
|
|
|
656
|
|
|
$group = $objectStateService->loadObjectStateGroup(2); |
657
|
|
|
|
658
|
|
|
$updatedGroup = $objectStateService->updateObjectStateGroup($group, $groupUpdateStruct); |
659
|
|
|
|
660
|
|
|
$this->assertInstanceOf( |
661
|
|
|
ObjectStateGroup::class, |
662
|
|
|
$updatedGroup |
663
|
|
|
); |
664
|
|
|
|
665
|
|
|
$this->assertPropertiesCorrect( |
666
|
|
|
[ |
667
|
|
|
'id' => 2, |
668
|
|
|
'identifier' => 'ez_lock', |
669
|
|
|
'defaultLanguageCode' => 'eng-GB', |
670
|
|
|
'languageCodes' => ['eng-GB'], |
671
|
|
|
'names' => ['eng-GB' => 'Test'], |
672
|
|
|
// descriptions array should have an empty value for eng-GB |
673
|
|
|
// without the original descriptions |
674
|
|
|
// since the descriptions were not in the update struct and we're changing default language |
675
|
|
|
'descriptions' => ['eng-GB' => ''], |
676
|
|
|
], |
677
|
|
|
$updatedGroup |
678
|
|
|
); |
679
|
|
|
} |
680
|
|
|
|
681
|
|
|
/** |
682
|
|
|
* Test for the updateObjectStateGroup() method. |
683
|
|
|
* |
684
|
|
|
* |
685
|
|
|
* @see \eZ\Publish\API\Repository\ObjectStateService::updateObjectStateGroup() |
686
|
|
|
* @depends testUpdateObjectStateGroup |
687
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
688
|
|
|
*/ |
689
|
|
|
public function testUpdateObjectStateGroupThrowsInvalidArgumentException() |
690
|
|
|
{ |
691
|
|
|
$repository = $this->getRepository(); |
692
|
|
|
|
693
|
|
|
$objectStateService = $repository->getObjectStateService(); |
694
|
|
|
|
695
|
|
|
// Create object state group which we will later update |
696
|
|
|
$objectStateGroupCreate = $objectStateService->newObjectStateGroupCreateStruct( |
697
|
|
|
'publishing' |
698
|
|
|
); |
699
|
|
|
$objectStateGroupCreate->defaultLanguageCode = 'eng-US'; |
700
|
|
|
$objectStateGroupCreate->names = array( |
|
|
|
|
701
|
|
|
'eng-US' => 'Publishing', |
702
|
|
|
'eng-GB' => 'Sindelfingen', |
703
|
|
|
); |
704
|
|
|
$objectStateGroupCreate->descriptions = array( |
|
|
|
|
705
|
|
|
'eng-US' => 'Put something online', |
706
|
|
|
'eng-GB' => 'Put something ton Sindelfingen.', |
707
|
|
|
); |
708
|
|
|
|
709
|
|
|
$createdObjectStateGroup = $objectStateService->createObjectStateGroup( |
710
|
|
|
$objectStateGroupCreate |
711
|
|
|
); |
712
|
|
|
|
713
|
|
|
$groupUpdateStruct = $objectStateService->newObjectStateGroupUpdateStruct(); |
714
|
|
|
// 'ez_lock' is the identifier of already existing group |
715
|
|
|
$groupUpdateStruct->identifier = 'ez_lock'; |
716
|
|
|
$groupUpdateStruct->defaultLanguageCode = 'ger-DE'; |
717
|
|
|
$groupUpdateStruct->names = array( |
|
|
|
|
718
|
|
|
'ger-DE' => 'Sindelfingen', |
719
|
|
|
); |
720
|
|
|
$groupUpdateStruct->descriptions = array( |
|
|
|
|
721
|
|
|
'ger-DE' => 'Sindelfingen ist nicht nur eine Stadt', |
722
|
|
|
); |
723
|
|
|
|
724
|
|
|
// This call will fail since state group with 'ez_lock' identifier already exists |
725
|
|
|
$objectStateService->updateObjectStateGroup( |
726
|
|
|
$createdObjectStateGroup, |
727
|
|
|
$groupUpdateStruct |
728
|
|
|
); |
729
|
|
|
} |
730
|
|
|
|
731
|
|
|
/** |
732
|
|
|
* testUpdateObjectStateGroupStructValues. |
733
|
|
|
* |
734
|
|
|
* @param array $testData |
735
|
|
|
* |
736
|
|
|
* |
737
|
|
|
* @depends testUpdateObjectStateGroup |
738
|
|
|
*/ |
739
|
|
|
public function testUpdateObjectStateGroupStructValues(array $testData) |
740
|
|
|
{ |
741
|
|
|
list( |
742
|
|
|
$loadedObjectStateGroup, |
|
|
|
|
743
|
|
|
$groupUpdateStruct, |
744
|
|
|
$updatedObjectStateGroup |
745
|
|
|
) = $testData; |
746
|
|
|
|
747
|
|
|
$this->assertStructPropertiesCorrect( |
748
|
|
|
$groupUpdateStruct, |
749
|
|
|
$updatedObjectStateGroup |
750
|
|
|
); |
751
|
|
|
} |
752
|
|
|
|
753
|
|
|
/** |
754
|
|
|
* Test for the createObjectState() method. |
755
|
|
|
* |
756
|
|
|
* |
757
|
|
|
* @see \eZ\Publish\API\Repository\ObjectStateService::createObjectState() |
758
|
|
|
* @depends testLoadObjectStateGroup |
759
|
|
|
* @depends testNewObjectStateCreateStruct |
760
|
|
|
*/ |
761
|
|
View Code Duplication |
public function testCreateObjectState() |
762
|
|
|
{ |
763
|
|
|
$repository = $this->getRepository(); |
764
|
|
|
|
765
|
|
|
$objectStateGroupId = $this->generateId('objectstategroup', 2); |
766
|
|
|
/* BEGIN: Use Case */ |
767
|
|
|
// $objectStateGroupId contains the ID of the standard object state |
768
|
|
|
// group ez_lock. |
769
|
|
|
$objectStateService = $repository->getObjectStateService(); |
770
|
|
|
|
771
|
|
|
$loadedObjectStateGroup = $objectStateService->loadObjectStateGroup( |
772
|
|
|
$objectStateGroupId |
773
|
|
|
); |
774
|
|
|
|
775
|
|
|
$objectStateCreateStruct = $objectStateService->newObjectStateCreateStruct( |
776
|
|
|
'locked_and_unlocked' |
777
|
|
|
); |
778
|
|
|
$objectStateCreateStruct->priority = 23; |
779
|
|
|
$objectStateCreateStruct->defaultLanguageCode = 'eng-US'; |
780
|
|
|
$objectStateCreateStruct->names = array( |
|
|
|
|
781
|
|
|
'eng-US' => 'Locked and Unlocked', |
782
|
|
|
); |
783
|
|
|
$objectStateCreateStruct->descriptions = array( |
|
|
|
|
784
|
|
|
'eng-US' => 'A state between locked and unlocked.', |
785
|
|
|
); |
786
|
|
|
|
787
|
|
|
// Creates a new object state in the $loadObjectStateGroup with the |
788
|
|
|
// data from $objectStateCreateStruct |
789
|
|
|
$createdObjectState = $objectStateService->createObjectState( |
790
|
|
|
$loadedObjectStateGroup, |
791
|
|
|
$objectStateCreateStruct |
792
|
|
|
); |
793
|
|
|
/* END: Use Case */ |
794
|
|
|
|
795
|
|
|
$this->assertInstanceOf( |
796
|
|
|
'\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectState', |
797
|
|
|
$createdObjectState |
798
|
|
|
); |
799
|
|
|
// Object sequences are renumbered |
800
|
|
|
$objectStateCreateStruct->priority = 2; |
801
|
|
|
|
802
|
|
|
return array( |
803
|
|
|
$loadedObjectStateGroup, |
804
|
|
|
$objectStateCreateStruct, |
805
|
|
|
$createdObjectState, |
806
|
|
|
); |
807
|
|
|
} |
808
|
|
|
|
809
|
|
|
/** |
810
|
|
|
* Test service method for creating object state in empty group. |
811
|
|
|
* |
812
|
|
|
* @covers \eZ\Publish\API\Repository\ObjectStateService::createObjectState |
813
|
|
|
*/ |
814
|
|
|
public function testCreateObjectStateInEmptyGroup() |
815
|
|
|
{ |
816
|
|
|
$repository = $this->getRepository(); |
817
|
|
|
$objectStateService = $repository->getObjectStateService(); |
818
|
|
|
|
819
|
|
|
$groupCreateStruct = $objectStateService->newObjectStateGroupCreateStruct('test'); |
820
|
|
|
$groupCreateStruct->defaultLanguageCode = 'eng-GB'; |
821
|
|
|
$groupCreateStruct->names = ['eng-GB' => 'Test']; |
|
|
|
|
822
|
|
|
$groupCreateStruct->descriptions = ['eng-GB' => 'Test description']; |
|
|
|
|
823
|
|
|
|
824
|
|
|
$createdGroup = $objectStateService->createObjectStateGroup($groupCreateStruct); |
825
|
|
|
|
826
|
|
|
$stateCreateStruct = $objectStateService->newObjectStateCreateStruct('test'); |
827
|
|
|
$stateCreateStruct->priority = 2; |
828
|
|
|
$stateCreateStruct->defaultLanguageCode = 'eng-GB'; |
829
|
|
|
$stateCreateStruct->names = ['eng-GB' => 'Test']; |
830
|
|
|
$stateCreateStruct->descriptions = ['eng-GB' => 'Test description']; |
831
|
|
|
|
832
|
|
|
$createdState = $objectStateService->createObjectState( |
833
|
|
|
$createdGroup, |
834
|
|
|
$stateCreateStruct |
835
|
|
|
); |
836
|
|
|
|
837
|
|
|
$this->assertInstanceOf( |
838
|
|
|
ObjectState::class, |
839
|
|
|
$createdState |
840
|
|
|
); |
841
|
|
|
|
842
|
|
|
$this->assertNotNull($createdState->id); |
843
|
|
|
$this->assertPropertiesCorrect( |
844
|
|
|
[ |
845
|
|
|
'identifier' => 'test', |
846
|
|
|
'priority' => 0, |
847
|
|
|
'defaultLanguageCode' => 'eng-GB', |
848
|
|
|
'languageCodes' => ['eng-GB'], |
849
|
|
|
'names' => ['eng-GB' => 'Test'], |
850
|
|
|
'descriptions' => ['eng-GB' => 'Test description'], |
851
|
|
|
], |
852
|
|
|
$createdState |
853
|
|
|
); |
854
|
|
|
|
855
|
|
|
$objectStateGroup = $createdState->getObjectStateGroup(); |
856
|
|
|
$this->assertInstanceOf( |
857
|
|
|
ObjectStateGroup::class, |
858
|
|
|
$objectStateGroup |
859
|
|
|
); |
860
|
|
|
|
861
|
|
|
$this->assertEquals($createdGroup->id, $objectStateGroup->id); |
862
|
|
|
$this->assertGreaterThan(0, $objectStateService->getContentCount($createdState)); |
863
|
|
|
} |
864
|
|
|
|
865
|
|
|
/** |
866
|
|
|
* Test for the createObjectState() method. |
867
|
|
|
* |
868
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
869
|
|
|
* |
870
|
|
|
* @see \eZ\Publish\API\Repository\ObjectStateService::createObjectState() |
871
|
|
|
* @depends testLoadObjectStateGroup |
872
|
|
|
* @depends testCreateObjectState |
873
|
|
|
*/ |
874
|
|
|
public function testCreateObjectStateThrowsInvalidArgumentException() |
875
|
|
|
{ |
876
|
|
|
$repository = $this->getRepository(); |
877
|
|
|
|
878
|
|
|
$objectStateGroupId = $this->generateId('objectstategroup', 2); |
879
|
|
|
// $objectStateGroupId contains the ID of the standard object state |
880
|
|
|
// group ez_lock. |
881
|
|
|
$objectStateService = $repository->getObjectStateService(); |
882
|
|
|
|
883
|
|
|
$loadedObjectStateGroup = $objectStateService->loadObjectStateGroup( |
884
|
|
|
$objectStateGroupId |
885
|
|
|
); |
886
|
|
|
|
887
|
|
|
$objectStateCreateStruct = $objectStateService->newObjectStateCreateStruct( |
888
|
|
|
// 'not_locked' is the identifier of already existing state |
889
|
|
|
'not_locked' |
890
|
|
|
); |
891
|
|
|
$objectStateCreateStruct->priority = 23; |
892
|
|
|
$objectStateCreateStruct->defaultLanguageCode = 'eng-US'; |
893
|
|
|
$objectStateCreateStruct->names = array( |
|
|
|
|
894
|
|
|
'eng-US' => 'Locked and Unlocked', |
895
|
|
|
); |
896
|
|
|
$objectStateCreateStruct->descriptions = array( |
|
|
|
|
897
|
|
|
'eng-US' => 'A state between locked and unlocked.', |
898
|
|
|
); |
899
|
|
|
|
900
|
|
|
// This call will fail because object state with |
901
|
|
|
// 'not_locked' identifier already exists |
902
|
|
|
$objectStateService->createObjectState( |
903
|
|
|
$loadedObjectStateGroup, |
904
|
|
|
$objectStateCreateStruct |
905
|
|
|
); |
906
|
|
|
} |
907
|
|
|
|
908
|
|
|
/** |
909
|
|
|
* testCreateObjectStateStructValues. |
910
|
|
|
* |
911
|
|
|
* @param array $testData |
912
|
|
|
* |
913
|
|
|
* |
914
|
|
|
* @depends testCreateObjectState |
915
|
|
|
*/ |
916
|
|
|
public function testCreateObjectStateStructValues(array $testData) |
917
|
|
|
{ |
918
|
|
|
list( |
919
|
|
|
$loadedObjectStateGroup, |
920
|
|
|
$objectStateCreateStruct, |
921
|
|
|
$createdObjectState |
922
|
|
|
) = $testData; |
923
|
|
|
|
924
|
|
|
$this->assertStructPropertiesCorrect( |
925
|
|
|
$objectStateCreateStruct, |
926
|
|
|
$createdObjectState |
927
|
|
|
); |
928
|
|
|
|
929
|
|
|
$this->assertNotNull($createdObjectState->id); |
930
|
|
|
|
931
|
|
|
$this->assertEquals( |
932
|
|
|
$loadedObjectStateGroup, |
933
|
|
|
$createdObjectState->getObjectStateGroup() |
934
|
|
|
); |
935
|
|
|
} |
936
|
|
|
|
937
|
|
|
/** |
938
|
|
|
* Test for the loadObjectState() method. |
939
|
|
|
* |
940
|
|
|
* |
941
|
|
|
* @see \eZ\Publish\API\Repository\ObjectStateService::loadObjectState() |
942
|
|
|
* @depends testLoadObjectStateGroup |
943
|
|
|
*/ |
944
|
|
View Code Duplication |
public function testLoadObjectState() |
945
|
|
|
{ |
946
|
|
|
$repository = $this->getRepository(); |
947
|
|
|
|
948
|
|
|
$objectStateId = $this->generateId('objectstate', 2); |
949
|
|
|
/* BEGIN: Use Case */ |
950
|
|
|
// $objectStateId contains the ID of the "locked" state |
951
|
|
|
$objectStateService = $repository->getObjectStateService(); |
952
|
|
|
|
953
|
|
|
$loadedObjectState = $objectStateService->loadObjectState( |
954
|
|
|
$objectStateId |
955
|
|
|
); |
956
|
|
|
/* END: Use Case */ |
957
|
|
|
|
958
|
|
|
$this->assertInstanceOf( |
959
|
|
|
'eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectState', |
960
|
|
|
$loadedObjectState |
961
|
|
|
); |
962
|
|
|
|
963
|
|
|
return $loadedObjectState; |
964
|
|
|
} |
965
|
|
|
|
966
|
|
|
/** |
967
|
|
|
* testLoadObjectStateStructValues. |
968
|
|
|
* |
969
|
|
|
* @param \eZ\Publish\API\Repository\Values\ObjectState\ObjectState $loadedObjectState |
970
|
|
|
* |
971
|
|
|
* |
972
|
|
|
* @depends testLoadObjectState |
973
|
|
|
*/ |
974
|
|
|
public function testLoadObjectStateStructValues(ObjectState $loadedObjectState) |
975
|
|
|
{ |
976
|
|
|
$this->assertPropertiesCorrect( |
977
|
|
|
array( |
978
|
|
|
'id' => 2, |
979
|
|
|
'identifier' => 'locked', |
980
|
|
|
'priority' => 1, |
981
|
|
|
'defaultLanguageCode' => 'eng-US', |
982
|
|
|
'languageCodes' => array(0 => 'eng-US'), |
983
|
|
|
'names' => array('eng-US' => 'Locked'), |
984
|
|
|
'descriptions' => array('eng-US' => ''), |
985
|
|
|
), |
986
|
|
|
$loadedObjectState |
987
|
|
|
); |
988
|
|
|
|
989
|
|
|
$this->assertEquals( |
990
|
|
|
$this->getRepository()->getObjectStateService()->loadObjectStateGroup(2), |
991
|
|
|
$loadedObjectState->getObjectStateGroup() |
992
|
|
|
); |
993
|
|
|
} |
994
|
|
|
|
995
|
|
|
/** |
996
|
|
|
* Test for the loadObjectState() method. |
997
|
|
|
* |
998
|
|
|
* |
999
|
|
|
* @see \eZ\Publish\API\Repository\ObjectStateService::loadObjectState() |
1000
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
1001
|
|
|
* @depends testLoadObjectState |
1002
|
|
|
*/ |
1003
|
|
|
public function testLoadObjectStateThrowsNotFoundException() |
1004
|
|
|
{ |
1005
|
|
|
$repository = $this->getRepository(); |
1006
|
|
|
|
1007
|
|
|
$nonExistingObjectStateId = $this->generateId('objectstate', self::DB_INT_MAX); |
1008
|
|
|
/* BEGIN: Use Case */ |
1009
|
|
|
// $nonExistingObjectStateId contains the ID of a non existing state |
1010
|
|
|
$objectStateService = $repository->getObjectStateService(); |
1011
|
|
|
|
1012
|
|
|
// Throws not found exception |
1013
|
|
|
$loadedObjectState = $objectStateService->loadObjectState( |
|
|
|
|
1014
|
|
|
$nonExistingObjectStateId |
1015
|
|
|
); |
1016
|
|
|
/* END: Use Case */ |
1017
|
|
|
} |
1018
|
|
|
|
1019
|
|
|
/** |
1020
|
|
|
* Test for the updateObjectState() method. |
1021
|
|
|
* |
1022
|
|
|
* @covers \eZ\Publish\API\Repository\ObjectStateService::updateObjectState |
1023
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ObjectStateServiceTest::testLoadObjectState |
1024
|
|
|
*/ |
1025
|
|
|
public function testUpdateObjectState() |
1026
|
|
|
{ |
1027
|
|
|
$repository = $this->getRepository(); |
1028
|
|
|
|
1029
|
|
|
$objectStateId = $this->generateId('objectstate', 2); |
1030
|
|
|
/* BEGIN: Use Case */ |
1031
|
|
|
// $objectStateId contains the ID of the "locked" state |
1032
|
|
|
$objectStateService = $repository->getObjectStateService(); |
1033
|
|
|
|
1034
|
|
|
$loadedObjectState = $objectStateService->loadObjectState( |
1035
|
|
|
$objectStateId |
1036
|
|
|
); |
1037
|
|
|
|
1038
|
|
|
$updateStateStruct = $objectStateService->newObjectStateUpdateStruct(); |
1039
|
|
|
$updateStateStruct->identifier = 'somehow_locked'; |
1040
|
|
|
$updateStateStruct->defaultLanguageCode = 'ger-DE'; |
1041
|
|
|
$updateStateStruct->names = array( |
|
|
|
|
1042
|
|
|
'eng-US' => 'Somehow locked', |
1043
|
|
|
'ger-DE' => 'Irgendwie gelockt', |
1044
|
|
|
); |
1045
|
|
|
$updateStateStruct->descriptions = array( |
|
|
|
|
1046
|
|
|
'eng-US' => 'The object is somehow locked', |
1047
|
|
|
'ger-DE' => 'Sindelfingen', |
1048
|
|
|
); |
1049
|
|
|
|
1050
|
|
|
$updatedObjectState = $objectStateService->updateObjectState( |
1051
|
|
|
$loadedObjectState, |
1052
|
|
|
$updateStateStruct |
1053
|
|
|
); |
1054
|
|
|
/* END: Use Case */ |
1055
|
|
|
|
1056
|
|
|
$this->assertInstanceOf( |
1057
|
|
|
ObjectState::class, |
1058
|
|
|
$updatedObjectState |
1059
|
|
|
); |
1060
|
|
|
|
1061
|
|
|
return array( |
1062
|
|
|
$loadedObjectState, |
1063
|
|
|
$updateStateStruct, |
1064
|
|
|
$updatedObjectState, |
1065
|
|
|
); |
1066
|
|
|
} |
1067
|
|
|
|
1068
|
|
|
/** |
1069
|
|
|
* Test service method for partially updating object state. |
1070
|
|
|
* |
1071
|
|
|
* @covers \eZ\Publish\API\Repository\ObjectStateService::updateObjectState |
1072
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ObjectStateServiceTest::testLoadObjectState |
1073
|
|
|
*/ |
1074
|
|
|
public function testUpdateObjectStateChosenFieldsOnly() |
1075
|
|
|
{ |
1076
|
|
|
$repository = $this->getRepository(); |
1077
|
|
|
$objectStateService = $repository->getObjectStateService(); |
1078
|
|
|
|
1079
|
|
|
$stateUpdateStruct = $objectStateService->newObjectStateUpdateStruct(); |
1080
|
|
|
$stateUpdateStruct->identifier = 'test'; |
1081
|
|
|
$stateUpdateStruct->names = ['eng-US' => 'Test']; |
|
|
|
|
1082
|
|
|
|
1083
|
|
|
$state = $objectStateService->loadObjectState(1); |
1084
|
|
|
|
1085
|
|
|
$updatedState = $objectStateService->updateObjectState($state, $stateUpdateStruct); |
1086
|
|
|
|
1087
|
|
|
$this->assertInstanceOf( |
1088
|
|
|
ObjectState::class, |
1089
|
|
|
$updatedState |
1090
|
|
|
); |
1091
|
|
|
|
1092
|
|
|
$this->assertPropertiesCorrect( |
1093
|
|
|
[ |
1094
|
|
|
'id' => 1, |
1095
|
|
|
'identifier' => 'test', |
1096
|
|
|
'priority' => 0, |
1097
|
|
|
'defaultLanguageCode' => 'eng-US', |
1098
|
|
|
'languageCodes' => ['eng-US'], |
1099
|
|
|
'names' => ['eng-US' => 'Test'], |
1100
|
|
|
// Original value of empty description for eng-US should be kept |
1101
|
|
|
'descriptions' => ['eng-US' => ''], |
1102
|
|
|
], |
1103
|
|
|
$updatedState |
1104
|
|
|
); |
1105
|
|
|
|
1106
|
|
|
$this->assertInstanceOf( |
1107
|
|
|
ObjectStateGroup::class, |
1108
|
|
|
$updatedState->getObjectStateGroup() |
1109
|
|
|
); |
1110
|
|
|
|
1111
|
|
|
$this->assertEquals($state->getObjectStateGroup()->id, $updatedState->getObjectStateGroup()->id); |
1112
|
|
|
} |
1113
|
|
|
|
1114
|
|
|
/** |
1115
|
|
|
* Test for the updateObjectState() method. |
1116
|
|
|
* |
1117
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
1118
|
|
|
* |
1119
|
|
|
* @see \eZ\Publish\API\Repository\ObjectStateService::updateObjectState() |
1120
|
|
|
* @depends testUpdateObjectState |
1121
|
|
|
*/ |
1122
|
|
View Code Duplication |
public function testUpdateObjectStateThrowsInvalidArgumentException() |
1123
|
|
|
{ |
1124
|
|
|
$repository = $this->getRepository(); |
1125
|
|
|
|
1126
|
|
|
$objectStateId = $this->generateId('objectstate', 2); |
1127
|
|
|
// $objectStateId contains the ID of the "locked" state |
1128
|
|
|
$objectStateService = $repository->getObjectStateService(); |
1129
|
|
|
|
1130
|
|
|
$loadedObjectState = $objectStateService->loadObjectState( |
1131
|
|
|
$objectStateId |
1132
|
|
|
); |
1133
|
|
|
|
1134
|
|
|
$updateStateStruct = $objectStateService->newObjectStateUpdateStruct(); |
1135
|
|
|
// 'not_locked' is the identifier of already existing state |
1136
|
|
|
$updateStateStruct->identifier = 'not_locked'; |
1137
|
|
|
$updateStateStruct->defaultLanguageCode = 'ger-DE'; |
1138
|
|
|
$updateStateStruct->names = array( |
|
|
|
|
1139
|
|
|
'eng-US' => 'Somehow locked', |
1140
|
|
|
'ger-DE' => 'Irgendwie gelockt', |
1141
|
|
|
); |
1142
|
|
|
$updateStateStruct->descriptions = array( |
|
|
|
|
1143
|
|
|
'eng-US' => 'The object is somehow locked', |
1144
|
|
|
'ger-DE' => 'Sindelfingen', |
1145
|
|
|
); |
1146
|
|
|
|
1147
|
|
|
// This call will fail because state with |
1148
|
|
|
// 'not_locked' identifier already exists |
1149
|
|
|
$objectStateService->updateObjectState( |
1150
|
|
|
$loadedObjectState, |
1151
|
|
|
$updateStateStruct |
1152
|
|
|
); |
1153
|
|
|
} |
1154
|
|
|
|
1155
|
|
|
/** |
1156
|
|
|
* testUpdateObjectStateStructValues. |
1157
|
|
|
* |
1158
|
|
|
* @param array $testData |
1159
|
|
|
* |
1160
|
|
|
* |
1161
|
|
|
* @depends testUpdateObjectState |
1162
|
|
|
*/ |
1163
|
|
|
public function testUpdateObjectStateStructValues(array $testData) |
1164
|
|
|
{ |
1165
|
|
|
list( |
1166
|
|
|
$loadedObjectState, |
1167
|
|
|
$updateStateStruct, |
1168
|
|
|
$updatedObjectState |
1169
|
|
|
) = $testData; |
1170
|
|
|
|
1171
|
|
|
$this->assertPropertiesCorrect( |
1172
|
|
|
array( |
1173
|
|
|
'id' => $loadedObjectState->id, |
1174
|
|
|
'identifier' => $updateStateStruct->identifier, |
1175
|
|
|
'priority' => $loadedObjectState->priority, |
1176
|
|
|
'defaultLanguageCode' => $updateStateStruct->defaultLanguageCode, |
1177
|
|
|
'languageCodes' => array('eng-US', 'ger-DE'), |
1178
|
|
|
'names' => $updateStateStruct->names, |
1179
|
|
|
'descriptions' => $updateStateStruct->descriptions, |
1180
|
|
|
), |
1181
|
|
|
$updatedObjectState |
1182
|
|
|
); |
1183
|
|
|
|
1184
|
|
|
$this->assertEquals( |
1185
|
|
|
$loadedObjectState->getObjectStateGroup(), |
1186
|
|
|
$updatedObjectState->getObjectStateGroup() |
1187
|
|
|
); |
1188
|
|
|
} |
1189
|
|
|
|
1190
|
|
|
/** |
1191
|
|
|
* Test for the setPriorityOfObjectState() method. |
1192
|
|
|
* |
1193
|
|
|
* |
1194
|
|
|
* @see \eZ\Publish\API\Repository\ObjectStateService::setPriorityOfObjectState() |
1195
|
|
|
* @depends testLoadObjectState |
1196
|
|
|
*/ |
1197
|
|
View Code Duplication |
public function testSetPriorityOfObjectState() |
1198
|
|
|
{ |
1199
|
|
|
$repository = $this->getRepository(); |
1200
|
|
|
|
1201
|
|
|
$objectStateId = $this->generateId('objectstate', 1); |
1202
|
|
|
/* BEGIN: Use Case */ |
1203
|
|
|
// $objectStateId contains the ID of the "not_locked" state |
1204
|
|
|
$objectStateService = $repository->getObjectStateService(); |
1205
|
|
|
|
1206
|
|
|
$initiallyLoadedObjectState = $objectStateService->loadObjectState( |
1207
|
|
|
$objectStateId |
1208
|
|
|
); |
1209
|
|
|
|
1210
|
|
|
// Sets the given priority on $initiallyLoadedObjectState |
1211
|
|
|
$objectStateService->setPriorityOfObjectState( |
1212
|
|
|
$initiallyLoadedObjectState, |
1213
|
|
|
23 |
1214
|
|
|
); |
1215
|
|
|
// $loadObjectState now has the priority 1, since object state |
1216
|
|
|
// priorities are always made sequential |
1217
|
|
|
$loadedObjectState = $objectStateService->loadObjectState( |
1218
|
|
|
$objectStateId |
1219
|
|
|
); |
1220
|
|
|
/* END: Use Case */ |
1221
|
|
|
|
1222
|
|
|
$this->assertInstanceOf( |
1223
|
|
|
'eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectState', |
1224
|
|
|
$loadedObjectState |
1225
|
|
|
); |
1226
|
|
|
$this->assertEquals(1, $loadedObjectState->priority); |
1227
|
|
|
} |
1228
|
|
|
|
1229
|
|
|
/** |
1230
|
|
|
* Test for the getContentState() method. |
1231
|
|
|
* |
1232
|
|
|
* |
1233
|
|
|
* @see \eZ\Publish\API\Repository\ObjectStateService::getContentState() |
1234
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
1235
|
|
|
* @depends testLoadObjectState |
1236
|
|
|
*/ |
1237
|
|
|
public function testGetContentState() |
1238
|
|
|
{ |
1239
|
|
|
$repository = $this->getRepository(); |
1240
|
|
|
|
1241
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
1242
|
|
|
$ezLockObjectStateGroupId = $this->generateId('objectstategroup', 2); |
1243
|
|
|
/* BEGIN: Use Case */ |
1244
|
|
|
// $anonymousUserId is the content ID of "Anonymous User" |
1245
|
|
|
$contentService = $repository->getContentService(); |
1246
|
|
|
$objectStateService = $repository->getObjectStateService(); |
1247
|
|
|
|
1248
|
|
|
$contentInfo = $contentService->loadContentInfo($anonymousUserId); |
1249
|
|
|
|
1250
|
|
|
$ezLockObjectStateGroup = $objectStateService->loadObjectStateGroup( |
1251
|
|
|
$ezLockObjectStateGroupId |
1252
|
|
|
); |
1253
|
|
|
|
1254
|
|
|
// Loads the state of $contentInfo in the "ez_lock" object state group |
1255
|
|
|
$ezLockObjectState = $objectStateService->getContentState( |
1256
|
|
|
$contentInfo, |
1257
|
|
|
$ezLockObjectStateGroup |
1258
|
|
|
); |
1259
|
|
|
/* END: Use Case */ |
1260
|
|
|
|
1261
|
|
|
$this->assertInstanceOf( |
1262
|
|
|
'eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectState', |
1263
|
|
|
$ezLockObjectState |
1264
|
|
|
); |
1265
|
|
|
$this->assertEquals('not_locked', $ezLockObjectState->identifier); |
1266
|
|
|
} |
1267
|
|
|
|
1268
|
|
|
/** |
1269
|
|
|
* testGetInitialObjectState. |
1270
|
|
|
* |
1271
|
|
|
* |
1272
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
1273
|
|
|
* @depends testLoadObjectState |
1274
|
|
|
*/ |
1275
|
|
|
public function testGetInitialObjectState() |
1276
|
|
|
{ |
1277
|
|
|
$repository = $this->getRepository(); |
1278
|
|
|
$objectStateService = $repository->getObjectStateService(); |
1279
|
|
|
|
1280
|
|
|
// Create object state group with custom state |
1281
|
|
|
$createdStateGroups = $this->createObjectStateGroups(); |
1282
|
|
|
|
1283
|
|
|
$customObjectStateGroupId = $createdStateGroups[1]->id; |
1284
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
1285
|
|
|
|
1286
|
|
|
$customGroup = $objectStateService->loadObjectStateGroup( |
1287
|
|
|
$customObjectStateGroupId |
1288
|
|
|
); |
1289
|
|
|
|
1290
|
|
|
$objectStateCreateStruct = $objectStateService->newObjectStateCreateStruct( |
1291
|
|
|
'sindelfingen' |
1292
|
|
|
); |
1293
|
|
|
$objectStateCreateStruct->priority = 1; |
1294
|
|
|
$objectStateCreateStruct->defaultLanguageCode = 'eng-US'; |
1295
|
|
|
$objectStateCreateStruct->names = array('eng-US' => 'Sindelfingen'); |
|
|
|
|
1296
|
|
|
|
1297
|
|
|
$createdState = $objectStateService->createObjectState( |
1298
|
|
|
$customGroup, |
1299
|
|
|
$objectStateCreateStruct |
1300
|
|
|
); |
1301
|
|
|
|
1302
|
|
|
// Store state ID to be used |
1303
|
|
|
$customObjectStateId = $createdState->id; |
|
|
|
|
1304
|
|
|
|
1305
|
|
|
/* BEGIN: Use Case */ |
1306
|
|
|
// $anonymousUserId is the content ID of "Anonymous User" |
1307
|
|
|
// $customObjectStateGroupId is the ID of a state group, from which no |
1308
|
|
|
// state has been assigned to $anonymousUserId, yet |
1309
|
|
|
$contentService = $repository->getContentService(); |
1310
|
|
|
$objectStateService = $repository->getObjectStateService(); |
1311
|
|
|
|
1312
|
|
|
$contentInfo = $contentService->loadContentInfo($anonymousUserId); |
1313
|
|
|
|
1314
|
|
|
$customObjectStateGroup = $objectStateService->loadObjectStateGroup( |
1315
|
|
|
$customObjectStateGroupId |
1316
|
|
|
); |
1317
|
|
|
|
1318
|
|
|
// Loads the initial state of the custom state group |
1319
|
|
|
$initialObjectState = $objectStateService->getContentState( |
1320
|
|
|
$contentInfo, |
1321
|
|
|
$customObjectStateGroup |
1322
|
|
|
); |
1323
|
|
|
/* END: Use Case */ |
1324
|
|
|
|
1325
|
|
|
$this->assertInstanceOf( |
1326
|
|
|
'eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectState', |
1327
|
|
|
$initialObjectState |
1328
|
|
|
); |
1329
|
|
|
$this->assertEquals('sindelfingen', $initialObjectState->identifier); |
1330
|
|
|
$this->assertEquals(array('eng-US' => 'Sindelfingen'), $initialObjectState->names); |
|
|
|
|
1331
|
|
|
$this->assertEquals('eng-US', $initialObjectState->defaultLanguageCode); |
1332
|
|
|
} |
1333
|
|
|
|
1334
|
|
|
/** |
1335
|
|
|
* Test for the setContentState() method. |
1336
|
|
|
* |
1337
|
|
|
* |
1338
|
|
|
* @see \eZ\Publish\API\Repository\ObjectStateService::setContentState() |
1339
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
1340
|
|
|
* @depends testLoadObjectState |
1341
|
|
|
*/ |
1342
|
|
View Code Duplication |
public function testSetContentState() |
1343
|
|
|
{ |
1344
|
|
|
$repository = $this->getRepository(); |
1345
|
|
|
|
1346
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
1347
|
|
|
$ezLockObjectStateGroupId = $this->generateId('objectstategroup', 2); |
1348
|
|
|
$lockedObjectStateId = $this->generateId('objectstate', 2); |
1349
|
|
|
/* BEGIN: Use Case */ |
1350
|
|
|
// $anonymousUserId is the content ID of "Anonymous User" |
1351
|
|
|
// $ezLockObjectStateGroupId contains the ID of the "ez_lock" object |
1352
|
|
|
// state group |
1353
|
|
|
// $lockedObjectStateId is the ID of the state "locked" |
1354
|
|
|
$contentService = $repository->getContentService(); |
1355
|
|
|
$objectStateService = $repository->getObjectStateService(); |
1356
|
|
|
|
1357
|
|
|
$contentInfo = $contentService->loadContentInfo($anonymousUserId); |
1358
|
|
|
|
1359
|
|
|
$ezLockObjectStateGroup = $objectStateService->loadObjectStateGroup( |
1360
|
|
|
$ezLockObjectStateGroupId |
1361
|
|
|
); |
1362
|
|
|
$lockedObjectState = $objectStateService->loadObjectState($lockedObjectStateId); |
1363
|
|
|
|
1364
|
|
|
// Sets the state of $contentInfo from "not_locked" to "locked" |
1365
|
|
|
$objectStateService->setContentState( |
1366
|
|
|
$contentInfo, |
1367
|
|
|
$ezLockObjectStateGroup, |
1368
|
|
|
$lockedObjectState |
1369
|
|
|
); |
1370
|
|
|
/* END: Use Case */ |
1371
|
|
|
|
1372
|
|
|
$ezLockObjectState = $objectStateService->getContentState( |
1373
|
|
|
$contentInfo, |
1374
|
|
|
$ezLockObjectStateGroup |
1375
|
|
|
); |
1376
|
|
|
|
1377
|
|
|
$this->assertEquals('locked', $ezLockObjectState->identifier); |
1378
|
|
|
} |
1379
|
|
|
|
1380
|
|
|
/** |
1381
|
|
|
* Test for the setContentState() method. |
1382
|
|
|
* |
1383
|
|
|
* @covers \eZ\Publish\API\Repository\ObjectStateService::setContentState |
1384
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
1385
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ObjectStateServiceTest::testSetContentState |
1386
|
|
|
*/ |
1387
|
|
|
public function testSetContentStateThrowsInvalidArgumentException() |
1388
|
|
|
{ |
1389
|
|
|
$repository = $this->getRepository(); |
1390
|
|
|
|
1391
|
|
|
$createdStateGroups = $this->createObjectStateGroups(); |
1392
|
|
|
|
1393
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
1394
|
|
|
$differentObjectStateGroupId = $createdStateGroups[1]->id; |
1395
|
|
|
$lockedObjectStateId = $this->generateId('objectstate', 2); |
1396
|
|
|
|
1397
|
|
|
/* BEGIN: Use Case */ |
1398
|
|
|
// $anonymousUserId is the content ID of "Anonymous User" |
1399
|
|
|
// $differentObjectStateGroupId contains the ID of an object state |
1400
|
|
|
// group which does not contain $lockedObjectStateId |
1401
|
|
|
// $lockedObjectStateId is the ID of the state "locked" |
1402
|
|
|
$contentService = $repository->getContentService(); |
1403
|
|
|
$objectStateService = $repository->getObjectStateService(); |
1404
|
|
|
|
1405
|
|
|
$contentInfo = $contentService->loadContentInfo($anonymousUserId); |
1406
|
|
|
|
1407
|
|
|
$differentObjectStateGroup = $objectStateService->loadObjectStateGroup( |
1408
|
|
|
$differentObjectStateGroupId |
1409
|
|
|
); |
1410
|
|
|
$lockedObjectState = $objectStateService->loadObjectState($lockedObjectStateId); |
1411
|
|
|
|
1412
|
|
|
// Throws an invalid argument exception since $lockedObjectState does |
1413
|
|
|
// not belong to $differentObjectStateGroup |
1414
|
|
|
$objectStateService->setContentState( |
1415
|
|
|
$contentInfo, |
1416
|
|
|
$differentObjectStateGroup, |
1417
|
|
|
$lockedObjectState |
1418
|
|
|
); |
1419
|
|
|
/* END: Use Case */ |
1420
|
|
|
} |
1421
|
|
|
|
1422
|
|
|
/** |
1423
|
|
|
* Test for the getContentCount() method. |
1424
|
|
|
* |
1425
|
|
|
* |
1426
|
|
|
* @see \eZ\Publish\API\Repository\ObjectStateService::getContentCount() |
1427
|
|
|
* @depends testLoadObjectState |
1428
|
|
|
*/ |
1429
|
|
View Code Duplication |
public function testGetContentCount() |
1430
|
|
|
{ |
1431
|
|
|
$repository = $this->getRepository(); |
1432
|
|
|
|
1433
|
|
|
$notLockedObjectStateId = $this->generateId('objectstate', 1); |
1434
|
|
|
/* BEGIN: Use Case */ |
1435
|
|
|
// $notLockedObjectStateId is the ID of the state "not_locked" |
1436
|
|
|
$objectStateService = $repository->getObjectStateService(); |
1437
|
|
|
|
1438
|
|
|
$notLockedObjectState = $objectStateService->loadObjectState($notLockedObjectStateId); |
1439
|
|
|
|
1440
|
|
|
$objectCount = $objectStateService->getContentCount($notLockedObjectState); |
1441
|
|
|
/* END: Use Case */ |
1442
|
|
|
|
1443
|
|
|
$this->assertEquals(18, $objectCount); |
1444
|
|
|
} |
1445
|
|
|
|
1446
|
|
|
/** |
1447
|
|
|
* Test for the deleteObjectState() method. |
1448
|
|
|
* |
1449
|
|
|
* |
1450
|
|
|
* @see \eZ\Publish\API\Repository\ObjectStateService::deleteObjectState() |
1451
|
|
|
* @depends testLoadObjectState |
1452
|
|
|
*/ |
1453
|
|
View Code Duplication |
public function testDeleteObjectState() |
1454
|
|
|
{ |
1455
|
|
|
$repository = $this->getRepository(); |
1456
|
|
|
|
1457
|
|
|
$notLockedObjectStateId = $this->generateId('objectstate', 1); |
1458
|
|
|
$lockedObjectStateId = $this->generateId('objectstate', 2); |
1459
|
|
|
/* BEGIN: Use Case */ |
1460
|
|
|
// $notLockedObjectStateId is the ID of the state "not_locked" |
1461
|
|
|
$objectStateService = $repository->getObjectStateService(); |
1462
|
|
|
|
1463
|
|
|
$notLockedObjectState = $objectStateService->loadObjectState($notLockedObjectStateId); |
1464
|
|
|
|
1465
|
|
|
// Deletes the object state and sets all objects, which where in that |
1466
|
|
|
// state, to the first state of the same object state group |
1467
|
|
|
$objectStateService->deleteObjectState($notLockedObjectState); |
1468
|
|
|
/* END: Use Case */ |
1469
|
|
|
|
1470
|
|
|
$lockedObjectState = $objectStateService->loadObjectState($lockedObjectStateId); |
1471
|
|
|
|
1472
|
|
|
// All objects transferred |
1473
|
|
|
$this->assertEquals( |
1474
|
|
|
18, |
1475
|
|
|
$objectStateService->getContentCount($lockedObjectState) |
1476
|
|
|
); |
1477
|
|
|
} |
1478
|
|
|
|
1479
|
|
|
/** |
1480
|
|
|
* Test for the deleteObjectStateGroup() method. |
1481
|
|
|
* |
1482
|
|
|
* |
1483
|
|
|
* @see \eZ\Publish\API\Repository\ObjectStateService::deleteObjectStateGroup() |
1484
|
|
|
* @depends testLoadObjectStateGroup |
1485
|
|
|
*/ |
1486
|
|
|
public function testDeleteObjectStateGroup() |
1487
|
|
|
{ |
1488
|
|
|
$repository = $this->getRepository(); |
1489
|
|
|
|
1490
|
|
|
$objectStateGroupId = $this->generateId('objectstategroup', 2); |
1491
|
|
|
/* BEGIN: Use Case */ |
1492
|
|
|
// $objectStateGroupId contains the ID of the standard object state |
1493
|
|
|
// group ez_lock. |
1494
|
|
|
$objectStateService = $repository->getObjectStateService(); |
1495
|
|
|
|
1496
|
|
|
$loadedObjectStateGroup = $objectStateService->loadObjectStateGroup( |
1497
|
|
|
$objectStateGroupId |
1498
|
|
|
); |
1499
|
|
|
|
1500
|
|
|
$objectStateService->deleteObjectStateGroup($loadedObjectStateGroup); |
1501
|
|
|
/* END: Use Case */ |
1502
|
|
|
|
1503
|
|
|
try { |
1504
|
|
|
$objectStateService->loadObjectStateGroup($objectStateGroupId); |
1505
|
|
|
$this->fail( |
1506
|
|
|
sprintf( |
1507
|
|
|
'ObjectStateGroup with ID "%s" not deleted.', |
1508
|
|
|
$objectStateGroupId |
1509
|
|
|
) |
1510
|
|
|
); |
1511
|
|
|
} catch (NotFoundException $e) { |
|
|
|
|
1512
|
|
|
} |
1513
|
|
|
} |
1514
|
|
|
} |
1515
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..