| @@ 31-87 (lines=57) @@ | ||
| 28 | * |
|
| 29 | * @throws \ErrorException |
|
| 30 | */ |
|
| 31 | public function testContentTypeLimitationAllow() |
|
| 32 | { |
|
| 33 | $repository = $this->getRepository(); |
|
| 34 | ||
| 35 | $contentService = $repository->getContentService(); |
|
| 36 | ||
| 37 | $contentTypeId = $this->generateId('contentType', 22); |
|
| 38 | /* BEGIN: Use Case */ |
|
| 39 | $user = $this->createUserVersion1(); |
|
| 40 | ||
| 41 | $roleService = $repository->getRoleService(); |
|
| 42 | ||
| 43 | $role = $roleService->loadRoleByIdentifier('Editor'); |
|
| 44 | ||
| 45 | $editPolicy = null; |
|
| 46 | foreach ($role->getPolicies() as $policy) { |
|
| 47 | if ('content' != $policy->module || 'edit' != $policy->function) { |
|
| 48 | continue; |
|
| 49 | } |
|
| 50 | $editPolicy = $policy; |
|
| 51 | break; |
|
| 52 | } |
|
| 53 | ||
| 54 | if (null === $editPolicy) { |
|
| 55 | throw new \ErrorException('No content:edit policy found.'); |
|
| 56 | } |
|
| 57 | ||
| 58 | $policyUpdate = $roleService->newPolicyUpdateStruct(); |
|
| 59 | $policyUpdate->addLimitation( |
|
| 60 | new ContentTypeLimitation( |
|
| 61 | ['limitationValues' => [$contentTypeId]] |
|
| 62 | ) |
|
| 63 | ); |
|
| 64 | ||
| 65 | $roleService->updatePolicy($editPolicy, $policyUpdate); |
|
| 66 | $roleService->assignRoleToUser($roleService->loadRole($role->id), $user); |
|
| 67 | ||
| 68 | $content = $this->createWikiPage(); |
|
| 69 | ||
| 70 | $repository->setCurrentUser($user); |
|
| 71 | ||
| 72 | $updateDraft = $contentService->createContentDraft($content->contentInfo); |
|
| 73 | ||
| 74 | $contentUpdate = $contentService->newContentUpdateStruct(); |
|
| 75 | $contentUpdate->setField('title', 'Your wiki page'); |
|
| 76 | ||
| 77 | $updateContent = $contentService->updateContent( |
|
| 78 | $updateDraft->versionInfo, |
|
| 79 | $contentUpdate |
|
| 80 | ); |
|
| 81 | /* END: Use Case */ |
|
| 82 | ||
| 83 | $this->assertEquals( |
|
| 84 | 'Your wiki page', |
|
| 85 | $updateContent->getFieldValue('title')->text |
|
| 86 | ); |
|
| 87 | } |
|
| 88 | ||
| 89 | /** |
|
| 90 | * Test for the ContentTypeLimitation. |
|
| @@ 31-92 (lines=62) @@ | ||
| 28 | * |
|
| 29 | * @throws \ErrorException |
|
| 30 | */ |
|
| 31 | public function testLanguageLimitationAllow() |
|
| 32 | { |
|
| 33 | $repository = $this->getRepository(); |
|
| 34 | ||
| 35 | $contentId = $this->generateId('content', 58); |
|
| 36 | /* BEGIN: Use Case */ |
|
| 37 | $user = $this->createUserVersion1(); |
|
| 38 | ||
| 39 | $roleService = $repository->getRoleService(); |
|
| 40 | ||
| 41 | $role = $roleService->loadRoleByIdentifier('Editor'); |
|
| 42 | ||
| 43 | $editPolicy = null; |
|
| 44 | foreach ($role->getPolicies() as $policy) { |
|
| 45 | if ('content' != $policy->module || 'edit' != $policy->function) { |
|
| 46 | continue; |
|
| 47 | } |
|
| 48 | $editPolicy = $policy; |
|
| 49 | break; |
|
| 50 | } |
|
| 51 | ||
| 52 | if (null === $editPolicy) { |
|
| 53 | throw new \ErrorException('No content:edit policy found.'); |
|
| 54 | } |
|
| 55 | ||
| 56 | // Only allow eng-GB content |
|
| 57 | $policyUpdate = $roleService->newPolicyUpdateStruct(); |
|
| 58 | $policyUpdate->addLimitation( |
|
| 59 | new LanguageLimitation( |
|
| 60 | ['limitationValues' => ['eng-GB']] |
|
| 61 | ) |
|
| 62 | ); |
|
| 63 | $roleService->updatePolicy($editPolicy, $policyUpdate); |
|
| 64 | ||
| 65 | $roleService->assignRoleToUser($role, $user); |
|
| 66 | ||
| 67 | $contentService = $repository->getContentService(); |
|
| 68 | ||
| 69 | $repository->setCurrentUser($user); |
|
| 70 | ||
| 71 | $contentUpdate = $contentService->newContentUpdateStruct(); |
|
| 72 | $contentUpdate->setField('name', 'Contact Me'); |
|
| 73 | ||
| 74 | $draft = $contentService->createContentDraft( |
|
| 75 | $contentService->loadContentInfo($contentId) |
|
| 76 | ); |
|
| 77 | ||
| 78 | // Update content object |
|
| 79 | $draft = $contentService->updateContent( |
|
| 80 | $draft->versionInfo, |
|
| 81 | $contentUpdate |
|
| 82 | ); |
|
| 83 | ||
| 84 | $contentService->publishVersion($draft->versionInfo); |
|
| 85 | /* END: Use Case */ |
|
| 86 | ||
| 87 | $this->assertEquals( |
|
| 88 | 'Contact Me', |
|
| 89 | $contentService->loadContent($contentId) |
|
| 90 | ->getFieldValue('name')->text |
|
| 91 | ); |
|
| 92 | } |
|
| 93 | ||
| 94 | /** |
|
| 95 | * Test for the LanguageLimitation. |
|