Code Duplication    Length = 36-36 lines in 2 locations

eZ/Publish/API/Repository/Tests/ContentServiceAuthorizationTest.php 2 locations

@@ 68-103 (lines=36) @@
65
     * @see \eZ\Publish\API\Repository\ContentService::createContent()
66
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent
67
     */
68
    public function testCreateContentThrowsUnauthorizedException()
69
    {
70
        if ($this->isVersion4()) {
71
            $this->markTestSkipped('This test requires eZ Publish 5');
72
        }
73
74
        $repository = $this->getRepository();
75
76
        $anonymousUserId = $this->generateId('user', 10);
77
        /* BEGIN: Use Case */
78
        // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish
79
        // demo installation
80
        // Load the user service
81
        $userService = $repository->getUserService();
82
83
        // Set anonymous user
84
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
85
86
        $contentTypeService = $repository->getContentTypeService();
87
88
        $contentType = $contentTypeService->loadContentTypeByIdentifier('forum');
89
90
        $contentService = $repository->getContentService();
91
92
        $contentCreate = $contentService->newContentCreateStruct($contentType, 'eng-US');
93
        $contentCreate->setField('name', 'Awesome Sindelfingen forum');
94
95
        $contentCreate->remoteId = 'abcdef0123456789abcdef0123456789';
96
        $contentCreate->alwaysAvailable = true;
97
98
        $this->expectException(UnauthorizedException::class);
99
        $this->expectExceptionMessageRegExp('/\'create\' \'content\'/');
100
101
        $contentService->createContent($contentCreate);
102
        /* END: Use Case */
103
    }
104
105
    /**
106
     * Test for the createContent() method.
@@ 1008-1043 (lines=36) @@
1005
     * @see \eZ\Publish\API\Repository\ContentService::updateContent()
1006
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent
1007
     */
1008
    public function testUpdateContentThrowsUnauthorizedException()
1009
    {
1010
        $repository = $this->getRepository();
1011
        $contentService = $repository->getContentService();
1012
1013
        $anonymousUserId = $this->generateId('user', 10);
1014
        /* BEGIN: Use Case */
1015
        // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish
1016
        // demo installation
1017
        // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish
1018
        // demo installation
1019
        $draftVersion2 = $this->createContentDraftVersion2();
1020
1021
        // Get VersionInfo instance
1022
        $versionInfo = $draftVersion2->getVersionInfo();
1023
1024
        // Load the user service
1025
        $userService = $repository->getUserService();
1026
1027
        // Set anonymous user
1028
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
1029
1030
        // Create an update struct and modify some fields
1031
        $contentUpdate = $contentService->newContentUpdateStruct();
1032
        $contentUpdate->setField('name', 'An awesome² story about ezp.');
1033
        $contentUpdate->setField('name', 'An awesome²³ story about ezp.', 'eng-GB');
1034
1035
        $contentUpdate->initialLanguageCode = 'eng-US';
1036
1037
        $this->expectException(UnauthorizedException::class);
1038
        /* TODO - the `content/edit` policy should be probably needed */
1039
        $this->expectExceptionMessageRegExp('/\'versionread\' \'content\'/');
1040
1041
        $contentService->updateContent($versionInfo, $contentUpdate);
1042
        /* END: Use Case */
1043
    }
1044
1045
    /**
1046
     * Test for the publishVersion() method.