Code Duplication    Length = 26-27 lines in 5 locations

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

@@ 95-121 (lines=27) @@
92
     * @see \eZ\Publish\API\Repository\LanguageService::enableLanguage()
93
     * @depends eZ\Publish\API\Repository\Tests\LanguageServiceTest::testEnableLanguage
94
     */
95
    public function testEnableLanguageThrowsUnauthorizedException()
96
    {
97
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\UnauthorizedException::class);
98
99
        $repository = $this->getRepository();
100
101
        $anonymousUserId = $this->generateId('user', 10);
102
        /* BEGIN: Use Case */
103
        // $anonymousUserId is the ID of the "Anonymous" user in a eZ
104
        // Publish demo installation.
105
        $userService = $repository->getUserService();
106
        $languageService = $repository->getContentLanguageService();
107
108
        $languageCreate = $languageService->newLanguageCreateStruct();
109
        $languageCreate->enabled = false;
110
        $languageCreate->name = 'English';
111
        $languageCreate->languageCode = 'eng-NZ';
112
113
        $language = $languageService->createLanguage($languageCreate);
114
115
        // Set anonymous user
116
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
117
118
        // This call will fail with a "UnauthorizedException"
119
        $languageService->enableLanguage($language);
120
        /* END: Use Case */
121
    }
122
123
    /**
124
     * Test for the disableLanguage() method.
@@ 129-155 (lines=27) @@
126
     * @see \eZ\Publish\API\Repository\LanguageService::disableLanguage()
127
     * @depends eZ\Publish\API\Repository\Tests\LanguageServiceTest::testDisableLanguage
128
     */
129
    public function testDisableLanguageThrowsUnauthorizedException()
130
    {
131
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\UnauthorizedException::class);
132
133
        $repository = $this->getRepository();
134
135
        $anonymousUserId = $this->generateId('user', 10);
136
        /* BEGIN: Use Case */
137
        // $anonymousUserId is the ID of the "Anonymous" user in a eZ
138
        // Publish demo installation.
139
        $userService = $repository->getUserService();
140
        $languageService = $repository->getContentLanguageService();
141
142
        $languageCreate = $languageService->newLanguageCreateStruct();
143
        $languageCreate->enabled = true;
144
        $languageCreate->name = 'English';
145
        $languageCreate->languageCode = 'eng-NZ';
146
147
        $language = $languageService->createLanguage($languageCreate);
148
149
        // Set anonymous user
150
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
151
152
        // This call will fail with a "UnauthorizedException"
153
        $languageService->disableLanguage($language);
154
        /* END: Use Case */
155
    }
156
157
    /**
158
     * Test for the deleteLanguage() method.
@@ 163-189 (lines=27) @@
160
     * @see \eZ\Publish\API\Repository\LanguageService::deleteLanguage()
161
     * @depends eZ\Publish\API\Repository\Tests\LanguageServiceTest::testDeleteLanguage
162
     */
163
    public function testDeleteLanguageThrowsUnauthorizedException()
164
    {
165
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\UnauthorizedException::class);
166
167
        $repository = $this->getRepository();
168
169
        $anonymousUserId = $this->generateId('user', 10);
170
        /* BEGIN: Use Case */
171
        // $anonymousUserId is the ID of the "Anonymous" user in a eZ
172
        // Publish demo installation.
173
        $userService = $repository->getUserService();
174
        $languageService = $repository->getContentLanguageService();
175
176
        $languageCreateEnglish = $languageService->newLanguageCreateStruct();
177
        $languageCreateEnglish->enabled = false;
178
        $languageCreateEnglish->name = 'English';
179
        $languageCreateEnglish->languageCode = 'eng-NZ';
180
181
        $language = $languageService->createLanguage($languageCreateEnglish);
182
183
        // Set anonymous user
184
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
185
186
        // This call will fail with a "UnauthorizedException"
187
        $languageService->deleteLanguage($language);
188
        /* END: Use Case */
189
    }
190
}
191

eZ/Publish/API/Repository/Tests/SectionServiceAuthorizationTest.php 2 locations

@@ 60-85 (lines=26) @@
57
     * @see \eZ\Publish\API\Repository\SectionService::loadSection()
58
     * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testLoadSection
59
     */
60
    public function testLoadSectionThrowsUnauthorizedException()
61
    {
62
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\UnauthorizedException::class);
63
64
        $repository = $this->getRepository();
65
66
        $anonymousUserId = $this->generateId('user', 10);
67
        /* BEGIN: Use Case */
68
        // $anonymousUserId is the ID of the "Anonymous" user in a eZ
69
        // Publish demo installation.
70
        $userService = $repository->getUserService();
71
        $sectionService = $repository->getSectionService();
72
73
        $sectionCreate = $sectionService->newSectionCreateStruct();
74
        $sectionCreate->name = 'Test Section';
75
        $sectionCreate->identifier = 'uniqueKey';
76
77
        $sectionId = $sectionService->createSection($sectionCreate)->id;
78
79
        // Set anonymous user
80
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
81
82
        // This call will fail with a "UnauthorizedException"
83
        $sectionService->loadSection($sectionId);
84
        /* END: Use Case */
85
    }
86
87
    /**
88
     * Test for the updateSection() method.
@@ 287-312 (lines=26) @@
284
     *
285
     * @see \eZ\Publish\API\Repository\SectionService::deleteSection()
286
     */
287
    public function testDeleteSectionThrowsUnauthorizedException()
288
    {
289
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\UnauthorizedException::class);
290
291
        $repository = $this->getRepository();
292
293
        $anonymousUserId = $this->generateId('user', 10);
294
        /* BEGIN: Use Case */
295
        // $anonymousUserId is the ID of the "Anonymous" user in a eZ
296
        // Publish demo installation.
297
        $userService = $repository->getUserService();
298
        $sectionService = $repository->getSectionService();
299
300
        $sectionCreate = $sectionService->newSectionCreateStruct();
301
        $sectionCreate->name = 'Test Section';
302
        $sectionCreate->identifier = 'uniqueKey';
303
304
        $section = $sectionService->createSection($sectionCreate);
305
306
        // Set anonymous user
307
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
308
309
        // This call will fail with a "UnauthorizedException"
310
        $sectionService->deleteSection($section);
311
        /* END: Use Case */
312
    }
313
}
314