Code Duplication    Length = 20-22 lines in 4 locations

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

@@ 939-960 (lines=22) @@
936
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentDrafts
937
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentDrafts
938
     */
939
    public function testLoadContentDraftsThrowsUnauthorizedException()
940
    {
941
        $repository = $this->getRepository();
942
943
        $anonymousUserId = $this->generateId('user', 10);
944
        /* BEGIN: Use Case */
945
        // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish
946
        // demo installation
947
        $contentService = $repository->getContentService();
948
949
        // Load the user service
950
        $userService = $repository->getUserService();
951
952
        // Set anonymous user
953
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
954
955
        $this->expectException(UnauthorizedException::class);
956
        $this->expectExceptionMessageRegExp('/\'versionread\' \'content\'/');
957
958
        $contentService->loadContentDrafts();
959
        /* END: Use Case */
960
    }
961
962
    /**
963
     * Test for the loadContentDrafts() method.

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

@@ 186-207 (lines=22) @@
183
     * @depends eZ\Publish\API\Repository\Tests\TrashServiceTest::testEmptyTrash
184
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testLoadAnonymousUser
185
     */
186
    public function testEmptyTrashThrowsUnauthorizedException()
187
    {
188
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\UnauthorizedException::class);
189
190
        $repository = $this->getRepository();
191
        $trashService = $repository->getTrashService();
192
193
        $anonymousUserId = $this->generateId('user', 10);
194
        /* BEGIN: Use Case */
195
        // $anonymousUserId is the ID of the "Anonymous" user
196
        $this->createTrashItem();
197
198
        // Load user service
199
        $userService = $repository->getUserService();
200
201
        // Set "Anonymous" as current user
202
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
203
204
        // This call will fail with an "UnauthorizedException"
205
        $trashService->emptyTrash();
206
        /* END: Use Case */
207
    }
208
209
    /**
210
     * Test for the deleteTrashItem() method.

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

@@ 80-100 (lines=21) @@
77
     *
78
     * @see \eZ\Publish\API\Repository\URLService::loadById
79
     */
80
    public function testLoadByIdThrowsUnauthorizedException()
81
    {
82
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\UnauthorizedException::class);
83
84
        $repository = $this->getRepository();
85
86
        $anonymousUserId = $this->generateId('user', 10);
87
        $urlId = $this->generateId('url', 23);
88
        /* BEGIN: Use Case */
89
        // $anonymousUserId is the ID of the "Anonymous" user in a eZ
90
        // Publish demo installation.
91
92
        $userService = $repository->getUserService();
93
        $urlService = $repository->getURLService();
94
95
        $repository->getPermissionResolver()->setCurrentUserReference($userService->loadUser($anonymousUserId));
96
97
        // This call will fail with an UnauthorizedException
98
        $urlService->loadById($urlId);
99
        /* END: Use Case */
100
    }
101
102
    /**
103
     * Test for the loadByUrl() method.

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

@@ 30-49 (lines=20) @@
27
     * @see \eZ\Publish\API\Repository\URLWildcardService::create()
28
     * @depends eZ\Publish\API\Repository\Tests\URLWildcardServiceTest::testCreate
29
     */
30
    public function testCreateThrowsUnauthorizedException()
31
    {
32
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\UnauthorizedException::class);
33
34
        $repository = $this->getRepository();
35
36
        $anonymousUserId = $this->generateId('user', 10);
37
        /* BEGIN: Use Case */
38
        // $anonymousUserId is the ID of the "Anonymous" user in a eZ
39
        // Publish demo installation.
40
41
        $userService = $repository->getUserService();
42
        $urlWildcardService = $repository->getURLWildcardService();
43
44
        $repository->getPermissionResolver()->setCurrentUserReference($userService->loadUser($anonymousUserId));
45
46
        $this->expectException(UnauthorizedException::class);
47
        $urlWildcardService->create('/articles/*', '/content/{1}');
48
        /* END: Use Case */
49
    }
50
51
    /**
52
     * Test for the remove() method.