Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
markus-moser committed May 28, 2024
1 parent 92f708b commit c5325f5
Showing 1 changed file with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Asset\SearchResult\AssetSearchResultItem;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Interfaces\ElementSearchResultItemInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\Asset\AssetSearchServiceInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\Element\ElementSearchServiceInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Service\Search\SearchService\SearchProviderInterface;
use Pimcore\Db;
use Pimcore\Model\Asset;
Expand Down Expand Up @@ -314,6 +315,49 @@ public function testHandleElementWorkspacesQuery(): void
'/test-object-folder-3/sub-folder-3/sub-sub-folder-3/sub-sub-sub-folder-3',
], $user);


$user = $this->createUserWithWorkspaces(
[
'/test-asset-folder-1' => true,
'/test-asset-folder-2' => true,
],
[
'/test-document-folder-2' => true,
],
[
'/test-object-folder-3' => true,
]
);

$user->setPermission('assets', false)->save();

$this->assertElementSearchResultFolders([
'/',
'/test-document-folder-2',
'/test-document-folder-2/sub-folder-2',
'/test-document-folder-2/sub-folder-2/sub-sub-folder-2',
'/test-document-folder-2/sub-folder-2/sub-sub-folder-2/sub-sub-sub-folder-2',
'/',
'/test-object-folder-3',
'/test-object-folder-3/sub-folder-3',
'/test-object-folder-3/sub-folder-3/sub-sub-folder-3',
'/test-object-folder-3/sub-folder-3/sub-sub-folder-3/sub-sub-sub-folder-3',
], $user);

$user->setPermission('documents', false)->save();

$this->assertElementSearchResultFolders([
'/',
'/test-object-folder-3',
'/test-object-folder-3/sub-folder-3',
'/test-object-folder-3/sub-folder-3/sub-sub-folder-3',
'/test-object-folder-3/sub-folder-3/sub-sub-folder-3/sub-sub-sub-folder-3',
], $user);

$user->setPermission('objects', false)->save();

$this->assertElementSearchResultFolders([], $user);

}

private function assertAssetSearchResultFolders(array $expectedPaths, User $user)
Expand Down Expand Up @@ -341,7 +385,7 @@ private function assertAssetSearchResultFolders(array $expectedPaths, User $user

private function assertElementSearchResultFolders(array $expectedPaths, User $user)
{
/** @var AssetSearchServiceInterface $searchService */
/** @var ElementSearchServiceInterface $searchService */
$searchService = $this->tester->grabService('generic-data-index.test.service.element-search-service');
/** @var SearchProviderInterface $searchProvider */
$searchProvider = $this->tester->grabService(SearchProviderInterface::class);
Expand Down Expand Up @@ -392,6 +436,8 @@ private function createUserWithWorkspaces(array $assetWorkspaces, array $documen
$user = new User();
$user
->setPermission('assets', true)
->setPermission('documents', true)
->setPermission('objects', true)
->setUsername('test-user-' . uniqid())
->save();

Expand Down

0 comments on commit c5325f5

Please sign in to comment.