Completed
Push — master ( 83fb2b...0f847f )
by
unknown
42:12 queued 20:32
created

LanguageLimitationIntegrationTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 148
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
dl 0
loc 148
c 0
b 0
f 0
rs 10
wmc 5
lcom 1
cbo 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A providerForCanUserCreateContent() 0 19 1
A testCanUserCreateContent() 0 29 1
A providerForCanUserEditOrPublishContent() 0 18 1
A testCanUserEditContent() 0 20 1
A testCanUserPublishContent() 0 8 1
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace eZ\Publish\API\Repository\Tests\Limitation\PermissionResolver;
10
11
use eZ\Publish\API\Repository\Values\User\Limitation\LanguageLimitation;
12
13
/**
14
 * Integration test for chosen use cases of calls to PermissionResolver::canUser.
15
 */
16
class LanguageLimitationIntegrationTest extends BaseLimitationIntegrationTest
17
{
18
    private const LANG_ENG_GB = 'eng-GB';
19
    private const LANG_ENG_US = 'eng-US';
20
    private const LANG_GER_DE = 'ger-DE';
21
22
    /**
23
     * Data provider for testCanUserCreateContent.
24
     *
25
     * @see testCanUserCreateContent
26
     *
27
     * @return array
28
     */
29
    public function providerForCanUserCreateContent(): array
30
    {
31
        $limitationForGerman = new LanguageLimitation();
32
        $limitationForGerman->limitationValues = [self::LANG_GER_DE];
33
34
        $limitationForBritishEnglish = new LanguageLimitation();
35
        $limitationForBritishEnglish->limitationValues = [self::LANG_ENG_GB];
36
37
        $multilingualLimitation = new LanguageLimitation();
38
        $multilingualLimitation->limitationValues = [self::LANG_ENG_US, self::LANG_GER_DE];
39
40
        return [
41
            // trying to create German Content, so for British it's false
42
            [[$limitationForBritishEnglish], false],
43
            [[$limitationForGerman], true],
44
            // at least one multilingual limitation must match
45
            [[$multilingualLimitation], true],
46
        ];
47
    }
48
49
    /**
50
     * @dataProvider providerForCanUserCreateContent
51
     *
52
     * @param array $limitations
53
     * @param bool $expectedResult
54
     *
55
     * @throws \eZ\Publish\API\Repository\Exceptions\ForbiddenException
56
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
57
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
58
     */
59
    public function testCanUserCreateContent(array $limitations, bool $expectedResult): void
60
    {
61
        $repository = $this->getRepository();
62
        $contentTypeService = $repository->getContentTypeService();
63
        $contentService = $repository->getContentService();
64
        $locationService = $repository->getLocationService();
65
66
        $this->loginAsEditorUserWithLimitations('content', 'create', $limitations);
67
68
        $folderType = $contentTypeService->loadContentTypeByIdentifier(
69
            'folder'
70
        );
71
        $contentCreateStruct = $contentService->newContentCreateStruct(
72
            $folderType,
73
            self::LANG_GER_DE
74
        );
75
        $targets = [
76
            $locationService->newLocationCreateStruct(2),
77
        ];
78
79
        $this->assertCanUser(
80
            $expectedResult,
81
            'content',
82
            'create',
83
            $limitations,
84
            $contentCreateStruct,
85
            $targets
86
        );
87
    }
88
89
    /**
90
     * Data provider for testCanUserEditContent and testCanUserPublishContent.
91
     *
92
     * @see testCanUserEditContent
93
     * @see testCanUserPublishContent
94
     */
95
    public function providerForCanUserEditOrPublishContent(): array
96
    {
97
        $limitationForGerman = new LanguageLimitation();
98
        $limitationForGerman->limitationValues = [self::LANG_GER_DE];
99
100
        $limitationForBritishEnglish = new LanguageLimitation();
101
        $limitationForBritishEnglish->limitationValues = [self::LANG_ENG_GB];
102
103
        $multilingualLimitation = new LanguageLimitation();
104
        $multilingualLimitation->limitationValues = [self::LANG_ENG_US, self::LANG_GER_DE];
105
106
        return [
107
            // dealing with British content, so true only for British Language Limitation
108
            [[$limitationForBritishEnglish], true],
109
            [[$limitationForGerman], false],
110
            [[$multilingualLimitation], false],
111
        ];
112
    }
113
114
    /**
115
     * @dataProvider providerForCanUserEditOrPublishContent
116
     *
117
     * @param array $limitations
118
     * @param bool $expectedResult
119
     *
120
     * @throws \eZ\Publish\API\Repository\Exceptions\ForbiddenException
121
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
122
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
123
     */
124
    public function testCanUserEditContent(array $limitations, bool $expectedResult): void
125
    {
126
        $repository = $this->getRepository();
127
        $locationService = $repository->getLocationService();
128
129
        $content = $this->createFolder([self::LANG_ENG_GB => 'British Folder'], 2);
130
        $contentInfo = $content->contentInfo;
131
        $location = $locationService->loadLocation($contentInfo->mainLocationId);
132
133
        $this->loginAsEditorUserWithLimitations('content', 'edit', $limitations);
134
135
        $this->assertCanUser(
136
            $expectedResult,
137
            'content',
138
            'edit',
139
            $limitations,
140
            $contentInfo,
141
            [$location]
142
        );
143
    }
144
145
    /**
146
     * @dataProvider providerForCanUserEditOrPublishContent
147
     *
148
     * @param array $limitations
149
     * @param bool $expectedResult
150
     *
151
     * @throws \eZ\Publish\API\Repository\Exceptions\ForbiddenException
152
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
153
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
154
     */
155
    public function testCanUserPublishContent(array $limitations, bool $expectedResult): void
156
    {
157
        $content = $this->createFolder([self::LANG_ENG_GB => 'British Folder'], 2);
158
159
        $this->loginAsEditorUserWithLimitations('content', 'publish', $limitations);
160
161
        $this->assertCanUser($expectedResult, 'content', 'publish', $limitations, $content);
162
    }
163
}
164