Code Duplication    Length = 22-29 lines in 4 locations

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

@@ 436-464 (lines=29) @@
433
     * @see \eZ\Publish\API\Repository\RoleService::createRole()
434
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewRoleCreateStruct
435
     */
436
    public function testCreateRoleInTransactionWithRollback()
437
    {
438
        $repository = $this->getRepository();
439
440
        /* BEGIN: Use Case */
441
442
        $roleService = $repository->getRoleService();
443
444
        $repository->beginTransaction();
445
446
        $roleCreate = $roleService->newRoleCreateStruct('roleName');
447
448
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
449
        // $roleCreate->mainLanguageCode = 'eng-US';
450
451
        $createdRoleId = $roleService->createRole($roleCreate)->id;
452
453
        $repository->rollback();
454
455
        try {
456
            // This call will fail with a "NotFoundException"
457
            $role = $roleService->loadRole($createdRoleId);
458
        } catch (NotFoundException $e) {
459
            return;
460
        }
461
        /* END: Use Case */
462
463
        $this->fail('Role object still exists after rollback.');
464
    }
465
466
    /**
467
     * Test for the createRoleDraft() method.
@@ 472-500 (lines=29) @@
469
     * @see \eZ\Publish\API\Repository\RoleService::createRoleDraft()
470
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewRoleCreateStruct
471
     */
472
    public function testCreateRoleDraftInTransactionWithRollback()
473
    {
474
        $repository = $this->getRepository();
475
476
        /* BEGIN: Use Case */
477
478
        $roleService = $repository->getRoleService();
479
480
        $repository->beginTransaction();
481
482
        $roleCreate = $roleService->newRoleCreateStruct('roleName');
483
484
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
485
        // $roleCreate->mainLanguageCode = 'eng-US';
486
487
        $createdRoleId = $roleService->createRole($roleCreate)->id;
488
489
        $repository->rollback();
490
491
        try {
492
            // This call will fail with a "NotFoundException"
493
            $role = $roleService->loadRoleDraft($createdRoleId);
494
        } catch (NotFoundException $e) {
495
            return;
496
        }
497
        /* END: Use Case */
498
499
        $this->fail('Role draft object still exists after rollback.');
500
    }
501
502
    /**
503
     * Test for the loadRole() method.
@@ 508-529 (lines=22) @@
505
     * @see \eZ\Publish\API\Repository\RoleService::loadRole()
506
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRole
507
     */
508
    public function testLoadRole()
509
    {
510
        $repository = $this->getRepository();
511
512
        /* BEGIN: Use Case */
513
514
        $roleService = $repository->getRoleService();
515
        $roleCreate = $roleService->newRoleCreateStruct('roleName');
516
517
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
518
        // $roleCreate->mainLanguageCode = 'eng-US';
519
520
        $roleDraft = $roleService->createRole($roleCreate);
521
        $roleService->publishRoleDraft($roleDraft);
522
523
        // Load the newly created role by its ID
524
        $role = $roleService->loadRole($roleDraft->id);
525
526
        /* END: Use Case */
527
528
        $this->assertEquals('roleName', $role->identifier);
529
    }
530
531
    /**
532
     * Test for the loadRoleDraft() method.
@@ 654-675 (lines=22) @@
651
     * @see \eZ\Publish\API\Repository\RoleService::loadRoleByIdentifier()
652
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRole
653
     */
654
    public function testLoadRoleByIdentifier()
655
    {
656
        $repository = $this->getRepository();
657
658
        /* BEGIN: Use Case */
659
660
        $roleService = $repository->getRoleService();
661
        $roleCreate = $roleService->newRoleCreateStruct('roleName');
662
663
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
664
        // $roleCreate->mainLanguageCode = 'eng-US';
665
666
        $roleDraft = $roleService->createRole($roleCreate);
667
        $roleService->publishRoleDraft($roleDraft);
668
669
        // Load the newly created role by its identifier
670
        $role = $roleService->loadRoleByIdentifier('roleName');
671
672
        /* END: Use Case */
673
674
        $this->assertEquals('roleName', $role->identifier);
675
    }
676
677
    /**
678
     * Test for the loadRoleByIdentifier() method.