From efa242faa00e100155d9d0439cad24c8399d9bd4 Mon Sep 17 00:00:00 2001 From: konradoboza Date: Fri, 23 Feb 2024 12:17:58 +0100 Subject: [PATCH] added integration test coverage --- .../Limitation/UserGroupLimitationTest.php | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 tests/integration/Core/Limitation/UserGroupLimitationTest.php diff --git a/tests/integration/Core/Limitation/UserGroupLimitationTest.php b/tests/integration/Core/Limitation/UserGroupLimitationTest.php new file mode 100644 index 0000000000..882207e4c2 --- /dev/null +++ b/tests/integration/Core/Limitation/UserGroupLimitationTest.php @@ -0,0 +1,91 @@ +getRepository(); + + $user = $this->createUserWithPolicies('test_user', $this->getPermissions()); + $userGroups = $repository->getUserService()->loadUserGroupsOfUser($user); + $userGroupIds = array_column($userGroups, 'id'); + + $repository->getPermissionResolver()->setCurrentUserReference($user); + + $parentFolder = $this->createFolder( + ['eng-US' => 'Parent folder'], + 2 + ); + $childFolder = $this->createFolder( + ['eng-US' => 'Child folder'], + $parentFolder->contentInfo->getMainLocationId() + ); + + $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 \eZ\Publish\API\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> + */ + 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]]), + ], + ], + ]; + } +}