Code Duplication    Length = 33-35 lines in 2 locations

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

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

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

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