Code Duplication    Length = 24-27 lines in 5 locations

eZ/Publish/API/Repository/Tests/RoleServiceTest.php 4 locations

@@ 310-333 (lines=24) @@
307
     * @see \eZ\Publish\API\Repository\RoleService::createRoleDraft()
308
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewRoleCreateStruct
309
     */
310
    public function testCreateRoleDraft()
311
    {
312
        $repository = $this->getRepository();
313
314
        /* BEGIN: Use Case */
315
316
        $roleService = $repository->getRoleService();
317
        $roleCreate = $roleService->newRoleCreateStruct('roleName');
318
319
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
320
        // $roleCreate->mainLanguageCode = 'eng-US';
321
322
        $roleDraft = $roleService->createRole($roleCreate);
323
        $roleService->publishRoleDraft($roleDraft);
324
        $role = $roleService->loadRole($roleDraft->id);
325
        $newRoleDraft = $roleService->createRoleDraft($role);
326
327
        /* END: Use Case */
328
329
        $this->assertInstanceOf(
330
            '\\eZ\\Publish\\API\\Repository\\Values\\User\\RoleDraft',
331
            $newRoleDraft
332
        );
333
    }
334
335
    /**
336
     * Test for the createRole() method.
@@ 367-390 (lines=24) @@
364
     * @see \eZ\Publish\API\Repository\RoleService::createRoleDraft()
365
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleDraft
366
     */
367
    public function testCreateRoleDraftThrowsInvalidArgumentException()
368
    {
369
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\InvalidArgumentException::class);
370
371
        $repository = $this->getRepository();
372
373
        /* BEGIN: Use Case */
374
375
        $roleService = $repository->getRoleService();
376
        $roleCreate = $roleService->newRoleCreateStruct('Editor');
377
378
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
379
        // $roleCreate->mainLanguageCode = 'eng-US';
380
381
        $roleDraft = $roleService->createRole($roleCreate);
382
        $roleService->publishRoleDraft($roleDraft);
383
        $role = $roleService->loadRole($roleDraft->id);
384
        $roleService->createRoleDraft($role); // First role draft
385
386
        // This call will fail with an InvalidArgumentException, because there is already a draft
387
        $roleService->createRoleDraft($role);
388
389
        /* END: Use Case */
390
    }
391
392
    /**
393
     * Test for the createRole() method.
@@ 830-853 (lines=24) @@
827
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewRoleUpdateStruct
828
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleDraft
829
     */
830
    public function testUpdateRoleDraft()
831
    {
832
        $repository = $this->getRepository();
833
834
        /* BEGIN: Use Case */
835
        $roleService = $repository->getRoleService();
836
        $roleCreate = $roleService->newRoleCreateStruct('newRole');
837
838
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
839
        // $roleCreate->mainLanguageCode = 'eng-US';
840
841
        $roleDraft = $roleService->createRole($roleCreate);
842
843
        $roleUpdate = $roleService->newRoleUpdateStruct();
844
        $roleUpdate->identifier = 'updatedRole';
845
846
        $updatedRole = $roleService->updateRoleDraft($roleDraft, $roleUpdate);
847
        /* END: Use Case */
848
849
        // Now verify that our change was saved
850
        $role = $roleService->loadRoleDraft($updatedRole->id);
851
852
        $this->assertEquals($role->identifier, 'updatedRole');
853
    }
854
855
    /**
856
     * Test for the updateRole() method.
@@ 861-884 (lines=24) @@
858
     * @see \eZ\Publish\API\Repository\RoleService::updateRole()
859
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testUpdateRole
860
     */
861
    public function testUpdateRoleThrowsInvalidArgumentException()
862
    {
863
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\InvalidArgumentException::class);
864
865
        $repository = $this->getRepository();
866
867
        /* BEGIN: Use Case */
868
        $roleService = $repository->getRoleService();
869
        $roleCreate = $roleService->newRoleCreateStruct('newRole');
870
871
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
872
        // $roleCreate->mainLanguageCode = 'eng-US';
873
874
        $roleDraft = $roleService->createRole($roleCreate);
875
        $roleService->publishRoleDraft($roleDraft);
876
        $role = $roleService->loadRole($roleDraft->id);
877
878
        $roleUpdate = $roleService->newRoleUpdateStruct();
879
        $roleUpdate->identifier = 'Editor';
880
881
        // This call will fail with an InvalidArgumentException, because Editor is a predefined role
882
        $roleService->updateRole($role, $roleUpdate);
883
        /* END: Use Case */
884
    }
885
886
    /**
887
     * Test for the updateRoleDraft() method.

eZ/Publish/API/Repository/Tests/RoleServiceAuthorizationTest.php 1 location

@@ 677-703 (lines=27) @@
674
     *
675
     * @return \eZ\Publish\API\Repository\Values\User\Role
676
     */
677
    private function createRole()
678
    {
679
        $repository = $this->getRepository();
680
681
        /* BEGIN: Inline */
682
        // Get the role service
683
        $roleService = $repository->getRoleService();
684
685
        // Get new policy create struct
686
        $policyCreate = $roleService->newPolicyCreateStruct('content', '*');
687
688
        // Get a role create struct instance and set properties
689
        $roleCreate = $roleService->newRoleCreateStruct('testRole');
690
691
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
692
        // $roleCreate->mainLanguageCode = 'eng-GB';
693
694
        $roleCreate->addPolicy($policyCreate);
695
696
        // Create a new role instance.
697
        $roleDraft = $roleService->createRole($roleCreate);
698
        $roleService->publishRoleDraft($roleDraft);
699
        $role = $roleService->loadRole($roleDraft->id);
700
        /* END: Inline */
701
702
        return $role;
703
    }
704
}
705