Code Duplication    Length = 29-38 lines in 3 locations

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

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

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

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

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

@@ 515-552 (lines=38) @@
512
     * @depends eZ\Publish\API\Repository\Tests\LanguageServiceTest::testDeleteLanguage
513
     * @depend(s) eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
514
     */
515
    public function testDeleteLanguageThrowsInvalidArgumentException()
516
    {
517
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\InvalidArgumentException::class);
518
        $this->expectExceptionMessage('Argument \'language\' is invalid: Deleting language logic error, some content still references that language and therefore it can\'t be deleted');
519
520
        $repository = $this->getRepository();
521
522
        $editorsGroupId = $this->generateId('group', 13);
523
        /* BEGIN: Use Case */
524
        // $editorsGroupId is the ID of the "Editors" user group in an eZ
525
        // Publish demo installation
526
527
        $languageService = $repository->getContentLanguageService();
528
529
        $languageCreateEnglish = $languageService->newLanguageCreateStruct();
530
        $languageCreateEnglish->enabled = true;
531
        $languageCreateEnglish->name = 'English';
532
        $languageCreateEnglish->languageCode = 'eng-NZ';
533
534
        $language = $languageService->createLanguage($languageCreateEnglish);
535
536
        $contentService = $repository->getContentService();
537
538
        // Get metadata update struct and set new language as main language.
539
        $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
540
        $metadataUpdate->mainLanguageCode = 'eng-NZ';
541
542
        // Update content object
543
        $contentService->updateContentMetadata(
544
            $contentService->loadContentInfo($editorsGroupId),
545
            $metadataUpdate
546
        );
547
548
        // This call will fail with an "InvalidArgumentException", because the
549
        // new language is used by a content object.
550
        $languageService->deleteLanguage($language);
551
        /* END: Use Case */
552
    }
553
554
    /**
555
     * Test for the getDefaultLanguageCode() method.