|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* File containing the LanguageLimitationTest class. |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
namespace eZ\Publish\API\Repository\Tests\Values\User\Limitation; |
|
10
|
|
|
|
|
11
|
|
|
use eZ\Publish\API\Repository\Values\User\Limitation\LanguageLimitation; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Test case for the {@link \eZ\Publish\API\Repository\Values\User\Limitation\LanguageLimitation} |
|
15
|
|
|
* class. |
|
16
|
|
|
* |
|
17
|
|
|
* @see eZ\Publish\API\Repository\Values\User\Limitation |
|
18
|
|
|
* @see eZ\Publish\API\Repository\Values\User\Limitation\LanguageLimitation |
|
19
|
|
|
* @group integration |
|
20
|
|
|
* @group limitation |
|
21
|
|
|
*/ |
|
22
|
|
|
class LanguageLimitationTest extends BaseLimitationTest |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* Test for the LanguageLimitation. |
|
26
|
|
|
* |
|
27
|
|
|
* @see \eZ\Publish\API\Repository\Values\User\Limitation\LanguageLimitation |
|
28
|
|
|
* |
|
29
|
|
|
* @throws \ErrorException |
|
30
|
|
|
*/ |
|
31
|
|
View Code Duplication |
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. |
|
96
|
|
|
* |
|
97
|
|
|
* @see \eZ\Publish\API\Repository\Values\User\Limitation\LanguageLimitation |
|
98
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
|
99
|
|
|
* |
|
100
|
|
|
* @throws \ErrorException |
|
101
|
|
|
*/ |
|
102
|
|
|
public function testLanguageLimitationForbid() |
|
103
|
|
|
{ |
|
104
|
|
|
$repository = $this->getRepository(); |
|
105
|
|
|
|
|
106
|
|
|
$contentId = $this->generateId('content', 58); |
|
107
|
|
|
/* BEGIN: Use Case */ |
|
108
|
|
|
$user = $this->createUserVersion1(); |
|
109
|
|
|
|
|
110
|
|
|
$roleService = $repository->getRoleService(); |
|
111
|
|
|
|
|
112
|
|
|
$role = $roleService->loadRoleByIdentifier('Editor'); |
|
113
|
|
|
|
|
114
|
|
|
$editPolicy = null; |
|
115
|
|
|
foreach ($role->getPolicies() as $policy) { |
|
116
|
|
|
if ('content' != $policy->module || 'edit' != $policy->function) { |
|
117
|
|
|
continue; |
|
118
|
|
|
} |
|
119
|
|
|
$editPolicy = $policy; |
|
120
|
|
|
break; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
if (null === $editPolicy) { |
|
124
|
|
|
throw new \ErrorException('No content:edit policy found.'); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
// Only allow eng-US content |
|
128
|
|
|
$policyUpdate = $roleService->newPolicyUpdateStruct(); |
|
129
|
|
|
$policyUpdate->addLimitation( |
|
130
|
|
|
new LanguageLimitation( |
|
131
|
|
|
['limitationValues' => ['eng-US']] |
|
132
|
|
|
) |
|
133
|
|
|
); |
|
134
|
|
|
$roleService->updatePolicy($editPolicy, $policyUpdate); |
|
|
|
|
|
|
135
|
|
|
|
|
136
|
|
|
$roleService->assignRoleToUser($role, $user); |
|
137
|
|
|
|
|
138
|
|
|
$contentService = $repository->getContentService(); |
|
139
|
|
|
|
|
140
|
|
|
$repository->setCurrentUser($user); |
|
|
|
|
|
|
141
|
|
|
|
|
142
|
|
|
$contentUpdate = $contentService->newContentUpdateStruct(); |
|
143
|
|
|
$contentUpdate->setField('name', 'Contact Me'); |
|
144
|
|
|
|
|
145
|
|
|
// This call will fail with an UnauthorizedException |
|
146
|
|
|
$contentService->createContentDraft( |
|
147
|
|
|
$contentService->loadContentInfo($contentId) |
|
148
|
|
|
); |
|
149
|
|
|
/* END: Use Case */ |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.