-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathUserGroupLimitationTest.php
96 lines (82 loc) · 3.42 KB
/
UserGroupLimitationTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);
namespace Ibexa\Tests\Integration\Core\Limitation;
use Ibexa\Contracts\Core\Repository\Values\Content\LocationQuery;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion;
use Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchHit;
use Ibexa\Contracts\Core\Repository\Values\User\Limitation\ContentTypeLimitation;
use Ibexa\Contracts\Core\Repository\Values\User\Limitation\LocationLimitation;
use Ibexa\Contracts\Core\Repository\Values\User\Limitation\UserGroupLimitation;
use Ibexa\Tests\Integration\Core\Repository\Limitation\PermissionResolver\BaseLimitationIntegrationTest;
final class UserGroupLimitationTest extends BaseLimitationIntegrationTest
{
private const FOLDER_CONTENT_TYPE_ID = 1;
public function testHasUserWithUserGroupLimitationAccessToCreatedLocations(): void
{
$repository = $this->getRepository();
$user = $this->createUserWithPolicies('test_user', $this->getPermissions());
$userGroups = $repository->getUserService()->loadUserGroupsOfUser($user);
$userGroupIds = [];
foreach ($userGroups as $userGroup) {
$userGroupIds[] = $userGroup->id;
}
$repository->getPermissionResolver()->setCurrentUserReference($user);
$parentFolder = $this->createFolder(
['eng-US' => 'Parent folder'],
2
);
$childFolder = $this->createFolder(
['eng-US' => 'Child folder'],
$parentFolder->contentInfo->getMainLocationId()
);
$this->refreshSearch($repository);
$query = new LocationQuery();
$query->filter = new Criterion\LogicalAnd([
new Criterion\ContentTypeId(self::FOLDER_CONTENT_TYPE_ID),
new Criterion\UserMetadata('group', 'in', $userGroupIds),
]);
$results = $repository->getSearchService()->findLocations($query)->searchHits;
$resultLocationIds = array_map(static function (SearchHit $hit): int {
/** @var \Ibexa\Contracts\Core\Repository\Values\Content\Location $location */
$location = $hit->valueObject;
return $location->id;
}, $results);
self::assertContains($parentFolder->contentInfo->getMainLocationId(), $resultLocationIds);
self::assertContains($childFolder->contentInfo->getMainLocationId(), $resultLocationIds);
}
/**
* @return array<array<string, mixed>>
*/
private function getPermissions(): array
{
return [
[
'module' => 'content',
'function' => 'create',
],
[
'module' => 'content',
'function' => 'publish',
],
[
'module' => 'content',
'function' => 'read',
'limitations' => [
new LocationLimitation(['limitationValues' => [2]]),
],
],
[
'module' => 'content',
'function' => 'read',
'limitations' => [
new ContentTypeLimitation(['limitationValues' => [self::FOLDER_CONTENT_TYPE_ID]]),
new UserGroupLimitation(['limitationValues' => [1]]),
],
],
];
}
}