Code Duplication    Length = 24-27 lines in 4 locations

eZ/Publish/API/Repository/Tests/RoleServiceTest.php 3 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.
@@ 796-819 (lines=24) @@
793
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewRoleUpdateStruct
794
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleDraft
795
     */
796
    public function testUpdateRoleDraft()
797
    {
798
        $repository = $this->getRepository();
799
800
        /* BEGIN: Use Case */
801
        $roleService = $repository->getRoleService();
802
        $roleCreate = $roleService->newRoleCreateStruct('newRole');
803
804
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
805
        // $roleCreate->mainLanguageCode = 'eng-US';
806
807
        $roleDraft = $roleService->createRole($roleCreate);
808
809
        $roleUpdate = $roleService->newRoleUpdateStruct();
810
        $roleUpdate->identifier = 'updatedRole';
811
812
        $updatedRole = $roleService->updateRoleDraft($roleDraft, $roleUpdate);
813
        /* END: Use Case */
814
815
        // Now verify that our change was saved
816
        $role = $roleService->loadRoleDraft($updatedRole->id);
817
818
        $this->assertEquals($role->identifier, 'updatedRole');
819
    }
820
821
    /**
822
     * Test for the updateRoleDraft() method.

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

@@ 647-673 (lines=27) @@
644
     *
645
     * @return \eZ\Publish\API\Repository\Values\User\Role
646
     */
647
    private function createRole()
648
    {
649
        $repository = $this->getRepository();
650
651
        /* BEGIN: Inline */
652
        // Get the role service
653
        $roleService = $repository->getRoleService();
654
655
        // Get new policy create struct
656
        $policyCreate = $roleService->newPolicyCreateStruct('content', '*');
657
658
        // Get a role create struct instance and set properties
659
        $roleCreate = $roleService->newRoleCreateStruct('testRole');
660
661
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
662
        // $roleCreate->mainLanguageCode = 'eng-GB';
663
664
        $roleCreate->addPolicy($policyCreate);
665
666
        // Create a new role instance.
667
        $roleDraft = $roleService->createRole($roleCreate);
668
        $roleService->publishRoleDraft($roleDraft);
669
        $role = $roleService->loadRole($roleDraft->id);
670
        /* END: Inline */
671
672
        return $role;
673
    }
674
}
675