Code Duplication    Length = 10-11 lines in 6 locations

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

@@ 108-118 (lines=11) @@
105
     * @see \eZ\Publish\API\Repository\ContentService::loadContentInfo()
106
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
107
     */
108
    public function testLoadContentInfoThrowsUnauthorizedException()
109
    {
110
        $contentId = $this->generateId('object', 10);
111
        $this->setRestrictedEditorUser();
112
113
        $this->expectException(UnauthorizedException::class);
114
        $this->expectExceptionMessageMatches('/\'read\' \'content\'/');
115
116
        // $contentId contains a content object ID not accessible for anonymous
117
        $this->contentService->loadContentInfo($contentId);
118
    }
119
120
    /**
121
     * Test for the sudo() method.
@@ 216-225 (lines=10) @@
213
     * @see \eZ\Publish\API\Repository\ContentService::loadVersionInfoById()
214
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfoById
215
     */
216
    public function testLoadVersionInfoByIdThrowsUnauthorizedException()
217
    {
218
        $anonymousUserId = $this->generateId('user', 10);
219
        $this->setRestrictedEditorUser();
220
221
        $this->expectException(UnauthorizedException::class);
222
        $this->expectExceptionMessageMatches('/\'read\' \'content\'/');
223
224
        $this->contentService->loadVersionInfoById($anonymousUserId);
225
    }
226
227
    /**
228
     * Test for the loadVersionInfoById() method.
@@ 233-242 (lines=10) @@
230
     * @see \eZ\Publish\API\Repository\ContentService::loadVersionInfoById($contentId, $versionNo)
231
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfoByIdWithSecondParameter
232
     */
233
    public function testLoadVersionInfoByIdThrowsUnauthorizedExceptionWithSecondParameter()
234
    {
235
        $anonymousUserId = $this->generateId('user', 10);
236
        $this->setRestrictedEditorUser();
237
238
        $this->expectException(UnauthorizedException::class);
239
        $this->expectExceptionMessageMatches('/\'read\' \'content\'/');
240
241
        $this->contentService->loadVersionInfoById($anonymousUserId, 2);
242
    }
243
244
    /**
245
     * Test for the loadVersionInfoById() method.
@@ 366-375 (lines=10) @@
363
     * @see \eZ\Publish\API\Repository\ContentService::loadContent()
364
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
365
     */
366
    public function testLoadContentThrowsUnauthorizedException()
367
    {
368
        $anonymousUserId = $this->generateId('user', 10);
369
        $this->setRestrictedEditorUser();
370
371
        $this->expectException(UnauthorizedException::class);
372
        $this->expectExceptionMessageMatches('/\'read\' \'content\'/');
373
374
        $this->contentService->loadContent($anonymousUserId);
375
    }
376
377
    /**
378
     * Test for the loadContent() method.
@@ 383-392 (lines=10) @@
380
     * @see \eZ\Publish\API\Repository\ContentService::loadContent($contentId, $languages)
381
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentWithPrioritizedLanguages
382
     */
383
    public function testLoadContentThrowsUnauthorizedExceptionWithSecondParameter()
384
    {
385
        $anonymousUserId = $this->generateId('user', 10);
386
        $this->setRestrictedEditorUser();
387
388
        $this->expectException(UnauthorizedException::class);
389
        $this->expectExceptionMessageMatches('/\'read\' \'content\'/');
390
391
        $this->contentService->loadContent($anonymousUserId, ['eng-US']);
392
    }
393
394
    /**
395
     * Test for the loadContent() method.
@@ 400-409 (lines=10) @@
397
     * @see \eZ\Publish\API\Repository\ContentService::loadContent($contentId, $languages, $versionNo)
398
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentWithThirdParameter
399
     */
400
    public function testLoadContentThrowsUnauthorizedExceptionWithThirdParameter()
401
    {
402
        $anonymousUserId = $this->generateId('user', 10);
403
        $this->setRestrictedEditorUser();
404
405
        $this->expectException(UnauthorizedException::class);
406
        $this->expectExceptionMessageMatches('/\'read\' \'content\'/');
407
408
        $this->contentService->loadContent($anonymousUserId, ['eng-US'], 2);
409
    }
410
411
    /**
412
     * Test for the loadContent() method on a draft.