Code Duplication    Length = 27-35 lines in 4 locations

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

@@ 59-85 (lines=27) @@
56
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
57
     * @depends eZ\Publish\API\Repository\Tests\LanguageServiceTest::testUpdateLanguageName
58
     */
59
    public function testUpdateLanguageNameThrowsUnauthorizedException()
60
    {
61
        $repository = $this->getRepository();
62
63
        $anonymousUserId = $this->generateId('user', 10);
64
        /* BEGIN: Use Case */
65
        // $anonymousUserId is the ID of the "Anonymous" user in a eZ
66
        // Publish demo installation.
67
        $userService = $repository->getUserService();
68
        $languageService = $repository->getContentLanguageService();
69
70
        $languageCreate = $languageService->newLanguageCreateStruct();
71
        $languageCreate->enabled = false;
72
        $languageCreate->name = 'English';
73
        $languageCreate->languageCode = 'eng-NZ';
74
75
        $languageId = $languageService->createLanguage($languageCreate)->id;
76
77
        $language = $languageService->loadLanguageById($languageId);
78
79
        // Set anonymous user
80
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
81
82
        // This call will fail with a "UnauthorizedException"
83
        $languageService->updateLanguageName($language, 'New language name.');
84
        /* END: Use Case */
85
    }
86
87
    /**
88
     * Test for the enableLanguage() method.

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

@@ 429-463 (lines=35) @@
426
     * @depends eZ\Publish\API\Repository\Tests\LanguageServiceTest::testDeleteLanguage
427
     * @depend(s) eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
428
     */
429
    public function testDeleteLanguageThrowsInvalidArgumentException()
430
    {
431
        $repository = $this->getRepository();
432
433
        $editorsGroupId = $this->generateId('group', 13);
434
        /* BEGIN: Use Case */
435
        // $editorsGroupId is the ID of the "Editors" user group in an eZ
436
        // Publish demo installation
437
438
        $languageService = $repository->getContentLanguageService();
439
440
        $languageCreateEnglish = $languageService->newLanguageCreateStruct();
441
        $languageCreateEnglish->enabled = true;
442
        $languageCreateEnglish->name = 'English';
443
        $languageCreateEnglish->languageCode = 'eng-NZ';
444
445
        $language = $languageService->createLanguage($languageCreateEnglish);
446
447
        $contentService = $repository->getContentService();
448
449
        // Get metadata update struct and set new language as main language.
450
        $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
451
        $metadataUpdate->mainLanguageCode = 'eng-NZ';
452
453
        // Update content object
454
        $contentService->updateContentMetadata(
455
            $contentService->loadContentInfo($editorsGroupId),
456
            $metadataUpdate
457
        );
458
459
        // This call will fail with an "InvalidArgumentException", because the
460
        // new language is used by a content object.
461
        $languageService->deleteLanguage($language);
462
        /* END: Use Case */
463
    }
464
465
    /**
466
     * Test for the getDefaultLanguageCode() method.
@@ 194-226 (lines=33) @@
191
     * @see \eZ\Publish\API\Repository\LanguageService::updateLanguageName()
192
     * @depends eZ\Publish\API\Repository\Tests\LanguageServiceTest::testLoadLanguageById
193
     */
194
    public function testUpdateLanguageName()
195
    {
196
        $repository = $this->getRepository();
197
198
        /* BEGIN: Use Case */
199
        $languageService = $repository->getContentLanguageService();
200
201
        $languageCreate = $languageService->newLanguageCreateStruct();
202
        $languageCreate->enabled = false;
203
        $languageCreate->name = 'English';
204
        $languageCreate->languageCode = 'eng-NZ';
205
206
        $languageId = $languageService->createLanguage($languageCreate)->id;
207
208
        $language = $languageService->loadLanguageById($languageId);
209
210
        $updatedLanguage = $languageService->updateLanguageName(
211
            $language,
212
            'New language name.'
213
        );
214
        /* END: Use Case */
215
216
        // Verify that the service returns an updated language instance.
217
        $this->assertInstanceOf(
218
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Language',
219
            $updatedLanguage
220
        );
221
222
        // Verify that the service also persists the changes
223
        $updatedLanguage = $languageService->loadLanguageById($languageId);
224
225
        $this->assertEquals('New language name.', $updatedLanguage->name);
226
    }
227
228
    /**
229
     * Test for the enableLanguage() method.

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

@@ 126-155 (lines=30) @@
123
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
124
     * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testLoadSections
125
     */
126
    public function testLoadSectionsThrowsUnauthorizedException()
127
    {
128
        $repository = $this->getRepository();
129
130
        $anonymousUserId = $this->generateId('user', 10);
131
        /* BEGIN: Use Case */
132
        // $anonymousUserId is the ID of the "Anonymous" user in a eZ
133
        // Publish demo installation.
134
        $userService = $repository->getUserService();
135
        $sectionService = $repository->getSectionService();
136
137
        // Create some sections
138
        $sectionCreateOne = $sectionService->newSectionCreateStruct();
139
        $sectionCreateOne->name = 'Test section one';
140
        $sectionCreateOne->identifier = 'uniqueKeyOne';
141
142
        $sectionCreateTwo = $sectionService->newSectionCreateStruct();
143
        $sectionCreateTwo->name = 'Test section two';
144
        $sectionCreateTwo->identifier = 'uniqueKeyTwo';
145
146
        $sectionService->createSection($sectionCreateOne);
147
        $sectionService->createSection($sectionCreateTwo);
148
149
        // Set anonymous user
150
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
151
152
        // This call will fail with a "UnauthorizedException"
153
        $sectionService->loadSections();
154
        /* END: Use Case */
155
    }
156
157
    /**
158
     * Test for the loadSectionByIdentifier() method.