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, + ], + ]; + } +}