Code Duplication    Length = 20-22 lines in 4 locations

eZ/Publish/API/Repository/Tests/ContentTypeServiceAuthorizationTest.php 3 locations

@@ 425-446 (lines=22) @@
422
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
423
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testCreateContentTypeDraft
424
     */
425
    public function testCreateContentTypeDraftThrowsUnauthorizedException()
426
    {
427
        $repository = $this->getRepository();
428
429
        $anonymousUserId = $this->generateId('user', 10);
430
        /* BEGIN: Use Case */
431
        // $anonymousUserId is the ID of the "Anonymous" user in a eZ
432
        // Publish demo installation.
433
        $contentTypeService = $repository->getContentTypeService();
434
435
        // Load the user service
436
        $userService = $repository->getUserService();
437
438
        // Set anonymous user
439
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
440
441
        $commentType = $contentTypeService->loadContentTypeByIdentifier('comment');
442
443
        // This call will fail with a "UnauthorizedException"
444
        $contentTypeService->createContentTypeDraft($commentType);
445
        /* END: Use Case */
446
    }
447
448
    /**
449
     * Test for the deleteContentType() method.
@@ 455-476 (lines=22) @@
452
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
453
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testDeleteContentType
454
     */
455
    public function testDeleteContentTypeThrowsUnauthorizedException()
456
    {
457
        $repository = $this->getRepository();
458
459
        $anonymousUserId = $this->generateId('user', 10);
460
        /* BEGIN: Use Case */
461
        // $anonymousUserId is the ID of the "Anonymous" user in a eZ
462
        // Publish demo installation.
463
        $contentTypeService = $repository->getContentTypeService();
464
465
        // Load the user service
466
        $userService = $repository->getUserService();
467
468
        // Set anonymous user
469
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
470
471
        $commentType = $contentTypeService->loadContentTypeByIdentifier('comment');
472
473
        // This call will fail with a "UnauthorizedException"
474
        $contentTypeService->deleteContentType($commentType);
475
        /* END: Use Case */
476
    }
477
478
    /**
479
     * Test for the copyContentType() method.
@@ 485-506 (lines=22) @@
482
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
483
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testCopyContentType
484
     */
485
    public function testCopyContentTypeThrowsUnauthorizedException()
486
    {
487
        $repository = $this->getRepository();
488
489
        $anonymousUserId = $this->generateId('user', 10);
490
        /* BEGIN: Use Case */
491
        // $anonymousUserId is the ID of the "Anonymous" user in a eZ
492
        // Publish demo installation.
493
        $contentTypeService = $repository->getContentTypeService();
494
495
        // Load the user service
496
        $userService = $repository->getUserService();
497
498
        // Set anonymous user
499
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
500
501
        $commentType = $contentTypeService->loadContentTypeByIdentifier('comment');
502
503
        // This call will fail with a "UnauthorizedException"
504
        $contentTypeService->copyContentType($commentType);
505
        /* END: Use Case */
506
    }
507
508
    /**
509
     * Test for the assignContentTypeGroup() method.

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

@@ 104-123 (lines=20) @@
101
     * @see \eZ\Publish\API\Repository\URLService::loadById
102
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
103
     */
104
    public function testLoadByUrlThrowsUnauthorizedException()
105
    {
106
        $repository = $this->getRepository();
107
108
        $anonymousUserId = $this->generateId('user', 10);
109
        $url = '/content/view/sitemap/2';
110
111
        /* BEGIN: Use Case */
112
        // $anonymousUserId is the ID of the "Anonymous" user in a eZ
113
        // Publish demo installation.
114
115
        $userService = $repository->getUserService();
116
        $urlService = $repository->getURLService();
117
118
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
119
120
        // This call will fail with an UnauthorizedException
121
        $urlService->loadByUrl($url);
122
        /* END: Use Case */
123
    }
124
}
125