Code Duplication    Length = 30-42 lines in 2 locations

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

@@ 67-108 (lines=42) @@
64
     * @see \eZ\Publish\API\Repository\ContentTypeService::updateContentTypeGroup()
65
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testUpdateContentTypeGroup
66
     */
67
    public function testUpdateContentTypeGroupThrowsUnauthorizedException()
68
    {
69
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\UnauthorizedException::class);
70
71
        $repository = $this->getRepository();
72
73
        $modifierId = $this->generateId('user', 42);
74
        $anonymousUserId = $this->generateId('user', 10);
75
        /* BEGIN: Use Case */
76
        // $anonymousUserId is the ID of the "Anonymous" user in a eZ
77
        // Publish demo installation.
78
        $userService = $repository->getUserService();
79
        $contentTypeService = $repository->getContentTypeService();
80
81
        $group = $contentTypeService->loadContentTypeGroupByIdentifier('Setup');
82
83
        $groupUpdate = $contentTypeService->newContentTypeGroupUpdateStruct();
84
85
        $groupUpdate->identifier = 'Teardown';
86
        // $modifierId is the ID of a random user
87
        $groupUpdate->modifierId = $modifierId;
88
        $groupUpdate->modificationDate = $this->createDateTime();
89
        /* @todo uncomment when support for multilingual names and descriptions is added EZP-24776
90
        $groupUpdate->mainLanguageCode = 'eng-GB';
91
92
        $groupUpdate->names = array(
93
            'eng-GB' => 'A name',
94
            'eng-US' => 'A name',
95
        );
96
        $groupUpdate->descriptions = array(
97
            'eng-GB' => 'A description',
98
            'eng-US' => 'A description',
99
        );
100
        */
101
102
        // Set anonymous user
103
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
104
105
        // This call will fail with a "UnauthorizedException"
106
        $contentTypeService->updateContentTypeGroup($group, $groupUpdate);
107
        /* END: Use Case */
108
    }
109
110
    /**
111
     * Test for the deleteContentTypeGroup() method.

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

@@ 93-122 (lines=30) @@
90
     * @see \eZ\Publish\API\Repository\SectionService::updateSection()
91
     * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testUpdateSection
92
     */
93
    public function testUpdateSectionThrowsUnauthorizedException()
94
    {
95
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\UnauthorizedException::class);
96
97
        $repository = $this->getRepository();
98
99
        $standardSectionId = $this->generateId('section', 1);
100
        $anonymousUserId = $this->generateId('user', 10);
101
        /* BEGIN: Use Case */
102
        // $anonymousUserId is the ID of the "Anonymous" user in a eZ
103
        // Publish demo installation.
104
        // $standardSectionId is the ID of the "Standard" section in a eZ
105
        // Publish demo installation.
106
107
        $userService = $repository->getUserService();
108
        $sectionService = $repository->getSectionService();
109
110
        $section = $sectionService->loadSection($standardSectionId);
111
112
        $sectionUpdate = $sectionService->newSectionUpdateStruct();
113
        $sectionUpdate->name = 'New section name';
114
        $sectionUpdate->identifier = 'newUniqueKey';
115
116
        // Set anonymous user
117
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
118
119
        // This call will fail with a "UnauthorizedException"
120
        $sectionService->updateSection($section, $sectionUpdate);
121
        /* END: Use Case */
122
    }
123
124
    /**
125
     * Test for the loadSections() method.