| @@ 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. |
|
| @@ 499-533 (lines=35) @@ | ||
| 496 | * @depends eZ\Publish\API\Repository\Tests\LanguageServiceTest::testDeleteLanguage |
|
| 497 | * @depend(s) eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
|
| 498 | */ |
|
| 499 | public function testDeleteLanguageThrowsInvalidArgumentException() |
|
| 500 | { |
|
| 501 | $repository = $this->getRepository(); |
|
| 502 | ||
| 503 | $editorsGroupId = $this->generateId('group', 13); |
|
| 504 | /* BEGIN: Use Case */ |
|
| 505 | // $editorsGroupId is the ID of the "Editors" user group in an eZ |
|
| 506 | // Publish demo installation |
|
| 507 | ||
| 508 | $languageService = $repository->getContentLanguageService(); |
|
| 509 | ||
| 510 | $languageCreateEnglish = $languageService->newLanguageCreateStruct(); |
|
| 511 | $languageCreateEnglish->enabled = true; |
|
| 512 | $languageCreateEnglish->name = 'English'; |
|
| 513 | $languageCreateEnglish->languageCode = 'eng-NZ'; |
|
| 514 | ||
| 515 | $language = $languageService->createLanguage($languageCreateEnglish); |
|
| 516 | ||
| 517 | $contentService = $repository->getContentService(); |
|
| 518 | ||
| 519 | // Get metadata update struct and set new language as main language. |
|
| 520 | $metadataUpdate = $contentService->newContentMetadataUpdateStruct(); |
|
| 521 | $metadataUpdate->mainLanguageCode = 'eng-NZ'; |
|
| 522 | ||
| 523 | // Update content object |
|
| 524 | $contentService->updateContentMetadata( |
|
| 525 | $contentService->loadContentInfo($editorsGroupId), |
|
| 526 | $metadataUpdate |
|
| 527 | ); |
|
| 528 | ||
| 529 | // This call will fail with an "InvalidArgumentException", because the |
|
| 530 | // new language is used by a content object. |
|
| 531 | $languageService->deleteLanguage($language); |
|
| 532 | /* END: Use Case */ |
|
| 533 | } |
|
| 534 | ||
| 535 | /** |
|
| 536 | * Test for the getDefaultLanguageCode() method. |
|
| @@ 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. |
|