Code Duplication    Length = 22-29 lines in 5 locations

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

@@ 558-579 (lines=22) @@
555
     * @see \eZ\Publish\API\Repository\RoleService::loadRoleByIdentifier()
556
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRole
557
     */
558
    public function testLoadRoleByIdentifier()
559
    {
560
        $repository = $this->getRepository();
561
562
        /* BEGIN: Use Case */
563
564
        $roleService = $repository->getRoleService();
565
        $roleCreate = $roleService->newRoleCreateStruct('roleName');
566
567
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
568
        // $roleCreate->mainLanguageCode = 'eng-US';
569
570
        $roleDraft = $roleService->createRole($roleCreate);
571
        $roleService->publishRoleDraft($roleDraft);
572
573
        // Load the newly created role by its identifier
574
        $role = $roleService->loadRoleByIdentifier('roleName');
575
576
        /* END: Use Case */
577
578
        $this->assertEquals('roleName', $role->identifier);
579
    }
580
581
    /**
582
     * Test for the loadRoleByIdentifier() method.
@@ 341-369 (lines=29) @@
338
     * @see \eZ\Publish\API\Repository\RoleService::createRole()
339
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewRoleCreateStruct
340
     */
341
    public function testCreateRoleInTransactionWithRollback()
342
    {
343
        $repository = $this->getRepository();
344
345
        /* BEGIN: Use Case */
346
347
        $roleService = $repository->getRoleService();
348
349
        $repository->beginTransaction();
350
351
        $roleCreate = $roleService->newRoleCreateStruct('roleName');
352
353
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
354
        // $roleCreate->mainLanguageCode = 'eng-US';
355
356
        $createdRoleId = $roleService->createRole($roleCreate)->id;
357
358
        $repository->rollback();
359
360
        try {
361
            // This call will fail with a "NotFoundException"
362
            $role = $roleService->loadRole($createdRoleId);
363
        } catch (NotFoundException $e) {
364
            return;
365
        }
366
        /* END: Use Case */
367
368
        $this->fail('Role object still exists after rollback.');
369
    }
370
371
    /**
372
     * Test for the createRoleDraft() method.
@@ 377-405 (lines=29) @@
374
     * @see \eZ\Publish\API\Repository\RoleService::createRoleDraft()
375
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewRoleCreateStruct
376
     */
377
    public function testCreateRoleDraftInTransactionWithRollback()
378
    {
379
        $repository = $this->getRepository();
380
381
        /* BEGIN: Use Case */
382
383
        $roleService = $repository->getRoleService();
384
385
        $repository->beginTransaction();
386
387
        $roleCreate = $roleService->newRoleCreateStruct('roleName');
388
389
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
390
        // $roleCreate->mainLanguageCode = 'eng-US';
391
392
        $createdRoleId = $roleService->createRole($roleCreate)->id;
393
394
        $repository->rollback();
395
396
        try {
397
            // This call will fail with a "NotFoundException"
398
            $role = $roleService->loadRoleDraft($createdRoleId);
399
        } catch (NotFoundException $e) {
400
            return;
401
        }
402
        /* END: Use Case */
403
404
        $this->fail('Role draft object still exists after rollback.');
405
    }
406
407
    /**
408
     * Test for the loadRole() method.
@@ 413-434 (lines=22) @@
410
     * @see \eZ\Publish\API\Repository\RoleService::loadRole()
411
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRole
412
     */
413
    public function testLoadRole()
414
    {
415
        $repository = $this->getRepository();
416
417
        /* BEGIN: Use Case */
418
419
        $roleService = $repository->getRoleService();
420
        $roleCreate = $roleService->newRoleCreateStruct('roleName');
421
422
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
423
        // $roleCreate->mainLanguageCode = 'eng-US';
424
425
        $roleDraft = $roleService->createRole($roleCreate);
426
        $roleService->publishRoleDraft($roleDraft);
427
428
        // Load the newly created role by its ID
429
        $role = $roleService->loadRole($roleDraft->id);
430
431
        /* END: Use Case */
432
433
        $this->assertEquals('roleName', $role->identifier);
434
    }
435
436
    /**
437
     * Test for the loadRoleDraft() method.
@@ 608-636 (lines=29) @@
605
     * @see \eZ\Publish\API\Repository\RoleService::loadRoles()
606
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRole
607
     */
608
    public function testLoadRoles()
609
    {
610
        $repository = $this->getRepository();
611
612
        /* BEGIN: Use Case */
613
614
        // First create a custom role
615
        $roleService = $repository->getRoleService();
616
        $roleCreate = $roleService->newRoleCreateStruct('roleName');
617
618
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
619
        // $roleCreate->mainLanguageCode = 'eng-US';
620
621
        $roleDraft = $roleService->createRole($roleCreate);
622
        $roleService->publishRoleDraft($roleDraft);
623
624
        // Now load all available roles
625
        $roles = $roleService->loadRoles();
626
627
        foreach ($roles as $role) {
628
            if ($role->identifier === 'roleName') {
629
                break;
630
            }
631
        }
632
633
        /* END: Use Case */
634
635
        $this->assertEquals('roleName', $role->identifier);
636
    }
637
638
    /**
639
     * Test for the loadRoles() method.