From 8df18594349ff0d68c9e24b04ebbb91ec0d83377 Mon Sep 17 00:00:00 2001 From: Jakub Brzegowski Date: Thu, 16 May 2024 09:21:12 +0200 Subject: [PATCH] IBX-7653: Add FilterParser and IsContainer criterion parser (#84) --- src/bundle/Resources/config/input_parsers.yml | 7 ++++ .../Input/Parser/Criterion/IsContainer.php | 37 +++++++++++++++++ .../SearchView/Criterion/IsContainerTest.php | 40 +++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 src/lib/Server/Input/Parser/Criterion/IsContainer.php create mode 100644 tests/bundle/Functional/SearchView/Criterion/IsContainerTest.php diff --git a/src/bundle/Resources/config/input_parsers.yml b/src/bundle/Resources/config/input_parsers.yml index 4965346a..225153fd 100644 --- a/src/bundle/Resources/config/input_parsers.yml +++ b/src/bundle/Resources/config/input_parsers.yml @@ -441,6 +441,13 @@ services: tags: - { name: ibexa.rest.input.parser, mediaType: application/vnd.ibexa.api.internal.criterion.UserMetadata } + Ibexa\Rest\Server\Input\Parser\Criterion\IsContainer: + parent: Ibexa\Rest\Server\Common\Parser + arguments: + $parserTools: '@Ibexa\Rest\Input\ParserTools' + tags: + - { name: ibexa.rest.input.parser, mediaType: application/vnd.ibexa.api.internal.criterion.IsContainer } + Ibexa\Rest\Server\Input\Parser\Criterion\IsUserBased: parent: Ibexa\Rest\Server\Common\Parser arguments: diff --git a/src/lib/Server/Input/Parser/Criterion/IsContainer.php b/src/lib/Server/Input/Parser/Criterion/IsContainer.php new file mode 100644 index 00000000..6b1b5ae1 --- /dev/null +++ b/src/lib/Server/Input/Parser/Criterion/IsContainer.php @@ -0,0 +1,37 @@ +parserTools = $parserTools; + } + + /** + * @param array $data + */ + public function parse(array $data, ParsingDispatcher $parsingDispatcher): IsContainerCriterion + { + if (!array_key_exists('IsContainerCriterion', $data)) { + throw new Exceptions\Parser('Invalid format'); + } + + return new IsContainerCriterion($this->parserTools->parseBooleanValue($data['IsContainerCriterion'])); + } +} diff --git a/tests/bundle/Functional/SearchView/Criterion/IsContainerTest.php b/tests/bundle/Functional/SearchView/Criterion/IsContainerTest.php new file mode 100644 index 00000000..c19b966e --- /dev/null +++ b/tests/bundle/Functional/SearchView/Criterion/IsContainerTest.php @@ -0,0 +1,40 @@ + + */ + public function getCriteriaPayloads(): iterable + { + return [ + 'is container' => [ + 'json', + $this->buildJsonCriterionQuery('"IsContainerCriterion": true'), + 10, + ], + 'is not container' => [ + 'json', + $this->buildJsonCriterionQuery('"IsContainerCriterion": false'), + 2, + ], + ]; + } +}