Code Duplication    Length = 18-22 lines in 3 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/URLServiceAuthorizationTest.php 1 location

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

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

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