Code Duplication    Length = 33-35 lines in 2 locations

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

@@ 1011-1043 (lines=33) @@
1008
     * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited
1009
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1010
     */
1011
    public function testCanUserWithTargetThrowsInvalidArgumentExceptionVariant()
1012
    {
1013
        $repository = $this->getRepository();
1014
1015
        /* BEGIN: Use Case */
1016
        $user = $this->createUserVersion1();
1017
1018
        // Set created user as current user
1019
        $repository->setCurrentUser($user);
1020
1021
        $contentTypeService = $repository->getContentTypeService();
1022
1023
        $contentType = $contentTypeService->loadContentTypeByIdentifier('forum');
1024
1025
        $contentService = $repository->getContentService();
1026
1027
        $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-US');
1028
        $contentCreateStruct->setField('name', 'My awesome forum');
1029
        $contentCreateStruct->remoteId = 'abcdef0123456789abcdef0123456789';
1030
        $contentCreateStruct->alwaysAvailable = true;
1031
1032
        $urlAliasService = $repository->getURLAliasService();
1033
        $rootUrlAlias = $urlAliasService->lookUp('/');
1034
1035
        // This call will throw "InvalidArgumentException" because $rootAlias is not a valid target object
1036
        $canUser = $repository->canUser(
1037
            'content',
1038
            'create',
1039
            $contentCreateStruct,
1040
            $rootUrlAlias
1041
        );
1042
        /* END: Use Case */
1043
    }
1044
1045
    /**
1046
     * Test for the canUser() method.

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

@@ 713-747 (lines=35) @@
710
     * @depends eZ\Publish\API\Repository\Tests\PermissionResolverTest::testHasAccessLimited
711
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
712
     */
713
    public function testCanUserWithTargetThrowsInvalidArgumentException()
714
    {
715
        $repository = $this->getRepository();
716
717
        /* BEGIN: Use Case */
718
        $user = $this->createUserVersion1();
719
720
        $permissionResolver = $repository->getPermissionResolver();
721
722
        // Set created user as current user reference
723
        $permissionResolver->setCurrentUserReference($user);
724
725
        $contentTypeService = $repository->getContentTypeService();
726
727
        $contentType = $contentTypeService->loadContentTypeByIdentifier('forum');
728
729
        $contentService = $repository->getContentService();
730
731
        $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-US');
732
        $contentCreateStruct->setField('name', 'My awesome forum');
733
        $contentCreateStruct->remoteId = 'abcdef0123456789abcdef0123456789';
734
        $contentCreateStruct->alwaysAvailable = true;
735
736
        $urlAliasService = $repository->getURLAliasService();
737
        $rootUrlAlias = $urlAliasService->lookup('/');
738
739
        // This call will throw "InvalidArgumentException" because $rootAlias is not a valid target object
740
        $canUser = $permissionResolver->canUser(
741
            'content',
742
            'create',
743
            $contentCreateStruct,
744
            [$rootUrlAlias]
745
        );
746
        /* END: Use Case */
747
    }
748
749
    /**
750
     * Test for the canUser() method.