Code Duplication    Length = 22-29 lines in 5 locations

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

@@ 438-466 (lines=29) @@
435
     * @see \eZ\Publish\API\Repository\RoleService::createRole()
436
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewRoleCreateStruct
437
     */
438
    public function testCreateRoleInTransactionWithRollback()
439
    {
440
        $repository = $this->getRepository();
441
442
        /* BEGIN: Use Case */
443
444
        $roleService = $repository->getRoleService();
445
446
        $repository->beginTransaction();
447
448
        $roleCreate = $roleService->newRoleCreateStruct('roleName');
449
450
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
451
        // $roleCreate->mainLanguageCode = 'eng-US';
452
453
        $createdRoleId = $roleService->createRole($roleCreate)->id;
454
455
        $repository->rollback();
456
457
        try {
458
            // This call will fail with a "NotFoundException"
459
            $role = $roleService->loadRole($createdRoleId);
460
        } catch (NotFoundException $e) {
461
            return;
462
        }
463
        /* END: Use Case */
464
465
        $this->fail('Role object still exists after rollback.');
466
    }
467
468
    /**
469
     * Test for the createRoleDraft() method.
@@ 474-502 (lines=29) @@
471
     * @see \eZ\Publish\API\Repository\RoleService::createRoleDraft()
472
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewRoleCreateStruct
473
     */
474
    public function testCreateRoleDraftInTransactionWithRollback()
475
    {
476
        $repository = $this->getRepository();
477
478
        /* BEGIN: Use Case */
479
480
        $roleService = $repository->getRoleService();
481
482
        $repository->beginTransaction();
483
484
        $roleCreate = $roleService->newRoleCreateStruct('roleName');
485
486
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
487
        // $roleCreate->mainLanguageCode = 'eng-US';
488
489
        $createdRoleId = $roleService->createRole($roleCreate)->id;
490
491
        $repository->rollback();
492
493
        try {
494
            // This call will fail with a "NotFoundException"
495
            $role = $roleService->loadRoleDraft($createdRoleId);
496
        } catch (NotFoundException $e) {
497
            return;
498
        }
499
        /* END: Use Case */
500
501
        $this->fail('Role draft object still exists after rollback.');
502
    }
503
504
    /**
505
     * Test for the loadRole() method.
@@ 510-531 (lines=22) @@
507
     * @see \eZ\Publish\API\Repository\RoleService::loadRole()
508
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRole
509
     */
510
    public function testLoadRole()
511
    {
512
        $repository = $this->getRepository();
513
514
        /* BEGIN: Use Case */
515
516
        $roleService = $repository->getRoleService();
517
        $roleCreate = $roleService->newRoleCreateStruct('roleName');
518
519
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
520
        // $roleCreate->mainLanguageCode = 'eng-US';
521
522
        $roleDraft = $roleService->createRole($roleCreate);
523
        $roleService->publishRoleDraft($roleDraft);
524
525
        // Load the newly created role by its ID
526
        $role = $roleService->loadRole($roleDraft->id);
527
528
        /* END: Use Case */
529
530
        $this->assertEquals('roleName', $role->identifier);
531
    }
532
533
    /**
534
     * Test for the loadRoleDraft() method.
@@ 656-677 (lines=22) @@
653
     * @see \eZ\Publish\API\Repository\RoleService::loadRoleByIdentifier()
654
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRole
655
     */
656
    public function testLoadRoleByIdentifier()
657
    {
658
        $repository = $this->getRepository();
659
660
        /* BEGIN: Use Case */
661
662
        $roleService = $repository->getRoleService();
663
        $roleCreate = $roleService->newRoleCreateStruct('roleName');
664
665
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
666
        // $roleCreate->mainLanguageCode = 'eng-US';
667
668
        $roleDraft = $roleService->createRole($roleCreate);
669
        $roleService->publishRoleDraft($roleDraft);
670
671
        // Load the newly created role by its identifier
672
        $role = $roleService->loadRoleByIdentifier('roleName');
673
674
        /* END: Use Case */
675
676
        $this->assertEquals('roleName', $role->identifier);
677
    }
678
679
    /**
680
     * Test for the loadRoleByIdentifier() method.
@@ 707-735 (lines=29) @@
704
     * @see \eZ\Publish\API\Repository\RoleService::loadRoles()
705
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRole
706
     */
707
    public function testLoadRoles()
708
    {
709
        $repository = $this->getRepository();
710
711
        /* BEGIN: Use Case */
712
713
        // First create a custom role
714
        $roleService = $repository->getRoleService();
715
        $roleCreate = $roleService->newRoleCreateStruct('roleName');
716
717
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
718
        // $roleCreate->mainLanguageCode = 'eng-US';
719
720
        $roleDraft = $roleService->createRole($roleCreate);
721
        $roleService->publishRoleDraft($roleDraft);
722
723
        // Now load all available roles
724
        $roles = $roleService->loadRoles();
725
726
        foreach ($roles as $role) {
727
            if ($role->identifier === 'roleName') {
728
                break;
729
            }
730
        }
731
732
        /* END: Use Case */
733
734
        $this->assertEquals('roleName', $role->identifier);
735
    }
736
737
    /**
738
     * Test for the loadRoles() method.