Completed
Push — ezp26914-imagine_resolve_excep... ( c5a137...48c7cc )
by
unknown
42:21 queued 27:20
created

ObjectStateServiceTest::testLoadObjectStateGroup()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 10

Duplication

Lines 22
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 22
loc 22
rs 9.2
c 0
b 0
f 0
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(
0 ignored issues
show
Documentation Bug introduced by
It seems like array('eng-US' => 'Publi...-GB' => 'Sindelfingen') of type array<string,string,{"en...ng","eng-GB":"string"}> is incompatible with the declared type array<integer,string> of property $names.

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..

Loading history...
231
            'eng-US' => 'Publishing',
232
            'eng-GB' => 'Sindelfingen',
233
        );
234
        $objectStateGroupCreate->descriptions = array(
0 ignored issues
show
Documentation Bug introduced by
It seems like array('eng-US' => 'Put s...ing ton Sindelfingen.') of type array<string,string,{"en...ng","eng-GB":"string"}> is incompatible with the declared type array<integer,string> of property $descriptions.

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..

Loading history...
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(
0 ignored issues
show
Documentation Bug introduced by
It seems like array('eng-US' => 'Publi...-GB' => 'Sindelfingen') of type array<string,string,{"en...ng","eng-GB":"string"}> is incompatible with the declared type array<integer,string> of property $names.

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..

Loading history...
301
            'eng-US' => 'Publishing',
302
            'eng-GB' => 'Sindelfingen',
303
        );
304
        $objectStateGroupCreate->descriptions = array(
0 ignored issues
show
Documentation Bug introduced by
It seems like array('eng-US' => 'Put s...ing ton Sindelfingen.') of type array<string,string,{"en...ng","eng-GB":"string"}> is incompatible with the declared type array<integer,string> of property $descriptions.

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..

Loading history...
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
     *
319
     * @see \eZ\Publish\API\Repository\ObjectStateService::loadObjectStateGroup()
320
     */
321 View Code Duplication
    public function testLoadObjectStateGroup()
322
    {
323
        $repository = $this->getRepository();
324
325
        $objectStateGroupId = $this->generateId('objectstategroup', 2);
326
        /* BEGIN: Use Case */
327
        // $objectStateGroupId contains the ID of the standard object state
328
        // group ez_lock.
329
        $objectStateService = $repository->getObjectStateService();
330
331
        $loadedObjectStateGroup = $objectStateService->loadObjectStateGroup(
332
            $objectStateGroupId
333
        );
334
        /* END: Use Case */
335
336
        $this->assertInstanceOf(
337
            '\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectStateGroup',
338
            $loadedObjectStateGroup
339
        );
340
341
        return $loadedObjectStateGroup;
342
    }
343
344
    /**
345
     * Test for the loadObjectStateGroup() method.
346
     *
347
     *
348
     * @see \eZ\Publish\API\Repository\ObjectStateService::loadObjectStateGroup()
349
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
350
     * @depends testLoadObjectStateGroup
351
     */
352
    public function testLoadObjectStateGroupThrowsNotFoundException()
353
    {
354
        $repository = $this->getRepository();
355
356
        $nonExistentObjectStateGroupId = $this->generateId('objectstategroup', self::DB_INT_MAX);
357
        /* BEGIN: Use Case */
358
        // $nonExistentObjectStateGroupId contains an ID for an object state
359
        // that does not exist
360
        $objectStateService = $repository->getObjectStateService();
361
362
        // Throws a not found exception
363
        $loadedObjectStateGroup = $objectStateService->loadObjectStateGroup(
0 ignored issues
show
Unused Code introduced by
$loadedObjectStateGroup is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
364
            $nonExistentObjectStateGroupId
365
        );
366
        /* END: Use Case */
367
    }
368
369
    /**
370
     * Test for the loadObjectStateGroups() method.
371
     *
372
     *
373
     * @see \eZ\Publish\API\Repository\ObjectStateService::loadObjectStateGroups()
374
     * @depends testLoadObjectStateGroup
375
     */
376
    public function testLoadObjectStateGroups()
377
    {
378
        $repository = $this->getRepository();
379
380
        $expectedGroupIdentifiers = $this->getGroupIdentifierMap($this->createObjectStateGroups());
381
        $expectedGroupIdentifiers['ez_lock'] = true;
382
383
        /* BEGIN: Use Case */
384
        $objectStateService = $repository->getObjectStateService();
385
386
        $loadedObjectStateGroups = $objectStateService->loadObjectStateGroups();
387
        /* END: Use Case */
388
389
        $this->assertInternalType('array', $loadedObjectStateGroups);
390
391
        $this->assertObjectsLoadedByIdentifiers(
392
            $expectedGroupIdentifiers,
393
            $loadedObjectStateGroups,
394
            'ObjectStateGroup'
395
        );
396
    }
397
398
    /**
399
     * Creates a set of object state groups and returns an array of all
400
     * existing group identifiers after creation.
401
     *
402
     * @return bool[]
403
     */
404
    protected function createObjectStateGroups()
405
    {
406
        $repository = $this->getRepository();
407
        $objectStateService = $repository->getObjectStateService();
408
409
        $identifiersToCreate = array(
410
            'first',
411
            'second',
412
            'third',
413
        );
414
415
        $createdStateGroups = array();
416
417
        $groupCreateStruct = $objectStateService->newObjectStateGroupCreateStruct('dummy');
418
419
        $groupCreateStruct->defaultLanguageCode = 'eng-US';
420
        $groupCreateStruct->names = array('eng-US' => 'Foo');
0 ignored issues
show
Documentation Bug introduced by
It seems like array('eng-US' => 'Foo') of type array<string,string,{"eng-US":"string"}> is incompatible with the declared type array<integer,string> of property $names.

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..

Loading history...
421
        $groupCreateStruct->descriptions = array('eng-US' => 'Foo Bar');
0 ignored issues
show
Documentation Bug introduced by
It seems like array('eng-US' => 'Foo Bar') of type array<string,string,{"eng-US":"string"}> is incompatible with the declared type array<integer,string> of property $descriptions.

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..

Loading history...
422
423
        foreach ($identifiersToCreate as $identifier) {
424
            $groupCreateStruct->identifier = $identifier;
425
            $createdStateGroups[] = $objectStateService->createObjectStateGroup($groupCreateStruct);
426
        }
427
428
        return $createdStateGroups;
429
    }
430
431
    /**
432
     * testLoadObjectStateGroupsLoadedExpectedGroups.
433
     *
434
     * @param array $loadObjectStateGroups
0 ignored issues
show
Bug introduced by
There is no parameter named $loadObjectStateGroups. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
435
     *
436
     * @depends testLoadObjectStateGroups
437
     */
438
    protected function assertObjectsLoadedByIdentifiers(array $expectedIdentifiers, array $loadedObjects, $class)
439
    {
440
        foreach ($loadedObjects as $loadedObject) {
441
            if (!isset($expectedIdentifiers[$loadedObject->identifier])) {
442
                $this->fail(
443
                    sprintf(
444
                        'Loaded not expected %s with identifier "%s"',
445
                        $class,
446
                        $loadedObject->identifier
447
                    )
448
                );
449
            }
450
            unset($expectedIdentifiers[$loadedObject->identifier]);
451
        }
452
453
        if (!empty($expectedIdentifiers)) {
454
            $this->fail(
455
                sprintf(
456
                    'Expected %ss with identifiers "%s" not loaded.',
457
                    $class,
458
                    implode('", "', $expectedIdentifiers)
459
                )
460
            );
461
        }
462
    }
463
464
    /**
465
     * Test for the loadObjectStateGroups() method.
466
     *
467
     *
468
     * @see \eZ\Publish\API\Repository\ObjectStateService::loadObjectStateGroups($offset)
469
     * @depends testLoadObjectStateGroups
470
     */
471 View Code Duplication
    public function testLoadObjectStateGroupsWithOffset()
472
    {
473
        $repository = $this->getRepository();
474
        $objectStateService = $repository->getObjectStateService();
475
476
        $this->createObjectStateGroups();
477
478
        $allObjectStateGroups = $objectStateService->loadObjectStateGroups();
479
480
        $existingGroupIdentifiers = $this->getGroupIdentifierMap($allObjectStateGroups);
481
482
        /* BEGIN: Use Case */
483
        $objectStateService = $repository->getObjectStateService();
484
485
        $loadedObjectStateGroups = $objectStateService->loadObjectStateGroups(2);
486
        /* END: Use Case */
487
488
        $this->assertInternalType('array', $loadedObjectStateGroups);
489
490
        $this->assertObjectsLoadedByIdentifiers(
491
            array_slice($existingGroupIdentifiers, 2),
492
            $loadedObjectStateGroups,
493
            'ObjectStateGroup'
494
        );
495
    }
496
497
    /**
498
     * Returns a map of the given object state groups.
499
     *
500
     * @param array $groups
501
     */
502
    protected function getGroupIdentifierMap(array $groups)
503
    {
504
        $existingGroupIdentifiers = array_map(
505
            function ($group) {
506
                return $group->identifier;
507
            },
508
            $groups
509
        );
510
511
        return array_fill_keys($existingGroupIdentifiers, true);
512
    }
513
514
    /**
515
     * Test for the loadObjectStateGroups() method.
516
     *
517
     *
518
     * @see \eZ\Publish\API\Repository\ObjectStateService::loadObjectStateGroups($offset, $limit)
519
     * @depends testLoadObjectStateGroupsWithOffset
520
     */
521 View Code Duplication
    public function testLoadObjectStateGroupsWithOffsetAndLimit()
522
    {
523
        $repository = $this->getRepository();
524
        $objectStateService = $repository->getObjectStateService();
525
526
        $allObjectStateGroups = $objectStateService->loadObjectStateGroups();
527
528
        $existingGroupIdentifiers = $this->getGroupIdentifierMap($allObjectStateGroups);
529
530
        /* BEGIN: Use Case */
531
        $objectStateService = $repository->getObjectStateService();
532
533
        $loadedObjectStateGroups = $objectStateService->loadObjectStateGroups(1, 2);
534
        /* END: Use Case */
535
536
        $this->assertInternalType('array', $loadedObjectStateGroups);
537
538
        $this->assertObjectsLoadedByIdentifiers(
539
            array_slice($existingGroupIdentifiers, 1, 2),
540
            $loadedObjectStateGroups,
541
            'ObjectStateGroup'
542
        );
543
    }
544
545
    /**
546
     * Test for the loadObjectStates() method.
547
     *
548
     *
549
     * @see \eZ\Publish\API\Repository\ObjectStateService::loadObjectStates()
550
     * @depends testLoadObjectStateGroup
551
     */
552
    public function testLoadObjectStates()
553
    {
554
        $repository = $this->getRepository();
555
556
        $objectStateGroupId = $this->generateId('objectstategroup', 2);
557
        /* BEGIN: Use Case */
558
        // $objectStateGroupId contains the ID of the standard object state
559
        // group ez_lock.
560
        $objectStateService = $repository->getObjectStateService();
561
562
        $objectStateGroup = $objectStateService->loadObjectStateGroup(
563
            $objectStateGroupId
564
        );
565
566
        // Loads all object states in $objectStateGroup
567
        $loadedObjectStates = $objectStateService->loadObjectStates($objectStateGroup);
568
        /* END: Use Case */
569
570
        $this->assertInternalType(
571
            'array',
572
            $loadedObjectStates
573
        );
574
        $this->assertObjectsLoadedByIdentifiers(
575
            array('not_locked' => true, 'locked' => true),
576
            $loadedObjectStates,
577
            'ObjectState'
578
        );
579
    }
580
581
    /**
582
     * Test for the updateObjectStateGroup() method.
583
     *
584
     *
585
     * @see \eZ\Publish\API\Repository\ObjectStateService::updateObjectStateGroup()
586
     * @depends testLoadObjectStateGroup
587
     */
588 View Code Duplication
    public function testUpdateObjectStateGroup()
589
    {
590
        $repository = $this->getRepository();
591
592
        $objectStateGroupId = $this->generateId('objectstategroup', 2);
593
        /* BEGIN: Use Case */
594
        // $objectStateGroupId contains the ID of the standard object state
595
        // group ez_lock.
596
        $objectStateService = $repository->getObjectStateService();
597
598
        $loadedObjectStateGroup = $objectStateService->loadObjectStateGroup(
599
            $objectStateGroupId
600
        );
601
602
        $groupUpdateStruct = $objectStateService->newObjectStateGroupUpdateStruct();
603
        $groupUpdateStruct->identifier = 'sindelfingen';
604
        $groupUpdateStruct->defaultLanguageCode = 'ger-DE';
605
        $groupUpdateStruct->names = array(
0 ignored issues
show
Documentation Bug introduced by
It seems like array('ger-DE' => 'Sindelfingen') of type array<string,string,{"ger-DE":"string"}> is incompatible with the declared type array<integer,string> of property $names.

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..

Loading history...
606
            'ger-DE' => 'Sindelfingen',
607
        );
608
        $groupUpdateStruct->descriptions = array(
0 ignored issues
show
Documentation Bug introduced by
It seems like array('ger-DE' => 'Sinde... nicht nur eine Stadt') of type array<string,string,{"ger-DE":"string"}> is incompatible with the declared type array<integer,string> of property $descriptions.

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..

Loading history...
609
            'ger-DE' => 'Sindelfingen ist nicht nur eine Stadt',
610
        );
611
612
        // Updates the $loadObjectStateGroup with the data from
613
        // $groupUpdateStruct and returns the updated group
614
        $updatedObjectStateGroup = $objectStateService->updateObjectStateGroup(
615
            $loadedObjectStateGroup,
616
            $groupUpdateStruct
617
        );
618
        /* END: Use Case */
619
620
        $this->assertInstanceOf(
621
            '\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectStateGroup',
622
            $updatedObjectStateGroup
623
        );
624
625
        return array(
626
            $loadedObjectStateGroup,
627
            $groupUpdateStruct,
628
            $updatedObjectStateGroup,
629
        );
630
    }
631
632
    /**
633
     * Test for the updateObjectStateGroup() method.
634
     *
635
     *
636
     * @see \eZ\Publish\API\Repository\ObjectStateService::updateObjectStateGroup()
637
     * @depends testUpdateObjectStateGroup
638
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
639
     */
640
    public function testUpdateObjectStateGroupThrowsInvalidArgumentException()
641
    {
642
        $repository = $this->getRepository();
643
644
        $objectStateService = $repository->getObjectStateService();
645
646
        // Create object state group which we will later update
647
        $objectStateGroupCreate = $objectStateService->newObjectStateGroupCreateStruct(
648
            'publishing'
649
        );
650
        $objectStateGroupCreate->defaultLanguageCode = 'eng-US';
651
        $objectStateGroupCreate->names = array(
0 ignored issues
show
Documentation Bug introduced by
It seems like array('eng-US' => 'Publi...-GB' => 'Sindelfingen') of type array<string,string,{"en...ng","eng-GB":"string"}> is incompatible with the declared type array<integer,string> of property $names.

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..

Loading history...
652
            'eng-US' => 'Publishing',
653
            'eng-GB' => 'Sindelfingen',
654
        );
655
        $objectStateGroupCreate->descriptions = array(
0 ignored issues
show
Documentation Bug introduced by
It seems like array('eng-US' => 'Put s...ing ton Sindelfingen.') of type array<string,string,{"en...ng","eng-GB":"string"}> is incompatible with the declared type array<integer,string> of property $descriptions.

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..

Loading history...
656
            'eng-US' => 'Put something online',
657
            'eng-GB' => 'Put something ton Sindelfingen.',
658
        );
659
660
        $createdObjectStateGroup = $objectStateService->createObjectStateGroup(
661
            $objectStateGroupCreate
662
        );
663
664
        $groupUpdateStruct = $objectStateService->newObjectStateGroupUpdateStruct();
665
        // 'ez_lock' is the identifier of already existing group
666
        $groupUpdateStruct->identifier = 'ez_lock';
667
        $groupUpdateStruct->defaultLanguageCode = 'ger-DE';
668
        $groupUpdateStruct->names = array(
0 ignored issues
show
Documentation Bug introduced by
It seems like array('ger-DE' => 'Sindelfingen') of type array<string,string,{"ger-DE":"string"}> is incompatible with the declared type array<integer,string> of property $names.

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..

Loading history...
669
            'ger-DE' => 'Sindelfingen',
670
        );
671
        $groupUpdateStruct->descriptions = array(
0 ignored issues
show
Documentation Bug introduced by
It seems like array('ger-DE' => 'Sinde... nicht nur eine Stadt') of type array<string,string,{"ger-DE":"string"}> is incompatible with the declared type array<integer,string> of property $descriptions.

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..

Loading history...
672
            'ger-DE' => 'Sindelfingen ist nicht nur eine Stadt',
673
        );
674
675
        // This call will fail since state group with 'ez_lock' identifier already exists
676
        $objectStateService->updateObjectStateGroup(
677
            $createdObjectStateGroup,
678
            $groupUpdateStruct
679
        );
680
    }
681
682
    /**
683
     * testUpdateObjectStateGroupStructValues.
684
     *
685
     * @param array $testData
686
     *
687
     *
688
     * @depends testUpdateObjectStateGroup
689
     */
690
    public function testUpdateObjectStateGroupStructValues(array $testData)
691
    {
692
        list(
693
            $loadedObjectStateGroup,
0 ignored issues
show
Unused Code introduced by
The assignment to $loadedObjectStateGroup is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
694
            $groupUpdateStruct,
695
            $updatedObjectStateGroup
696
        ) = $testData;
697
698
        $this->assertStructPropertiesCorrect(
699
            $groupUpdateStruct,
700
            $updatedObjectStateGroup
701
        );
702
    }
703
704
    /**
705
     * Test for the createObjectState() method.
706
     *
707
     *
708
     * @see \eZ\Publish\API\Repository\ObjectStateService::createObjectState()
709
     * @depends testLoadObjectStateGroup
710
     * @depends testNewObjectStateCreateStruct
711
     */
712 View Code Duplication
    public function testCreateObjectState()
713
    {
714
        $repository = $this->getRepository();
715
716
        $objectStateGroupId = $this->generateId('objectstategroup', 2);
717
        /* BEGIN: Use Case */
718
        // $objectStateGroupId contains the ID of the standard object state
719
        // group ez_lock.
720
        $objectStateService = $repository->getObjectStateService();
721
722
        $loadedObjectStateGroup = $objectStateService->loadObjectStateGroup(
723
            $objectStateGroupId
724
        );
725
726
        $objectStateCreateStruct = $objectStateService->newObjectStateCreateStruct(
727
            'locked_and_unlocked'
728
        );
729
        $objectStateCreateStruct->priority = 23;
730
        $objectStateCreateStruct->defaultLanguageCode = 'eng-US';
731
        $objectStateCreateStruct->names = array(
0 ignored issues
show
Documentation Bug introduced by
It seems like array('eng-US' => 'Locked and Unlocked') of type array<string,string,{"eng-US":"string"}> is incompatible with the declared type array<integer,string> of property $names.

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..

Loading history...
732
            'eng-US' => 'Locked and Unlocked',
733
        );
734
        $objectStateCreateStruct->descriptions = array(
0 ignored issues
show
Documentation Bug introduced by
It seems like array('eng-US' => 'A sta... locked and unlocked.') of type array<string,string,{"eng-US":"string"}> is incompatible with the declared type array<integer,string> of property $descriptions.

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..

Loading history...
735
            'eng-US' => 'A state between locked and unlocked.',
736
        );
737
738
        // Creates a new object state in the $loadObjectStateGroup with the
739
        // data from $objectStateCreateStruct
740
        $createdObjectState = $objectStateService->createObjectState(
741
            $loadedObjectStateGroup,
742
            $objectStateCreateStruct
743
        );
744
        /* END: Use Case */
745
746
        $this->assertInstanceOf(
747
            '\\eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectState',
748
            $createdObjectState
749
        );
750
        // Object sequences are renumbered
751
        $objectStateCreateStruct->priority = 2;
752
753
        return array(
754
            $loadedObjectStateGroup,
755
            $objectStateCreateStruct,
756
            $createdObjectState,
757
        );
758
    }
759
760
    /**
761
     * Test for the createObjectState() method.
762
     *
763
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
764
     *
765
     * @see \eZ\Publish\API\Repository\ObjectStateService::createObjectState()
766
     * @depends testLoadObjectStateGroup
767
     * @depends testCreateObjectState
768
     */
769 View Code Duplication
    public function testCreateObjectStateThrowsInvalidArgumentException()
770
    {
771
        $repository = $this->getRepository();
772
773
        $objectStateGroupId = $this->generateId('objectstategroup', 2);
774
        // $objectStateGroupId contains the ID of the standard object state
775
        // group ez_lock.
776
        $objectStateService = $repository->getObjectStateService();
777
778
        $loadedObjectStateGroup = $objectStateService->loadObjectStateGroup(
779
            $objectStateGroupId
780
        );
781
782
        $objectStateCreateStruct = $objectStateService->newObjectStateCreateStruct(
783
            // 'not_locked' is the identifier of already existing state
784
            'not_locked'
785
        );
786
        $objectStateCreateStruct->priority = 23;
787
        $objectStateCreateStruct->defaultLanguageCode = 'eng-US';
788
        $objectStateCreateStruct->names = array(
0 ignored issues
show
Documentation Bug introduced by
It seems like array('eng-US' => 'Locked and Unlocked') of type array<string,string,{"eng-US":"string"}> is incompatible with the declared type array<integer,string> of property $names.

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..

Loading history...
789
            'eng-US' => 'Locked and Unlocked',
790
        );
791
        $objectStateCreateStruct->descriptions = array(
0 ignored issues
show
Documentation Bug introduced by
It seems like array('eng-US' => 'A sta... locked and unlocked.') of type array<string,string,{"eng-US":"string"}> is incompatible with the declared type array<integer,string> of property $descriptions.

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..

Loading history...
792
            'eng-US' => 'A state between locked and unlocked.',
793
        );
794
795
        // This call will fail because object state with
796
        // 'not_locked' identifier already exists
797
        $objectStateService->createObjectState(
798
            $loadedObjectStateGroup,
799
            $objectStateCreateStruct
800
        );
801
    }
802
803
    /**
804
     * testCreateObjectStateStructValues.
805
     *
806
     * @param array $testData
807
     *
808
     *
809
     * @depends testCreateObjectState
810
     */
811
    public function testCreateObjectStateStructValues(array $testData)
812
    {
813
        list(
814
            $loadedObjectStateGroup,
815
            $objectStateCreateStruct,
816
            $createdObjectState
817
        ) = $testData;
818
819
        $this->assertStructPropertiesCorrect(
820
            $objectStateCreateStruct,
821
            $createdObjectState
822
        );
823
824
        $this->assertNotNull($createdObjectState->id);
825
826
        $this->assertEquals(
827
            $loadedObjectStateGroup,
828
            $createdObjectState->getObjectStateGroup()
829
        );
830
    }
831
832
    /**
833
     * Test for the loadObjectState() method.
834
     *
835
     *
836
     * @see \eZ\Publish\API\Repository\ObjectStateService::loadObjectState()
837
     * @depends testLoadObjectStateGroup
838
     */
839 View Code Duplication
    public function testLoadObjectState()
840
    {
841
        $repository = $this->getRepository();
842
843
        $objectStateId = $this->generateId('objectstate', 2);
844
        /* BEGIN: Use Case */
845
        // $objectStateId contains the ID of the "locked" state
846
        $objectStateService = $repository->getObjectStateService();
847
848
        $loadedObjectState = $objectStateService->loadObjectState(
849
            $objectStateId
850
        );
851
        /* END: Use Case */
852
853
        $this->assertInstanceOf(
854
            'eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectState',
855
            $loadedObjectState
856
        );
857
858
        return $loadedObjectState;
859
    }
860
861
    /**
862
     * testLoadObjectStateStructValues.
863
     *
864
     * @param \eZ\Publish\API\Repository\Values\ObjectState\ObjectState $loadedObjectState
865
     *
866
     *
867
     * @depends testLoadObjectState
868
     */
869
    public function testLoadObjectStateStructValues(ObjectState $loadedObjectState)
870
    {
871
        $this->assertPropertiesCorrect(
872
            array(
873
                'id' => 2,
874
                'identifier' => 'locked',
875
                'priority' => 1,
876
                'defaultLanguageCode' => 'eng-US',
877
                'languageCodes' => array(0 => 'eng-US'),
878
                'names' => array('eng-US' => 'Locked'),
879
                'descriptions' => array('eng-US' => ''),
880
            ),
881
            $loadedObjectState
882
        );
883
884
        $this->assertEquals(
885
            $this->getRepository()->getObjectStateService()->loadObjectStateGroup(2),
886
            $loadedObjectState->getObjectStateGroup()
887
        );
888
    }
889
890
    /**
891
     * Test for the loadObjectState() method.
892
     *
893
     *
894
     * @see \eZ\Publish\API\Repository\ObjectStateService::loadObjectState()
895
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
896
     * @depends testLoadObjectState
897
     */
898
    public function testLoadObjectStateThrowsNotFoundException()
899
    {
900
        $repository = $this->getRepository();
901
902
        $nonExistingObjectStateId = $this->generateId('objectstate', self::DB_INT_MAX);
903
        /* BEGIN: Use Case */
904
        // $nonExistingObjectStateId contains the ID of a non existing state
905
        $objectStateService = $repository->getObjectStateService();
906
907
        // Throws not found exception
908
        $loadedObjectState = $objectStateService->loadObjectState(
0 ignored issues
show
Unused Code introduced by
$loadedObjectState is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
909
            $nonExistingObjectStateId
910
        );
911
        /* END: Use Case */
912
    }
913
914
    /**
915
     * Test for the updateObjectState() method.
916
     *
917
     *
918
     * @see \eZ\Publish\API\Repository\ObjectStateService::updateObjectState()
919
     * @depends testLoadObjectState
920
     */
921
    public function testUpdateObjectState()
922
    {
923
        $repository = $this->getRepository();
924
925
        $objectStateId = $this->generateId('objectstate', 2);
926
        /* BEGIN: Use Case */
927
        // $objectStateId contains the ID of the "locked" state
928
        $objectStateService = $repository->getObjectStateService();
929
930
        $loadedObjectState = $objectStateService->loadObjectState(
931
            $objectStateId
932
        );
933
934
        $updateStateStruct = $objectStateService->newObjectStateUpdateStruct();
935
        $updateStateStruct->identifier = 'somehow_locked';
936
        $updateStateStruct->defaultLanguageCode = 'ger-DE';
937
        $updateStateStruct->names = array(
0 ignored issues
show
Documentation Bug introduced by
It seems like array('eng-US' => 'Someh...=> 'Irgendwie gelockt') of type array<string,string,{"en...ng","ger-DE":"string"}> is incompatible with the declared type array<integer,string> of property $names.

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..

Loading history...
938
            'eng-US' => 'Somehow locked',
939
            'ger-DE' => 'Irgendwie gelockt',
940
        );
941
        $updateStateStruct->descriptions = array(
0 ignored issues
show
Documentation Bug introduced by
It seems like array('eng-US' => 'The o...-DE' => 'Sindelfingen') of type array<string,string,{"en...ng","ger-DE":"string"}> is incompatible with the declared type array<integer,string> of property $descriptions.

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..

Loading history...
942
            'eng-US' => 'The object is somehow locked',
943
            'ger-DE' => 'Sindelfingen',
944
        );
945
946
        $updatedObjectState = $objectStateService->updateObjectState(
947
            $loadedObjectState,
948
            $updateStateStruct
949
        );
950
        /* END: Use Case */
951
952
        $this->assertInstanceOf(
953
            'eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectState',
954
            $updatedObjectState
955
        );
956
957
        return array(
958
            $loadedObjectState,
959
            $updateStateStruct,
960
            $updatedObjectState,
961
        );
962
    }
963
964
    /**
965
     * Test for the updateObjectState() method.
966
     *
967
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
968
     *
969
     * @see \eZ\Publish\API\Repository\ObjectStateService::updateObjectState()
970
     * @depends testUpdateObjectState
971
     */
972 View Code Duplication
    public function testUpdateObjectStateThrowsInvalidArgumentException()
973
    {
974
        $repository = $this->getRepository();
975
976
        $objectStateId = $this->generateId('objectstate', 2);
977
        // $objectStateId contains the ID of the "locked" state
978
        $objectStateService = $repository->getObjectStateService();
979
980
        $loadedObjectState = $objectStateService->loadObjectState(
981
            $objectStateId
982
        );
983
984
        $updateStateStruct = $objectStateService->newObjectStateUpdateStruct();
985
        // 'not_locked' is the identifier of already existing state
986
        $updateStateStruct->identifier = 'not_locked';
987
        $updateStateStruct->defaultLanguageCode = 'ger-DE';
988
        $updateStateStruct->names = array(
0 ignored issues
show
Documentation Bug introduced by
It seems like array('eng-US' => 'Someh...=> 'Irgendwie gelockt') of type array<string,string,{"en...ng","ger-DE":"string"}> is incompatible with the declared type array<integer,string> of property $names.

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..

Loading history...
989
            'eng-US' => 'Somehow locked',
990
            'ger-DE' => 'Irgendwie gelockt',
991
        );
992
        $updateStateStruct->descriptions = array(
0 ignored issues
show
Documentation Bug introduced by
It seems like array('eng-US' => 'The o...-DE' => 'Sindelfingen') of type array<string,string,{"en...ng","ger-DE":"string"}> is incompatible with the declared type array<integer,string> of property $descriptions.

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..

Loading history...
993
            'eng-US' => 'The object is somehow locked',
994
            'ger-DE' => 'Sindelfingen',
995
        );
996
997
        // This call will fail because state with
998
        // 'not_locked' identifier already exists
999
        $objectStateService->updateObjectState(
1000
            $loadedObjectState,
1001
            $updateStateStruct
1002
        );
1003
    }
1004
1005
    /**
1006
     * testUpdateObjectStateStructValues.
1007
     *
1008
     * @param array $testData
1009
     *
1010
     *
1011
     * @depends testUpdateObjectState
1012
     */
1013
    public function testUpdateObjectStateStructValues(array $testData)
1014
    {
1015
        list(
1016
            $loadedObjectState,
1017
            $updateStateStruct,
1018
            $updatedObjectState
1019
        ) = $testData;
1020
1021
        $this->assertPropertiesCorrect(
1022
            array(
1023
                'id' => $loadedObjectState->id,
1024
                'identifier' => $updateStateStruct->identifier,
1025
                'priority' => $loadedObjectState->priority,
1026
                'defaultLanguageCode' => $updateStateStruct->defaultLanguageCode,
1027
                'languageCodes' => array('eng-US', 'ger-DE'),
1028
                'names' => $updateStateStruct->names,
1029
                'descriptions' => $updateStateStruct->descriptions,
1030
            ),
1031
            $updatedObjectState
1032
        );
1033
1034
        $this->assertEquals(
1035
            $loadedObjectState->getObjectStateGroup(),
1036
            $updatedObjectState->getObjectStateGroup()
1037
        );
1038
    }
1039
1040
    /**
1041
     * Test for the setPriorityOfObjectState() method.
1042
     *
1043
     *
1044
     * @see \eZ\Publish\API\Repository\ObjectStateService::setPriorityOfObjectState()
1045
     * @depends testLoadObjectState
1046
     */
1047 View Code Duplication
    public function testSetPriorityOfObjectState()
1048
    {
1049
        $repository = $this->getRepository();
1050
1051
        $objectStateId = $this->generateId('objectstate', 1);
1052
        /* BEGIN: Use Case */
1053
        // $objectStateId contains the ID of the "not_locked" state
1054
        $objectStateService = $repository->getObjectStateService();
1055
1056
        $initiallyLoadedObjectState = $objectStateService->loadObjectState(
1057
            $objectStateId
1058
        );
1059
1060
        // Sets the given priority on $initiallyLoadedObjectState
1061
        $objectStateService->setPriorityOfObjectState(
1062
            $initiallyLoadedObjectState,
1063
            23
1064
        );
1065
        // $loadObjectState now has the priority 1, since object state
1066
        // priorities are always made sequential
1067
        $loadedObjectState = $objectStateService->loadObjectState(
1068
            $objectStateId
1069
        );
1070
        /* END: Use Case */
1071
1072
        $this->assertInstanceOf(
1073
            'eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectState',
1074
            $loadedObjectState
1075
        );
1076
        $this->assertEquals(1, $loadedObjectState->priority);
1077
    }
1078
1079
    /**
1080
     * Test for the getContentState() method.
1081
     *
1082
     *
1083
     * @see \eZ\Publish\API\Repository\ObjectStateService::getContentState()
1084
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
1085
     * @depends testLoadObjectState
1086
     */
1087
    public function testGetContentState()
1088
    {
1089
        $repository = $this->getRepository();
1090
1091
        $anonymousUserId = $this->generateId('user', 10);
1092
        $ezLockObjectStateGroupId = $this->generateId('objectstategroup', 2);
1093
        /* BEGIN: Use Case */
1094
        // $anonymousUserId is the content ID of "Anonymous User"
1095
        $contentService = $repository->getContentService();
1096
        $objectStateService = $repository->getObjectStateService();
1097
1098
        $contentInfo = $contentService->loadContentInfo($anonymousUserId);
1099
1100
        $ezLockObjectStateGroup = $objectStateService->loadObjectStateGroup(
1101
            $ezLockObjectStateGroupId
1102
        );
1103
1104
        // Loads the state of $contentInfo in the "ez_lock" object state group
1105
        $ezLockObjectState = $objectStateService->getContentState(
1106
            $contentInfo,
1107
            $ezLockObjectStateGroup
1108
        );
1109
        /* END: Use Case */
1110
1111
        $this->assertInstanceOf(
1112
            'eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectState',
1113
            $ezLockObjectState
1114
        );
1115
        $this->assertEquals('not_locked', $ezLockObjectState->identifier);
1116
    }
1117
1118
    /**
1119
     * testGetInitialObjectState.
1120
     *
1121
     *
1122
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
1123
     * @depends testLoadObjectState
1124
     */
1125
    public function testGetInitialObjectState()
1126
    {
1127
        $repository = $this->getRepository();
1128
        $objectStateService = $repository->getObjectStateService();
1129
1130
        // Create object state group with custom state
1131
        $createdStateGroups = $this->createObjectStateGroups();
1132
1133
        $customObjectStateGroupId = $createdStateGroups[1]->id;
1134
        $anonymousUserId = $this->generateId('user', 10);
1135
1136
        $customGroup = $objectStateService->loadObjectStateGroup(
1137
            $customObjectStateGroupId
1138
        );
1139
1140
        $objectStateCreateStruct = $objectStateService->newObjectStateCreateStruct(
1141
            'sindelfingen'
1142
        );
1143
        $objectStateCreateStruct->priority = 1;
1144
        $objectStateCreateStruct->defaultLanguageCode = 'eng-US';
1145
        $objectStateCreateStruct->names = array('eng-US' => 'Sindelfingen');
0 ignored issues
show
Documentation Bug introduced by
It seems like array('eng-US' => 'Sindelfingen') of type array<string,string,{"eng-US":"string"}> is incompatible with the declared type array<integer,string> of property $names.

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..

Loading history...
1146
1147
        $createdState = $objectStateService->createObjectState(
1148
            $customGroup,
1149
            $objectStateCreateStruct
1150
        );
1151
1152
        // Store state ID to be used
1153
        $customObjectStateId = $createdState->id;
0 ignored issues
show
Unused Code introduced by
$customObjectStateId is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
1154
1155
        /* BEGIN: Use Case */
1156
        // $anonymousUserId is the content ID of "Anonymous User"
1157
        // $customObjectStateGroupId is the ID of a state group, from which no
1158
        // state has been assigned to $anonymousUserId, yet
1159
        $contentService = $repository->getContentService();
1160
        $objectStateService = $repository->getObjectStateService();
1161
1162
        $contentInfo = $contentService->loadContentInfo($anonymousUserId);
1163
1164
        $customObjectStateGroup = $objectStateService->loadObjectStateGroup(
1165
            $customObjectStateGroupId
1166
        );
1167
1168
        // Loads the initial state of the custom state group
1169
        $initialObjectState = $objectStateService->getContentState(
1170
            $contentInfo,
1171
            $customObjectStateGroup
1172
        );
1173
        /* END: Use Case */
1174
1175
        $this->assertInstanceOf(
1176
            'eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectState',
1177
            $initialObjectState
1178
        );
1179
        $this->assertEquals('sindelfingen', $initialObjectState->identifier);
1180
        $this->assertEquals(array('eng-US' => 'Sindelfingen'), $initialObjectState->names);
0 ignored issues
show
Documentation introduced by
The property names does not exist on object<eZ\Publish\API\Re...bjectState\ObjectState>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1181
        $this->assertEquals('eng-US', $initialObjectState->defaultLanguageCode);
1182
    }
1183
1184
    /**
1185
     * Test for the setContentState() method.
1186
     *
1187
     *
1188
     * @see \eZ\Publish\API\Repository\ObjectStateService::setContentState()
1189
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
1190
     * @depends testLoadObjectState
1191
     */
1192 View Code Duplication
    public function testSetContentState()
1193
    {
1194
        $repository = $this->getRepository();
1195
1196
        $anonymousUserId = $this->generateId('user', 10);
1197
        $ezLockObjectStateGroupId = $this->generateId('objectstategroup', 2);
1198
        $lockedObjectStateId = $this->generateId('objectstate', 2);
1199
        /* BEGIN: Use Case */
1200
        // $anonymousUserId is the content ID of "Anonymous User"
1201
        // $ezLockObjectStateGroupId contains the ID of the "ez_lock" object
1202
        // state group
1203
        // $lockedObjectStateId is the ID of the state "locked"
1204
        $contentService = $repository->getContentService();
1205
        $objectStateService = $repository->getObjectStateService();
1206
1207
        $contentInfo = $contentService->loadContentInfo($anonymousUserId);
1208
1209
        $ezLockObjectStateGroup = $objectStateService->loadObjectStateGroup(
1210
            $ezLockObjectStateGroupId
1211
        );
1212
        $lockedObjectState = $objectStateService->loadObjectState($lockedObjectStateId);
1213
1214
        // Sets the state of $contentInfo from "not_locked" to "locked"
1215
        $objectStateService->setContentState(
1216
            $contentInfo,
1217
            $ezLockObjectStateGroup,
1218
            $lockedObjectState
1219
        );
1220
        /* END: Use Case */
1221
1222
        $ezLockObjectState = $objectStateService->getContentState(
1223
            $contentInfo,
1224
            $ezLockObjectStateGroup
1225
        );
1226
1227
        $this->assertEquals('locked', $ezLockObjectState->identifier);
1228
    }
1229
1230
    /**
1231
     * Test for the setContentState() method.
1232
     *
1233
     *
1234
     * @see \eZ\Publish\API\Repository\ObjectStateService::setContentState()
1235
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1236
     * @depends testSetContentState
1237
     */
1238
    public function testSetContentStateThrowsInvalidArgumentExceptioon()
1239
    {
1240
        $repository = $this->getRepository();
1241
1242
        $createdStateGroups = $this->createObjectStateGroups();
1243
1244
        $anonymousUserId = $this->generateId('user', 10);
1245
        $differentObjectStateGroupId = $createdStateGroups[1]->id;
1246
        $lockedObjectStateId = $this->generateId('objectstate', 2);
1247
1248
        /* BEGIN: Use Case */
1249
        // $anonymousUserId is the content ID of "Anonymous User"
1250
        // $differentObjectStateGroupId contains the ID of an object state
1251
        // group which does not contain $lockedObjectStateId
1252
        // $lockedObjectStateId is the ID of the state "locked"
1253
        $contentService = $repository->getContentService();
1254
        $objectStateService = $repository->getObjectStateService();
1255
1256
        $contentInfo = $contentService->loadContentInfo($anonymousUserId);
1257
1258
        $differentObjectStateGroup = $objectStateService->loadObjectStateGroup(
1259
            $differentObjectStateGroupId
1260
        );
1261
        $lockedObjectState = $objectStateService->loadObjectState($lockedObjectStateId);
1262
1263
        // Throws an invalid argument exception since $lockedObjectState does
1264
        // not belong to $differentObjectStateGroup
1265
        $objectStateService->setContentState(
1266
            $contentInfo,
1267
            $differentObjectStateGroup,
1268
            $lockedObjectState
1269
        );
1270
        /* END: Use Case */
1271
    }
1272
1273
    /**
1274
     * Test for the getContentCount() method.
1275
     *
1276
     *
1277
     * @see \eZ\Publish\API\Repository\ObjectStateService::getContentCount()
1278
     * @depends testLoadObjectState
1279
     */
1280 View Code Duplication
    public function testGetContentCount()
1281
    {
1282
        $repository = $this->getRepository();
1283
1284
        $notLockedObjectStateId = $this->generateId('objectstate', 1);
1285
        /* BEGIN: Use Case */
1286
        // $notLockedObjectStateId is the ID of the state "not_locked"
1287
        $objectStateService = $repository->getObjectStateService();
1288
1289
        $notLockedObjectState = $objectStateService->loadObjectState($notLockedObjectStateId);
1290
1291
        $objectCount = $objectStateService->getContentCount($notLockedObjectState);
1292
        /* END: Use Case */
1293
1294
        $this->assertEquals(18, $objectCount);
1295
    }
1296
1297
    /**
1298
     * Test for the deleteObjectState() method.
1299
     *
1300
     *
1301
     * @see \eZ\Publish\API\Repository\ObjectStateService::deleteObjectState()
1302
     * @depends testLoadObjectState
1303
     */
1304 View Code Duplication
    public function testDeleteObjectState()
1305
    {
1306
        $repository = $this->getRepository();
1307
1308
        $notLockedObjectStateId = $this->generateId('objectstate', 1);
1309
        $lockedObjectStateId = $this->generateId('objectstate', 2);
1310
        /* BEGIN: Use Case */
1311
        // $notLockedObjectStateId is the ID of the state "not_locked"
1312
        $objectStateService = $repository->getObjectStateService();
1313
1314
        $notLockedObjectState = $objectStateService->loadObjectState($notLockedObjectStateId);
1315
1316
        // Deletes the object state and sets all objects, which where in that
1317
        // state, to the first state of the same object state group
1318
        $objectStateService->deleteObjectState($notLockedObjectState);
1319
        /* END: Use Case */
1320
1321
        $lockedObjectState = $objectStateService->loadObjectState($lockedObjectStateId);
1322
1323
        // All objects transferred
1324
        $this->assertEquals(
1325
            18,
1326
            $objectStateService->getContentCount($lockedObjectState)
1327
        );
1328
    }
1329
1330
    /**
1331
     * Test for the deleteObjectStateGroup() method.
1332
     *
1333
     *
1334
     * @see \eZ\Publish\API\Repository\ObjectStateService::deleteObjectStateGroup()
1335
     * @depends testLoadObjectStateGroup
1336
     */
1337
    public function testDeleteObjectStateGroup()
1338
    {
1339
        $repository = $this->getRepository();
1340
1341
        $objectStateGroupId = $this->generateId('objectstategroup', 2);
1342
        /* BEGIN: Use Case */
1343
        // $objectStateGroupId contains the ID of the standard object state
1344
        // group ez_lock.
1345
        $objectStateService = $repository->getObjectStateService();
1346
1347
        $loadedObjectStateGroup = $objectStateService->loadObjectStateGroup(
1348
            $objectStateGroupId
1349
        );
1350
1351
        $objectStateService->deleteObjectStateGroup($loadedObjectStateGroup);
1352
        /* END: Use Case */
1353
1354
        try {
1355
            $objectStateService->loadObjectStateGroup($objectStateGroupId);
1356
            $this->fail(
1357
                sprintf(
1358
                    'ObjectStateGroup with ID "%s" not deleted.',
1359
                    $objectStateGroupId
1360
                )
1361
            );
1362
        } catch (NotFoundException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
1363
        }
1364
    }
1365
}
1366