Code Duplication    Length = 49-51 lines in 2 locations

eZ/Publish/API/Repository/Tests/PermissionServiceTest.php 1 location

@@ 465-515 (lines=51) @@
462
     * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentTypeService
463
     * @depends eZ\Publish\API\Repository\Tests\PermissionServiceTest::testHasAccessLimited
464
     */
465
    public function testCanUserWithTargetYes()
466
    {
467
        $repository = $this->getRepository();
468
469
        $homeLocationId = $this->generateId('location', 2);
470
471
        /* BEGIN: Use Case */
472
        // $homeLocationId contains the ID of the "Home" location
473
474
        $user = $this->createUserVersion1();
475
476
        $permissionService = $repository->getPermissionService();
477
478
        // Set created user as current user reference
479
        $permissionService->setCurrentUserReference($user);
480
481
        $contentTypeService = $repository->getContentTypeService();
482
483
        $contentType = $contentTypeService->loadContentTypeByIdentifier('forums');
484
485
        $contentService = $repository->getContentService();
486
487
        $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-US');
488
        $contentCreateStruct->setField('title', 'My awesome forums');
489
        $contentCreateStruct->remoteId = 'abcdef0123456789abcdef0123456789';
490
        $contentCreateStruct->alwaysAvailable = true;
491
492
        $locationService = $repository->getLocationService();
493
        $locationCreateStruct = $locationService->newLocationCreateStruct($homeLocationId);
494
495
        // This call will return true
496
        $canUser = $permissionService->canUser(
497
            'content',
498
            'create',
499
            $contentCreateStruct,
500
            $locationCreateStruct
501
        );
502
503
        // Performing an action having necessary permissions will succeed
504
        $contentDraft = $contentService->createContent(
505
            $contentCreateStruct,
506
            array($locationCreateStruct)
507
        );
508
        /* END: Use Case */
509
510
        $this->assertTrue($canUser);
511
        $this->assertEquals(
512
            'My awesome forums',
513
            $contentDraft->getFieldValue('title')->text
514
        );
515
    }
516
517
    /**
518
     * Test for the canUser() method.

eZ/Publish/API/Repository/Tests/RepositoryTest.php 1 location

@@ 736-784 (lines=49) @@
733
     * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentTypeService
734
     * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited
735
     */
736
    public function testCanUserWithTargetYes()
737
    {
738
        $repository = $this->getRepository();
739
740
        $homeLocationId = $this->generateId('location', 2);
741
742
        /* BEGIN: Use Case */
743
        // $homeLocationId contains the ID of the "Home" location
744
745
        $user = $this->createUserVersion1();
746
747
        // Set created user as current user
748
        $repository->setCurrentUser($user);
749
750
        $contentTypeService = $repository->getContentTypeService();
751
752
        $contentType = $contentTypeService->loadContentTypeByIdentifier('forums');
753
754
        $contentService = $repository->getContentService();
755
756
        $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-US');
757
        $contentCreateStruct->setField('title', 'My awesome forums');
758
        $contentCreateStruct->remoteId = 'abcdef0123456789abcdef0123456789';
759
        $contentCreateStruct->alwaysAvailable = true;
760
761
        $locationService = $repository->getLocationService();
762
        $locationCreateStruct = $locationService->newLocationCreateStruct($homeLocationId);
763
764
        // This call will return true
765
        $canUser = $repository->canUser(
766
            'content',
767
            'create',
768
            $contentCreateStruct,
769
            $locationCreateStruct
770
        );
771
772
        // Performing an action having necessary permissions will succeed
773
        $contentDraft = $contentService->createContent(
774
            $contentCreateStruct,
775
            array($locationCreateStruct)
776
        );
777
        /* END: Use Case */
778
779
        $this->assertTrue($canUser);
780
        $this->assertEquals(
781
            'My awesome forums',
782
            $contentDraft->getFieldValue('title')->text
783
        );
784
    }
785
786
    /**
787
     * Test for the canUser() method.