1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
4
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
5
|
|
|
*/ |
6
|
|
|
namespace eZ\Publish\API\Repository\Tests\Limitation; |
7
|
|
|
|
8
|
|
|
use eZ\Publish\API\Repository\Exceptions\UnauthorizedException; |
9
|
|
|
use eZ\Publish\API\Repository\Tests\BaseTest; |
10
|
|
|
use eZ\Publish\API\Repository\Values\User\Limitation\LanguageLimitation; |
11
|
|
|
|
12
|
|
|
class LanguageLimitationTest extends BaseTest |
13
|
|
|
{ |
14
|
|
|
/** @var string */ |
15
|
|
|
private const ENG_US = 'eng-US'; |
16
|
|
|
|
17
|
|
|
/** @var string */ |
18
|
|
|
private const GER_DE = 'ger-DE'; |
19
|
|
|
|
20
|
|
|
public function testPublishVersionTranslation(): void |
21
|
|
|
{ |
22
|
|
|
$repository = $this->getRepository(false); |
23
|
|
|
$contentService = $repository->getContentService(); |
24
|
|
|
$permissionResolver = $repository->getPermissionResolver(); |
25
|
|
|
|
26
|
|
|
$publishedContent = $this->createFolder( |
27
|
|
|
[ |
28
|
|
|
self::ENG_US => 'Published US', |
29
|
|
|
self::GER_DE => 'Published DE', |
30
|
|
|
], |
31
|
|
|
$this->generateId('location', 2) |
32
|
|
|
); |
33
|
|
|
|
34
|
|
|
$draft = $contentService->createContentDraft($publishedContent->contentInfo); |
35
|
|
|
|
36
|
|
|
$contentUpdateStruct = $contentService->newContentUpdateStruct(); |
37
|
|
|
$contentUpdateStruct->initialLanguageCode = self::GER_DE; |
38
|
|
|
|
39
|
|
|
$contentUpdateStruct->setField('name', 'Draft 1 DE', self::GER_DE); |
40
|
|
|
|
41
|
|
|
$contentService->updateContent($draft->versionInfo, $contentUpdateStruct); |
42
|
|
|
|
43
|
|
|
$user = $this->createUserWithPolicies( |
44
|
|
|
'user', |
45
|
|
|
[ |
46
|
|
|
[ |
47
|
|
|
'module' => 'content', |
48
|
|
|
'function' => 'publish', |
49
|
|
|
'limitations' => [new LanguageLimitation(['limitationValues' => [self::GER_DE]])], |
50
|
|
|
], |
51
|
|
|
] |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
$admin = $permissionResolver->getCurrentUserReference(); |
55
|
|
|
$permissionResolver->setCurrentUserReference($user); |
56
|
|
|
|
57
|
|
|
$contentService->publishVersion($draft->versionInfo, [self::GER_DE]); |
58
|
|
|
|
59
|
|
|
$permissionResolver->setCurrentUserReference($admin); |
60
|
|
|
$content = $contentService->loadContent($draft->contentInfo->id); |
61
|
|
|
$this->assertEquals( |
62
|
|
|
[ |
63
|
|
|
self::ENG_US => 'Published US', |
64
|
|
|
self::GER_DE => 'Draft 1 DE', |
65
|
|
|
], |
66
|
|
|
$content->fields['name'] |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function testthrowUnauthorizedExceptionWhilePublishVersionTranslation(): void |
71
|
|
|
{ |
72
|
|
|
$this->expectException(UnauthorizedException::class); |
73
|
|
|
|
74
|
|
|
$repository = $this->getRepository(false); |
75
|
|
|
$contentService = $repository->getContentService(); |
76
|
|
|
$permissionResolver = $repository->getPermissionResolver(); |
77
|
|
|
|
78
|
|
|
$publishedContent = $this->createFolder( |
79
|
|
|
[ |
80
|
|
|
self::ENG_US => 'Published US', |
81
|
|
|
self::GER_DE => 'Published DE', |
82
|
|
|
], |
83
|
|
|
$this->generateId('location', 2) |
84
|
|
|
); |
85
|
|
|
|
86
|
|
|
$draft = $contentService->createContentDraft($publishedContent->contentInfo); |
87
|
|
|
|
88
|
|
|
$contentUpdateStruct = $contentService->newContentUpdateStruct(); |
89
|
|
|
$contentUpdateStruct->initialLanguageCode = self::ENG_US; |
90
|
|
|
|
91
|
|
|
$contentUpdateStruct->setField('name', 'Draft 1 EN', self::ENG_US); |
92
|
|
|
|
93
|
|
|
$contentService->updateContent($draft->versionInfo, $contentUpdateStruct); |
94
|
|
|
|
95
|
|
|
$user = $this->createUserWithPolicies( |
96
|
|
|
'editor', |
97
|
|
|
[ |
98
|
|
|
[ |
99
|
|
|
'module' => 'content', |
100
|
|
|
'function' => 'publish', |
101
|
|
|
'limitations' => [new LanguageLimitation(['limitationValues' => [self::GER_DE]])], |
102
|
|
|
], |
103
|
|
|
] |
104
|
|
|
); |
105
|
|
|
|
106
|
|
|
$admin = $permissionResolver->getCurrentUserReference(); |
|
|
|
|
107
|
|
|
$permissionResolver->setCurrentUserReference($user); |
108
|
|
|
|
109
|
|
|
$contentService->publishVersion($draft->versionInfo, [self::ENG_US]); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.