Code Duplication    Length = 22-27 lines in 4 locations

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

@@ 599-625 (lines=27) @@
596
     *
597
     * @return \eZ\Publish\API\Repository\Values\User\Role
598
     */
599
    private function createRole()
600
    {
601
        $repository = $this->getRepository();
602
603
        /* BEGIN: Inline */
604
        // Get the role service
605
        $roleService = $repository->getRoleService();
606
607
        // Get new policy create struct
608
        $policyCreate = $roleService->newPolicyCreateStruct('content', '*');
609
610
        // Get a role create struct instance and set properties
611
        $roleCreate = $roleService->newRoleCreateStruct('testRole');
612
613
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
614
        // $roleCreate->mainLanguageCode = 'eng-GB';
615
616
        $roleCreate->addPolicy($policyCreate);
617
618
        // Create a new role instance.
619
        $roleDraft = $roleService->createRole($roleCreate);
620
        $roleService->publishRoleDraft($roleDraft);
621
        $role = $roleService->loadRole($roleDraft->id);
622
        /* END: Inline */
623
624
        return $role;
625
    }
626
}
627

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

@@ 216-239 (lines=24) @@
213
     * @see \eZ\Publish\API\Repository\RoleService::createRoleDraft()
214
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewRoleCreateStruct
215
     */
216
    public function testCreateRoleDraft()
217
    {
218
        $repository = $this->getRepository();
219
220
        /* BEGIN: Use Case */
221
222
        $roleService = $repository->getRoleService();
223
        $roleCreate = $roleService->newRoleCreateStruct('roleName');
224
225
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
226
        // $roleCreate->mainLanguageCode = 'eng-US';
227
228
        $roleDraft = $roleService->createRole($roleCreate);
229
        $roleService->publishRoleDraft($roleDraft);
230
        $role = $roleService->loadRole($roleDraft->id);
231
        $newRoleDraft = $roleService->createRoleDraft($role);
232
233
        /* END: Use Case */
234
235
        $this->assertInstanceOf(
236
            '\\eZ\\Publish\\API\\Repository\\Values\\User\\RoleDraft',
237
            $newRoleDraft
238
        );
239
    }
240
241
    /**
242
     * Test for the createRole() method.
@@ 731-754 (lines=24) @@
728
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewRoleUpdateStruct
729
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleDraft
730
     */
731
    public function testUpdateRoleDraft()
732
    {
733
        $repository = $this->getRepository();
734
735
        /* BEGIN: Use Case */
736
        $roleService = $repository->getRoleService();
737
        $roleCreate = $roleService->newRoleCreateStruct('newRole');
738
739
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
740
        // $roleCreate->mainLanguageCode = 'eng-US';
741
742
        $roleDraft = $roleService->createRole($roleCreate);
743
744
        $roleUpdate = $roleService->newRoleUpdateStruct();
745
        $roleUpdate->identifier = 'updatedRole';
746
747
        $updatedRole = $roleService->updateRoleDraft($roleDraft, $roleUpdate);
748
        /* END: Use Case */
749
750
        // Now verify that our change was saved
751
        $role = $roleService->loadRoleDraft($updatedRole->id);
752
753
        $this->assertEquals($role->identifier, 'updatedRole');
754
    }
755
756
    /**
757
     * Test for the updateRole() method.
@@ 763-784 (lines=22) @@
760
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
761
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testUpdateRole
762
     */
763
    public function testUpdateRoleThrowsInvalidArgumentException()
764
    {
765
        $repository = $this->getRepository();
766
767
        /* BEGIN: Use Case */
768
        $roleService = $repository->getRoleService();
769
        $roleCreate = $roleService->newRoleCreateStruct('newRole');
770
771
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
772
        // $roleCreate->mainLanguageCode = 'eng-US';
773
774
        $roleDraft = $roleService->createRole($roleCreate);
775
        $roleService->publishRoleDraft($roleDraft);
776
        $role = $roleService->loadRole($roleDraft->id);
777
778
        $roleUpdate = $roleService->newRoleUpdateStruct();
779
        $roleUpdate->identifier = 'Editor';
780
781
        // This call will fail with an InvalidArgumentException, because Editor is a predefined role
782
        $roleService->updateRole($role, $roleUpdate);
783
        /* END: Use Case */
784
    }
785
786
    /**
787
     * Test for the updateRoleDraft() method.