Skip to content

Commit 7a8dbe8

Browse files
authored
IBX-8726: Added support for IsBookmarked criterion (#123)
For more details see https://issues.ibexa.co/browse/IBX-8726 and #123 Key changes: * Added IsBookmarked criterion * [Tests] Added IsBookmarkedTest
1 parent e2b32ed commit 7a8dbe8

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed

src/bundle/Resources/config/input_parsers.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,3 +863,11 @@ services:
863863
$validator: '@validator'
864864
tags:
865865
- { name: ibexa.rest.input.parser, mediaType: application/vnd.ibexa.api.internal.criterion.Image }
866+
867+
868+
Ibexa\Rest\Server\Input\Parser\Criterion\IsBookmarked:
869+
parent: Ibexa\Rest\Server\Common\Parser
870+
arguments:
871+
$parserTools: '@Ibexa\Rest\Input\ParserTools'
872+
tags:
873+
- { name: ibexa.rest.input.parser, mediaType: application/vnd.ibexa.api.internal.criterion.IsBookmarked }
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa 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 Ibexa\Rest\Server\Input\Parser\Criterion;
10+
11+
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Location\IsBookmarked as IsBookmarkedCriterion;
12+
use Ibexa\Contracts\Rest\Exceptions\Parser;
13+
use Ibexa\Contracts\Rest\Input\ParsingDispatcher;
14+
use Ibexa\Rest\Input\BaseParser;
15+
use Ibexa\Rest\Input\ParserTools;
16+
17+
final class IsBookmarked extends BaseParser
18+
{
19+
public const IS_BOOKMARKED_CRITERION = 'IsBookmarkedCriterion';
20+
21+
private ParserTools $parserTools;
22+
23+
public function __construct(ParserTools $parserTools)
24+
{
25+
$this->parserTools = $parserTools;
26+
}
27+
28+
public function parse(array $data, ParsingDispatcher $parsingDispatcher): IsBookmarkedCriterion
29+
{
30+
if (!array_key_exists(self::IS_BOOKMARKED_CRITERION, $data)) {
31+
throw new Parser('Invalid <IsBookmarkedCriterion> format');
32+
}
33+
34+
return new IsBookmarkedCriterion(
35+
$this->parserTools->parseBooleanValue($data[self::IS_BOOKMARKED_CRITERION])
36+
);
37+
}
38+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
namespace Ibexa\Tests\Bundle\Rest\Functional\SearchView\Criterion;
8+
9+
use Ibexa\Tests\Bundle\Rest\Functional\SearchView\SearchCriterionTestCase;
10+
11+
final class IsBookmarkedTest extends SearchCriterionTestCase
12+
{
13+
protected function setUp(): void
14+
{
15+
parent::setUp();
16+
17+
$this->addMediaFolderToBookmarks();
18+
}
19+
20+
/**
21+
* @phpstan-return iterable<
22+
* string,
23+
* array{
24+
* string,
25+
* string,
26+
* int,
27+
* },
28+
* >
29+
*/
30+
public function getCriteriaPayloads(): iterable
31+
{
32+
yield 'Bookmarked locations' => [
33+
'json',
34+
$this->buildJsonCriterionQuery('"IsBookmarkedCriterion": true'),
35+
1,
36+
];
37+
38+
yield 'Not bookmarked locations' => [
39+
'json',
40+
$this->buildJsonCriterionQuery('"IsBookmarkedCriterion": false'),
41+
11,
42+
];
43+
}
44+
45+
private function addMediaFolderToBookmarks(): void
46+
{
47+
$request = $this->createHttpRequest(
48+
'POST',
49+
'/api/ibexa/v2/bookmark/43'
50+
);
51+
52+
$this->sendHttpRequest($request);
53+
}
54+
}

0 commit comments

Comments
 (0)