Code Duplication    Length = 22-29 lines in 4 locations

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

@@ 457-485 (lines=29) @@
454
     * @see \eZ\Publish\API\Repository\RoleService::createRole()
455
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewRoleCreateStruct
456
     */
457
    public function testCreateRoleInTransactionWithRollback()
458
    {
459
        $repository = $this->getRepository();
460
461
        /* BEGIN: Use Case */
462
463
        $roleService = $repository->getRoleService();
464
465
        $repository->beginTransaction();
466
467
        $roleCreate = $roleService->newRoleCreateStruct('roleName');
468
469
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
470
        // $roleCreate->mainLanguageCode = 'eng-US';
471
472
        $createdRoleId = $roleService->createRole($roleCreate)->id;
473
474
        $repository->rollback();
475
476
        try {
477
            // This call will fail with a "NotFoundException"
478
            $role = $roleService->loadRole($createdRoleId);
479
        } catch (NotFoundException $e) {
480
            return;
481
        }
482
        /* END: Use Case */
483
484
        $this->fail('Role object still exists after rollback.');
485
    }
486
487
    /**
488
     * Test for the createRoleDraft() method.
@@ 493-521 (lines=29) @@
490
     * @see \eZ\Publish\API\Repository\RoleService::createRoleDraft()
491
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewRoleCreateStruct
492
     */
493
    public function testCreateRoleDraftInTransactionWithRollback()
494
    {
495
        $repository = $this->getRepository();
496
497
        /* BEGIN: Use Case */
498
499
        $roleService = $repository->getRoleService();
500
501
        $repository->beginTransaction();
502
503
        $roleCreate = $roleService->newRoleCreateStruct('roleName');
504
505
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
506
        // $roleCreate->mainLanguageCode = 'eng-US';
507
508
        $createdRoleId = $roleService->createRole($roleCreate)->id;
509
510
        $repository->rollback();
511
512
        try {
513
            // This call will fail with a "NotFoundException"
514
            $role = $roleService->loadRoleDraft($createdRoleId);
515
        } catch (NotFoundException $e) {
516
            return;
517
        }
518
        /* END: Use Case */
519
520
        $this->fail('Role draft object still exists after rollback.');
521
    }
522
523
    /**
524
     * Test for the copyRole() method.
@@ 649-670 (lines=22) @@
646
     * @see \eZ\Publish\API\Repository\RoleService::loadRole()
647
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRole
648
     */
649
    public function testLoadRole()
650
    {
651
        $repository = $this->getRepository();
652
653
        /* BEGIN: Use Case */
654
655
        $roleService = $repository->getRoleService();
656
        $roleCreate = $roleService->newRoleCreateStruct('roleName');
657
658
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
659
        // $roleCreate->mainLanguageCode = 'eng-US';
660
661
        $roleDraft = $roleService->createRole($roleCreate);
662
        $roleService->publishRoleDraft($roleDraft);
663
664
        // Load the newly created role by its ID
665
        $role = $roleService->loadRole($roleDraft->id);
666
667
        /* END: Use Case */
668
669
        $this->assertEquals('roleName', $role->identifier);
670
    }
671
672
    /**
673
     * Test for the loadRoleDraft() method.
@@ 795-816 (lines=22) @@
792
     * @see \eZ\Publish\API\Repository\RoleService::loadRoleByIdentifier()
793
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRole
794
     */
795
    public function testLoadRoleByIdentifier()
796
    {
797
        $repository = $this->getRepository();
798
799
        /* BEGIN: Use Case */
800
801
        $roleService = $repository->getRoleService();
802
        $roleCreate = $roleService->newRoleCreateStruct('roleName');
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
        $roleService->publishRoleDraft($roleDraft);
809
810
        // Load the newly created role by its identifier
811
        $role = $roleService->loadRoleByIdentifier('roleName');
812
813
        /* END: Use Case */
814
815
        $this->assertEquals('roleName', $role->identifier);
816
    }
817
818
    /**
819
     * Test for the loadRoleByIdentifier() method.