Code Duplication    Length = 22-29 lines in 4 locations

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

@@ 455-483 (lines=29) @@
452
     * @see \eZ\Publish\API\Repository\RoleService::createRole()
453
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewRoleCreateStruct
454
     */
455
    public function testCreateRoleInTransactionWithRollback()
456
    {
457
        $repository = $this->getRepository();
458
459
        /* BEGIN: Use Case */
460
461
        $roleService = $repository->getRoleService();
462
463
        $repository->beginTransaction();
464
465
        $roleCreate = $roleService->newRoleCreateStruct('roleName');
466
467
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
468
        // $roleCreate->mainLanguageCode = 'eng-US';
469
470
        $createdRoleId = $roleService->createRole($roleCreate)->id;
471
472
        $repository->rollback();
473
474
        try {
475
            // This call will fail with a "NotFoundException"
476
            $role = $roleService->loadRole($createdRoleId);
477
        } catch (NotFoundException $e) {
478
            return;
479
        }
480
        /* END: Use Case */
481
482
        $this->fail('Role object still exists after rollback.');
483
    }
484
485
    /**
486
     * Test for the createRoleDraft() method.
@@ 491-519 (lines=29) @@
488
     * @see \eZ\Publish\API\Repository\RoleService::createRoleDraft()
489
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewRoleCreateStruct
490
     */
491
    public function testCreateRoleDraftInTransactionWithRollback()
492
    {
493
        $repository = $this->getRepository();
494
495
        /* BEGIN: Use Case */
496
497
        $roleService = $repository->getRoleService();
498
499
        $repository->beginTransaction();
500
501
        $roleCreate = $roleService->newRoleCreateStruct('roleName');
502
503
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
504
        // $roleCreate->mainLanguageCode = 'eng-US';
505
506
        $createdRoleId = $roleService->createRole($roleCreate)->id;
507
508
        $repository->rollback();
509
510
        try {
511
            // This call will fail with a "NotFoundException"
512
            $role = $roleService->loadRoleDraft($createdRoleId);
513
        } catch (NotFoundException $e) {
514
            return;
515
        }
516
        /* END: Use Case */
517
518
        $this->fail('Role draft object still exists after rollback.');
519
    }
520
521
    public function providerForCopyRoleTests(): array
522
    {
@@ 696-717 (lines=22) @@
693
     * @see \eZ\Publish\API\Repository\RoleService::loadRole()
694
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRole
695
     */
696
    public function testLoadRole()
697
    {
698
        $repository = $this->getRepository();
699
700
        /* BEGIN: Use Case */
701
702
        $roleService = $repository->getRoleService();
703
        $roleCreate = $roleService->newRoleCreateStruct('roleName');
704
705
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
706
        // $roleCreate->mainLanguageCode = 'eng-US';
707
708
        $roleDraft = $roleService->createRole($roleCreate);
709
        $roleService->publishRoleDraft($roleDraft);
710
711
        // Load the newly created role by its ID
712
        $role = $roleService->loadRole($roleDraft->id);
713
714
        /* END: Use Case */
715
716
        $this->assertEquals('roleName', $role->identifier);
717
    }
718
719
    /**
720
     * Test for the loadRoleDraft() method.
@@ 842-863 (lines=22) @@
839
     * @see \eZ\Publish\API\Repository\RoleService::loadRoleByIdentifier()
840
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRole
841
     */
842
    public function testLoadRoleByIdentifier()
843
    {
844
        $repository = $this->getRepository();
845
846
        /* BEGIN: Use Case */
847
848
        $roleService = $repository->getRoleService();
849
        $roleCreate = $roleService->newRoleCreateStruct('roleName');
850
851
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
852
        // $roleCreate->mainLanguageCode = 'eng-US';
853
854
        $roleDraft = $roleService->createRole($roleCreate);
855
        $roleService->publishRoleDraft($roleDraft);
856
857
        // Load the newly created role by its identifier
858
        $role = $roleService->loadRoleByIdentifier('roleName');
859
860
        /* END: Use Case */
861
862
        $this->assertEquals('roleName', $role->identifier);
863
    }
864
865
    /**
866
     * Test for the loadRoleByIdentifier() method.