diff --git a/lib/Core/Site/QueryType/Base.php b/lib/Core/Site/QueryType/Base.php index 0c897a22..6507eb0d 100644 --- a/lib/Core/Site/QueryType/Base.php +++ b/lib/Core/Site/QueryType/Base.php @@ -194,6 +194,7 @@ protected function configureBaseOptions(OptionsResolver $resolver): void 'section', 'state', 'visible', + 'tag_id', ]); $resolver->setDefaults([ 'sort' => [], @@ -214,6 +215,8 @@ protected function configureBaseOptions(OptionsResolver $resolver): void $resolver->setAllowedTypes('creation_date', ['int', 'string', 'array']); $resolver->setAllowedTypes('modification_date', ['int', 'string', 'array']); $resolver->setAllowedTypes('state', ['array']); + $resolver->setAllowedTypes('tag_id', ['int', 'array']); + $resolver->setAllowedValues('visible', [true, false, null]); $resolver->setNormalizer('limit', static fn (Options $options, $value) => $value ?? 25); @@ -301,6 +304,9 @@ private function resolveCriterionDefinitions(string $name, $parameters): array case 'state': case 'is_field_empty': return $criterionDefinitionResolver->resolveTargets($name, $parameters); + + case 'tag_id': + return $criterionDefinitionResolver->resolve($name, $parameters); } return []; diff --git a/lib/Core/Site/QueryType/CriteriaBuilder.php b/lib/Core/Site/QueryType/CriteriaBuilder.php index abe79e6d..21833d22 100644 --- a/lib/Core/Site/QueryType/CriteriaBuilder.php +++ b/lib/Core/Site/QueryType/CriteriaBuilder.php @@ -20,6 +20,7 @@ use Netgen\IbexaSearchExtra\API\Values\Content\Query\Criterion\ObjectStateIdentifier; use Netgen\IbexaSearchExtra\API\Values\Content\Query\Criterion\SectionIdentifier; use Netgen\IbexaSearchExtra\API\Values\Content\Query\Criterion\Visible; +use Netgen\TagsBundle\API\Repository\Values\Content\Query\Criterion\TagId; use function count; use function is_array; use function is_int; @@ -108,6 +109,9 @@ private function dispatchBuild(CriterionDefinition $definition): ?Criterion case 'is_field_empty': return $this->buildIsFieldEmpty($definition); + + case 'tag_id': + return $this->buildTag($definition); } throw new InvalidArgumentException( @@ -336,4 +340,13 @@ private function buildIsFieldEmpty(CriterionDefinition $definition): ?IsFieldEmp return new IsFieldEmpty((string) $definition->target, (bool) $definition->value); } + + private function buildTag(CriterionDefinition $definition): ?TagId + { + if ($definition->value === null) { + return null; + } + + return new TagId($definition->value); + } } diff --git a/tests/lib/Unit/Core/Site/QueryType/Base/BaseQueryTypeTest.php b/tests/lib/Unit/Core/Site/QueryType/Base/BaseQueryTypeTest.php index b165c46c..fa87ec1f 100644 --- a/tests/lib/Unit/Core/Site/QueryType/Base/BaseQueryTypeTest.php +++ b/tests/lib/Unit/Core/Site/QueryType/Base/BaseQueryTypeTest.php @@ -18,6 +18,7 @@ use Netgen\IbexaSiteApi\Core\Site\QueryType\QueryType; use Netgen\IbexaSiteApi\Core\Site\Settings; use Netgen\IbexaSiteApi\Tests\Unit\Core\Site\QueryType\QueryTypeBaseTest; +use Netgen\TagsBundle\API\Repository\Values\Content\Query\Criterion\TagId; /** * Base QueryType stub test case. @@ -243,6 +244,46 @@ public function providerForTestGetQuery(): array ], ]), ], + [ + true, + [ + 'tag_id' => 223, + ], + new Query([ + 'filter' => new TagId(223), + ]), + ], + [ + true, + [ + 'tag_id' => [223, 224, 1], + ], + new Query([ + 'filter' => new TagId([223, 224, 1]), + ]), + ], + [ + true, + [ + 'tag_id' => [ + 'eq' => 225, + ], + ], + new Query([ + 'filter' => new TagId(225), + ]), + ], + [ + true, + [ + 'tag_id' => [ + 'in' => [225, 226], + ], + ], + new Query([ + 'filter' => new TagId([225, 226]), + ]), + ], ]; } @@ -286,6 +327,11 @@ public function providerForTestGetQueryWithInvalidOptions(): array 'is_field_empty' => [true], ], ], + [ + [ + 'tag_id' => 'ten', + ], + ], ]; } @@ -342,6 +388,7 @@ protected function getSupportedParameters(): array 'section', 'state', 'visible', + 'tag_id', 'sort', 'limit', 'offset', diff --git a/tests/lib/Unit/Core/Site/QueryType/Base/CustomQueryTypeTest.php b/tests/lib/Unit/Core/Site/QueryType/Base/CustomQueryTypeTest.php index 72cb825a..2ef482bf 100644 --- a/tests/lib/Unit/Core/Site/QueryType/Base/CustomQueryTypeTest.php +++ b/tests/lib/Unit/Core/Site/QueryType/Base/CustomQueryTypeTest.php @@ -52,6 +52,7 @@ public function testGetSupportedParameters(): void 'section', 'state', 'visible', + 'tag_id', 'sort', 'limit', 'offset', diff --git a/tests/lib/Unit/Core/Site/QueryType/Content/FetchTest.php b/tests/lib/Unit/Core/Site/QueryType/Content/FetchTest.php index f0fbf68c..9a9cef2a 100644 --- a/tests/lib/Unit/Core/Site/QueryType/Content/FetchTest.php +++ b/tests/lib/Unit/Core/Site/QueryType/Content/FetchTest.php @@ -17,6 +17,7 @@ use Netgen\IbexaSiteApi\Core\Site\QueryType\QueryType; use Netgen\IbexaSiteApi\Core\Site\Settings; use Netgen\IbexaSiteApi\Tests\Unit\Core\Site\QueryType\QueryTypeBaseTest; +use Netgen\TagsBundle\API\Repository\Values\Content\Query\Criterion\TagId; /** * Fetch Content QueryType test case. @@ -291,6 +292,46 @@ public function providerForTestGetQuery(): array ], ]), ], + [ + true, + [ + 'tag_id' => 223, + ], + new Query([ + 'filter' => new TagId(223), + ]), + ], + [ + true, + [ + 'tag_id' => [223, 224, 1], + ], + new Query([ + 'filter' => new TagId([223, 224, 1]), + ]), + ], + [ + true, + [ + 'tag_id' => [ + 'eq' => 225, + ], + ], + new Query([ + 'filter' => new TagId(225), + ]), + ], + [ + true, + [ + 'tag_id' => [ + 'in' => [225, 226], + ], + ], + new Query([ + 'filter' => new TagId([225, 226]), + ]), + ], ]; } @@ -329,6 +370,11 @@ public function providerForTestGetQueryWithInvalidOptions(): array ], ], ], + [ + [ + 'tag_id' => '223', + ], + ], ]; } @@ -385,6 +431,7 @@ protected function getSupportedParameters(): array 'section', 'state', 'visible', + 'tag_id', 'sort', 'limit', 'offset', diff --git a/tests/lib/Unit/Core/Site/QueryType/Content/Relations/AllTagFieldsTest.php b/tests/lib/Unit/Core/Site/QueryType/Content/Relations/AllTagFieldsTest.php index 0ca8b4bd..92b784c5 100644 --- a/tests/lib/Unit/Core/Site/QueryType/Content/Relations/AllTagFieldsTest.php +++ b/tests/lib/Unit/Core/Site/QueryType/Content/Relations/AllTagFieldsTest.php @@ -222,6 +222,66 @@ public function providerForTestGetQuery(): array ], ]), ], + [ + true, + [ + 'content' => $contentWithTags, + 'tag_id' => 223, + ], + new Query([ + 'filter' => new LogicalAnd([ + new TagId(223), + new TagId([1, 2, 3, 4]), + new LogicalNot(new ContentId(42)), + ]), + ]), + ], + [ + true, + [ + 'content' => $contentWithTags, + 'tag_id' => [223, 224, 1], + ], + new Query([ + 'filter' => new LogicalAnd([ + new TagId([223, 224, 1]), + new TagId([1, 2, 3, 4]), + new LogicalNot(new ContentId(42)), + ]), + ]), + ], + [ + true, + [ + 'content' => $contentWithTags, + 'tag_id' => [ + 'eq' => 225, + ], + ], + new Query([ + 'filter' => new LogicalAnd([ + new TagId(225), + new TagId([1, 2, 3, 4]), + new LogicalNot(new ContentId(42)), + ]), + ]), + ], + [ + true, + [ + 'content' => $contentWithTags, + 'tag_id' => [ + 'in' => [225, 226], + ], + ], + new Query([ + 'filter' => new LogicalAnd([ + new TagId([225, 226]), + new TagId([1, 2, 3, 4]), + new LogicalNot(new ContentId(42)), + ]), + ]), + ], ]; } @@ -260,6 +320,12 @@ public function providerForTestGetQueryWithInvalidOptions(): array 'offset' => 'ten', ], ], + [ + [ + 'content' => $content, + 'tag_id' => 'ten', + ], + ], ]; } @@ -427,6 +493,7 @@ protected function getSupportedParameters(): array 'section', 'state', 'visible', + 'tag_id', 'sort', 'limit', 'offset', diff --git a/tests/lib/Unit/Core/Site/QueryType/Content/Relations/ForwardFieldsTest.php b/tests/lib/Unit/Core/Site/QueryType/Content/Relations/ForwardFieldsTest.php index 696ac8fa..5d1a5a8b 100644 --- a/tests/lib/Unit/Core/Site/QueryType/Content/Relations/ForwardFieldsTest.php +++ b/tests/lib/Unit/Core/Site/QueryType/Content/Relations/ForwardFieldsTest.php @@ -31,6 +31,7 @@ use Netgen\IbexaSiteApi\Core\Site\Values\Content; use Netgen\IbexaSiteApi\Tests\Unit\Core\Site\ContentFieldsMockTrait; use Netgen\IbexaSiteApi\Tests\Unit\Core\Site\QueryType\QueryTypeBaseTest; +use Netgen\TagsBundle\API\Repository\Values\Content\Query\Criterion\TagId; use OutOfBoundsException; use Psr\Log\NullLogger; use RuntimeException; @@ -207,6 +208,66 @@ public function providerForTestGetQuery(): array ], ]), ], + [ + true, + [ + 'content' => $content, + 'relation_field' => ['relations_a', 'relations_b'], + 'tag_id' => 223, + ], + new Query([ + 'filter' => new LogicalAnd([ + new TagId(223), + new ContentId([1, 2, 3, 4]), + ]), + ]), + ], + [ + true, + [ + 'content' => $content, + 'relation_field' => ['relations_a', 'relations_b'], + 'tag_id' => [223, 224, 1], + ], + new Query([ + 'filter' => new LogicalAnd([ + new TagId([223, 224, 1]), + new ContentId([1, 2, 3, 4]), + ]), + ]), + ], + [ + true, + [ + 'content' => $content, + 'relation_field' => ['relations_a', 'relations_b'], + 'tag_id' => [ + 'eq' => 225, + ], + ], + new Query([ + 'filter' => new LogicalAnd([ + new TagId(225), + new ContentId([1, 2, 3, 4]), + ]), + ]), + ], + [ + true, + [ + 'content' => $content, + 'relation_field' => ['relations_a', 'relations_b'], + 'tag_id' => [ + 'in' => [225, 226], + ], + ], + new Query([ + 'filter' => new LogicalAnd([ + new TagId([225, 226]), + new ContentId([1, 2, 3, 4]), + ]), + ]), + ], ]; } @@ -314,6 +375,13 @@ public function providerForTestGetQueryWithInvalidOptions(): array 'relation_field' => [1], ], ], + [ + [ + 'content' => $content, + 'relation_field' => 'field', + 'tag_id' => 'ten', + ], + ], ]; } @@ -449,6 +517,7 @@ protected function getSupportedParameters(): array 'section', 'state', 'visible', + 'tag_id', 'sort', 'limit', 'offset', diff --git a/tests/lib/Unit/Core/Site/QueryType/Content/Relations/ReverseFieldsTest.php b/tests/lib/Unit/Core/Site/QueryType/Content/Relations/ReverseFieldsTest.php index 034cd801..0731cf60 100644 --- a/tests/lib/Unit/Core/Site/QueryType/Content/Relations/ReverseFieldsTest.php +++ b/tests/lib/Unit/Core/Site/QueryType/Content/Relations/ReverseFieldsTest.php @@ -22,6 +22,7 @@ use Netgen\IbexaSiteApi\Core\Site\Values\Content; use Netgen\IbexaSiteApi\Tests\Unit\Core\Site\ContentFieldsMockTrait; use Netgen\IbexaSiteApi\Tests\Unit\Core\Site\QueryType\QueryTypeBaseTest; +use Netgen\TagsBundle\API\Repository\Values\Content\Query\Criterion\TagId; use Psr\Log\NullLogger; /** @@ -199,6 +200,70 @@ public function providerForTestGetQuery(): array ], ]), ], + [ + true, + [ + 'content' => $content, + 'relation_field' => ['relations_a', 'relations_b'], + 'tag_id' => 223, + ], + new Query([ + 'filter' => new LogicalAnd([ + new TagId(223), + new FieldRelation('relations_a', Operator::CONTAINS, [42]), + new FieldRelation('relations_b', Operator::CONTAINS, [42]), + ]), + ]), + ], + [ + true, + [ + 'content' => $content, + 'relation_field' => ['relations_a', 'relations_b'], + 'tag_id' => [223, 224, 1], + ], + new Query([ + 'filter' => new LogicalAnd([ + new TagId([223, 224, 1]), + new FieldRelation('relations_a', Operator::CONTAINS, [42]), + new FieldRelation('relations_b', Operator::CONTAINS, [42]), + ]), + ]), + ], + [ + true, + [ + 'content' => $content, + 'relation_field' => ['relations_a', 'relations_b'], + 'tag_id' => [ + 'eq' => 225, + ], + ], + new Query([ + 'filter' => new LogicalAnd([ + new TagId(225), + new FieldRelation('relations_a', Operator::CONTAINS, [42]), + new FieldRelation('relations_b', Operator::CONTAINS, [42]), + ]), + ]), + ], + [ + true, + [ + 'content' => $content, + 'relation_field' => ['relations_a', 'relations_b'], + 'tag_id' => [ + 'in' => [225, 226], + ], + ], + new Query([ + 'filter' => new LogicalAnd([ + new TagId([225, 226]), + new FieldRelation('relations_a', Operator::CONTAINS, [42]), + new FieldRelation('relations_b', Operator::CONTAINS, [42]), + ]), + ]), + ], ]; } @@ -248,6 +313,13 @@ public function providerForTestGetQueryWithInvalidOptions(): array 'relation_field' => [1], ], ], + [ + [ + 'content' => $content, + 'relation_field' => 'field', + 'tag_id' => 'ten', + ], + ], ]; } @@ -340,6 +412,7 @@ protected function getSupportedParameters(): array 'section', 'state', 'visible', + 'tag_id', 'sort', 'limit', 'offset', diff --git a/tests/lib/Unit/Core/Site/QueryType/Content/Relations/TagFieldsTest.php b/tests/lib/Unit/Core/Site/QueryType/Content/Relations/TagFieldsTest.php index 0fe3de10..4511cd6e 100644 --- a/tests/lib/Unit/Core/Site/QueryType/Content/Relations/TagFieldsTest.php +++ b/tests/lib/Unit/Core/Site/QueryType/Content/Relations/TagFieldsTest.php @@ -211,6 +211,70 @@ public function providerForTestGetQuery(): array ], ]), ], + [ + true, + [ + 'content' => $content, + 'relation_field' => ['tags_a', 'tags_b'], + 'tag_id' => 223, + ], + new Query([ + 'filter' => new LogicalAnd([ + new TagId(223), + new TagId([1, 2, 3, 4]), + new LogicalNot(new ContentId(42)), + ]), + ]), + ], + [ + true, + [ + 'content' => $content, + 'relation_field' => ['tags_a', 'tags_b'], + 'tag_id' => [223, 224, 1], + ], + new Query([ + 'filter' => new LogicalAnd([ + new TagId([223, 224, 1]), + new TagId([1, 2, 3, 4]), + new LogicalNot(new ContentId(42)), + ]), + ]), + ], + [ + true, + [ + 'content' => $content, + 'relation_field' => ['tags_a', 'tags_b'], + 'tag_id' => [ + 'eq' => 225, + ], + ], + new Query([ + 'filter' => new LogicalAnd([ + new TagId(225), + new TagId([1, 2, 3, 4]), + new LogicalNot(new ContentId(42)), + ]), + ]), + ], + [ + true, + [ + 'content' => $content, + 'relation_field' => ['tags_a', 'tags_b'], + 'tag_id' => [ + 'in' => [225, 226], + ], + ], + new Query([ + 'filter' => new LogicalAnd([ + new TagId([225, 226]), + new TagId([1, 2, 3, 4]), + new LogicalNot(new ContentId(42)), + ]), + ]), + ], ]; } @@ -318,6 +382,13 @@ public function providerForTestGetQueryWithInvalidOptions(): array 'relation_field' => [1], ], ], + [ + [ + 'content' => $content, + 'relation_field' => 'field', + 'tag_id' => 'ten', + ], + ], ]; } @@ -462,6 +533,7 @@ protected function getSupportedParameters(): array 'section', 'state', 'visible', + 'tag_id', 'sort', 'limit', 'offset', diff --git a/tests/lib/Unit/Core/Site/QueryType/Location/ChildrenTest.php b/tests/lib/Unit/Core/Site/QueryType/Location/ChildrenTest.php index c35ec0f5..e4dad496 100644 --- a/tests/lib/Unit/Core/Site/QueryType/Location/ChildrenTest.php +++ b/tests/lib/Unit/Core/Site/QueryType/Location/ChildrenTest.php @@ -26,6 +26,7 @@ use Netgen\IbexaSiteApi\Core\Site\Values\Location; use Netgen\IbexaSiteApi\Tests\Unit\Core\Site\ContentFieldsMockTrait; use Netgen\IbexaSiteApi\Tests\Unit\Core\Site\QueryType\QueryTypeBaseTest; +use Netgen\TagsBundle\API\Repository\Values\Content\Query\Criterion\TagId; use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\NullLogger; @@ -239,6 +240,74 @@ public function providerForTestGetQuery(): array ], ]), ], + [ + true, + [ + 'location' => $location, + 'tag_id' => 223, + ], + new LocationQuery([ + 'filter' => new LogicalAnd([ + new TagId(223), + new ParentLocationId(42), + ]), + 'sortClauses' => [ + new Priority(Query::SORT_DESC), + ], + ]), + ], + [ + true, + [ + 'location' => $location, + 'tag_id' => [223, 224, 1], + ], + new LocationQuery([ + 'filter' => new LogicalAnd([ + new TagId([223, 224, 1]), + new ParentLocationId(42), + ]), + 'sortClauses' => [ + new Priority(Query::SORT_DESC), + ], + ]), + ], + [ + true, + [ + 'location' => $location, + 'tag_id' => [ + 'eq' => 225, + ], + ], + new LocationQuery([ + 'filter' => new LogicalAnd([ + new TagId(225), + new ParentLocationId(42), + ]), + 'sortClauses' => [ + new Priority(Query::SORT_DESC), + ], + ]), + ], + [ + true, + [ + 'location' => $location, + 'tag_id' => [ + 'in' => [225, 226], + ], + ], + new LocationQuery([ + 'filter' => new LogicalAnd([ + new TagId([225, 226]), + new ParentLocationId(42), + ]), + 'sortClauses' => [ + new Priority(Query::SORT_DESC), + ], + ]), + ], ]; } @@ -277,6 +346,12 @@ public function providerForTestGetQueryWithInvalidOptions(): array 'offset' => 'ten', ], ], + [ + [ + 'location' => $location, + 'tag_id' => 'ten', + ], + ], ]; } @@ -364,6 +439,7 @@ protected function getSupportedParameters(): array 'section', 'state', 'visible', + 'tag_id', 'sort', 'limit', 'offset', diff --git a/tests/lib/Unit/Core/Site/QueryType/Location/FetchTest.php b/tests/lib/Unit/Core/Site/QueryType/Location/FetchTest.php index 6a55e6d0..9d42cb0e 100644 --- a/tests/lib/Unit/Core/Site/QueryType/Location/FetchTest.php +++ b/tests/lib/Unit/Core/Site/QueryType/Location/FetchTest.php @@ -25,6 +25,7 @@ use Netgen\IbexaSiteApi\Core\Site\QueryType\QueryType; use Netgen\IbexaSiteApi\Core\Site\Settings; use Netgen\IbexaSiteApi\Tests\Unit\Core\Site\QueryType\QueryTypeBaseTest; +use Netgen\TagsBundle\API\Repository\Values\Content\Query\Criterion\TagId; /** * Fetch Location QueryType test case. @@ -225,6 +226,46 @@ public function providerForTestGetQuery(): array ]), ]), ], + [ + true, + [ + 'tag_id' => 223, + ], + new LocationQuery([ + 'filter' => new TagId(223), + ]), + ], + [ + true, + [ + 'tag_id' => [223, 224, 1], + ], + new LocationQuery([ + 'filter' => new TagId([223, 224, 1]), + ]), + ], + [ + true, + [ + 'tag_id' => [ + 'eq' => 225, + ], + ], + new LocationQuery([ + 'filter' => new TagId(225), + ]), + ], + [ + true, + [ + 'tag_id' => [ + 'in' => [225, 226], + ], + ], + new LocationQuery([ + 'filter' => new TagId([225, 226]), + ]), + ], ]; } @@ -256,6 +297,11 @@ public function providerForTestGetQueryWithInvalidOptions(): array 'offset' => 'ten', ], ], + [ + [ + 'tag_id' => '223', + ], + ], ]; } @@ -312,6 +358,7 @@ protected function getSupportedParameters(): array 'section', 'state', 'visible', + 'tag_id', 'sort', 'limit', 'offset', diff --git a/tests/lib/Unit/Core/Site/QueryType/Location/Relations/AllTagFieldsTest.php b/tests/lib/Unit/Core/Site/QueryType/Location/Relations/AllTagFieldsTest.php index 1c1d5605..7d96607d 100644 --- a/tests/lib/Unit/Core/Site/QueryType/Location/Relations/AllTagFieldsTest.php +++ b/tests/lib/Unit/Core/Site/QueryType/Location/Relations/AllTagFieldsTest.php @@ -230,6 +230,74 @@ public function providerForTestGetQuery(): array ], ]), ], + [ + true, + [ + 'content' => $contentWithTags, + 'tag_id' => 223, + ], + new LocationQuery([ + 'filter' => new LogicalAnd([ + new IsMainLocation(IsMainLocation::MAIN), + new Visible(true), + new TagId(223), + new TagId([1, 2, 3, 4]), + new LogicalNot(new ContentId(42)), + ]), + ]), + ], + [ + true, + [ + 'content' => $contentWithTags, + 'tag_id' => [223, 224, 1], + ], + new LocationQuery([ + 'filter' => new LogicalAnd([ + new IsMainLocation(IsMainLocation::MAIN), + new Visible(true), + new TagId([223, 224, 1]), + new TagId([1, 2, 3, 4]), + new LogicalNot(new ContentId(42)), + ]), + ]), + ], + [ + true, + [ + 'content' => $contentWithTags, + 'tag_id' => [ + 'eq' => 225, + ], + ], + new LocationQuery([ + 'filter' => new LogicalAnd([ + new IsMainLocation(IsMainLocation::MAIN), + new Visible(true), + new TagId(225), + new TagId([1, 2, 3, 4]), + new LogicalNot(new ContentId(42)), + ]), + ]), + ], + [ + true, + [ + 'content' => $contentWithTags, + 'tag_id' => [ + 'in' => [225, 226], + ], + ], + new LocationQuery([ + 'filter' => new LogicalAnd([ + new IsMainLocation(IsMainLocation::MAIN), + new Visible(true), + new TagId([225, 226]), + new TagId([1, 2, 3, 4]), + new LogicalNot(new ContentId(42)), + ]), + ]), + ], ]; } @@ -268,6 +336,12 @@ public function providerForTestGetQueryWithInvalidOptions(): array 'offset' => 'ten', ], ], + [ + [ + 'content' => $content, + 'tag_id' => 'ten', + ], + ], ]; } @@ -435,6 +509,7 @@ protected function getSupportedParameters(): array 'section', 'state', 'visible', + 'tag_id', 'sort', 'limit', 'offset', diff --git a/tests/lib/Unit/Core/Site/QueryType/Location/Relations/ForwardFieldsTest.php b/tests/lib/Unit/Core/Site/QueryType/Location/Relations/ForwardFieldsTest.php index 604f0401..12132dee 100644 --- a/tests/lib/Unit/Core/Site/QueryType/Location/Relations/ForwardFieldsTest.php +++ b/tests/lib/Unit/Core/Site/QueryType/Location/Relations/ForwardFieldsTest.php @@ -33,6 +33,7 @@ use Netgen\IbexaSiteApi\Core\Site\Values\Content; use Netgen\IbexaSiteApi\Tests\Unit\Core\Site\ContentFieldsMockTrait; use Netgen\IbexaSiteApi\Tests\Unit\Core\Site\QueryType\QueryTypeBaseTest; +use Netgen\TagsBundle\API\Repository\Values\Content\Query\Criterion\TagId; use OutOfBoundsException; use Psr\Log\NullLogger; use RuntimeException; @@ -214,6 +215,74 @@ public function providerForTestGetQuery(): array ], ]), ], + [ + true, + [ + 'content' => $content, + 'relation_field' => ['relations_a', 'relations_b'], + 'tag_id' => 223, + ], + new LocationQuery([ + 'filter' => new LogicalAnd([ + new IsMainLocation(IsMainLocation::MAIN), + new Visible(true), + new TagId(223), + new ContentId([1, 2, 3, 4]), + ]), + ]), + ], + [ + true, + [ + 'content' => $content, + 'relation_field' => ['relations_a', 'relations_b'], + 'tag_id' => [223, 224, 1], + ], + new LocationQuery([ + 'filter' => new LogicalAnd([ + new IsMainLocation(IsMainLocation::MAIN), + new Visible(true), + new TagId([223, 224, 1]), + new ContentId([1, 2, 3, 4]), + ]), + ]), + ], + [ + true, + [ + 'content' => $content, + 'relation_field' => ['relations_a', 'relations_b'], + 'tag_id' => [ + 'eq' => 225, + ], + ], + new LocationQuery([ + 'filter' => new LogicalAnd([ + new IsMainLocation(IsMainLocation::MAIN), + new Visible(true), + new TagId(225), + new ContentId([1, 2, 3, 4]), + ]), + ]), + ], + [ + true, + [ + 'content' => $content, + 'relation_field' => ['relations_a', 'relations_b'], + 'tag_id' => [ + 'in' => [225, 226], + ], + ], + new LocationQuery([ + 'filter' => new LogicalAnd([ + new IsMainLocation(IsMainLocation::MAIN), + new Visible(true), + new TagId([225, 226]), + new ContentId([1, 2, 3, 4]), + ]), + ]), + ], ]; } @@ -322,6 +391,13 @@ public function providerForTestGetQueryWithInvalidOptions(): array 'relation_field' => [1], ], ], + [ + [ + 'content' => $content, + 'relation_field' => 'field', + 'tag_id' => 'something', + ], + ], ]; } @@ -457,6 +533,7 @@ protected function getSupportedParameters(): array 'section', 'state', 'visible', + 'tag_id', 'sort', 'limit', 'offset', diff --git a/tests/lib/Unit/Core/Site/QueryType/Location/Relations/ReverseFieldsTest.php b/tests/lib/Unit/Core/Site/QueryType/Location/Relations/ReverseFieldsTest.php index 79c8306a..6cf4789f 100644 --- a/tests/lib/Unit/Core/Site/QueryType/Location/Relations/ReverseFieldsTest.php +++ b/tests/lib/Unit/Core/Site/QueryType/Location/Relations/ReverseFieldsTest.php @@ -24,6 +24,7 @@ use Netgen\IbexaSiteApi\Core\Site\Values\Content; use Netgen\IbexaSiteApi\Tests\Unit\Core\Site\ContentFieldsMockTrait; use Netgen\IbexaSiteApi\Tests\Unit\Core\Site\QueryType\QueryTypeBaseTest; +use Netgen\TagsBundle\API\Repository\Values\Content\Query\Criterion\TagId; use Psr\Log\NullLogger; /** @@ -206,6 +207,78 @@ public function providerForTestGetQuery(): array ], ]), ], + [ + true, + [ + 'content' => $content, + 'relation_field' => ['relations_a', 'relations_b'], + 'tag_id' => 223, + ], + new LocationQuery([ + 'filter' => new LogicalAnd([ + new IsMainLocation(IsMainLocation::MAIN), + new Visible(true), + new TagId(223), + new FieldRelation('relations_a', Operator::CONTAINS, [42]), + new FieldRelation('relations_b', Operator::CONTAINS, [42]), + ]), + ]), + ], + [ + true, + [ + 'content' => $content, + 'relation_field' => ['relations_a', 'relations_b'], + 'tag_id' => [223, 224, 1], + ], + new LocationQuery([ + 'filter' => new LogicalAnd([ + new IsMainLocation(IsMainLocation::MAIN), + new Visible(true), + new TagId([223, 224, 1]), + new FieldRelation('relations_a', Operator::CONTAINS, [42]), + new FieldRelation('relations_b', Operator::CONTAINS, [42]), + ]), + ]), + ], + [ + true, + [ + 'content' => $content, + 'relation_field' => ['relations_a', 'relations_b'], + 'tag_id' => [ + 'eq' => 225, + ], + ], + new LocationQuery([ + 'filter' => new LogicalAnd([ + new IsMainLocation(IsMainLocation::MAIN), + new Visible(true), + new TagId(225), + new FieldRelation('relations_a', Operator::CONTAINS, [42]), + new FieldRelation('relations_b', Operator::CONTAINS, [42]), + ]), + ]), + ], + [ + true, + [ + 'content' => $content, + 'relation_field' => ['relations_a', 'relations_b'], + 'tag_id' => [ + 'in' => [225, 226], + ], + ], + new LocationQuery([ + 'filter' => new LogicalAnd([ + new IsMainLocation(IsMainLocation::MAIN), + new Visible(true), + new TagId([225, 226]), + new FieldRelation('relations_a', Operator::CONTAINS, [42]), + new FieldRelation('relations_b', Operator::CONTAINS, [42]), + ]), + ]), + ], ]; } @@ -255,6 +328,13 @@ public function providerForTestGetQueryWithInvalidOptions(): array 'relation_field' => [1], ], ], + [ + [ + 'content' => $content, + 'relation_field' => 'field', + 'tag_id' => 'ten', + ], + ], ]; } @@ -347,6 +427,7 @@ protected function getSupportedParameters(): array 'section', 'state', 'visible', + 'tag_id', 'sort', 'limit', 'offset', diff --git a/tests/lib/Unit/Core/Site/QueryType/Location/Relations/TagFieldsTest.php b/tests/lib/Unit/Core/Site/QueryType/Location/Relations/TagFieldsTest.php index 569fd908..71ca1397 100644 --- a/tests/lib/Unit/Core/Site/QueryType/Location/Relations/TagFieldsTest.php +++ b/tests/lib/Unit/Core/Site/QueryType/Location/Relations/TagFieldsTest.php @@ -218,6 +218,78 @@ public function providerForTestGetQuery(): array ], ]), ], + [ + true, + [ + 'content' => $content, + 'relation_field' => ['tags_a', 'tags_b'], + 'tag_id' => 223, + ], + new LocationQuery([ + 'filter' => new LogicalAnd([ + new IsMainLocation(IsMainLocation::MAIN), + new Visible(true), + new TagId(223), + new TagId([1, 2, 3, 4]), + new LogicalNot(new ContentId(42)), + ]), + ]), + ], + [ + true, + [ + 'content' => $content, + 'relation_field' => ['tags_a', 'tags_b'], + 'tag_id' => [223, 224, 1], + ], + new LocationQuery([ + 'filter' => new LogicalAnd([ + new IsMainLocation(IsMainLocation::MAIN), + new Visible(true), + new TagId([223, 224, 1]), + new TagId([1, 2, 3, 4]), + new LogicalNot(new ContentId(42)), + ]), + ]), + ], + [ + true, + [ + 'content' => $content, + 'relation_field' => ['tags_a', 'tags_b'], + 'tag_id' => [ + 'eq' => 225, + ], + ], + new LocationQuery([ + 'filter' => new LogicalAnd([ + new IsMainLocation(IsMainLocation::MAIN), + new Visible(true), + new TagId(225), + new TagId([1, 2, 3, 4]), + new LogicalNot(new ContentId(42)), + ]), + ]), + ], + [ + true, + [ + 'content' => $content, + 'relation_field' => ['tags_a', 'tags_b'], + 'tag_id' => [ + 'in' => [225, 226], + ], + ], + new LocationQuery([ + 'filter' => new LogicalAnd([ + new IsMainLocation(IsMainLocation::MAIN), + new Visible(true), + new TagId([225, 226]), + new TagId([1, 2, 3, 4]), + new LogicalNot(new ContentId(42)), + ]), + ]), + ], ]; } @@ -326,6 +398,13 @@ public function providerForTestGetQueryWithInvalidOptions(): array 'relation_field' => [1], ], ], + [ + [ + 'content' => $content, + 'relation_field' => 'field', + 'tag_id' => 'something', + ], + ], ]; } @@ -470,6 +549,7 @@ protected function getSupportedParameters(): array 'section', 'state', 'visible', + 'tag_id', 'sort', 'limit', 'offset', diff --git a/tests/lib/Unit/Core/Site/QueryType/Location/SiblingsTest.php b/tests/lib/Unit/Core/Site/QueryType/Location/SiblingsTest.php index 87959be5..cc6f955f 100644 --- a/tests/lib/Unit/Core/Site/QueryType/Location/SiblingsTest.php +++ b/tests/lib/Unit/Core/Site/QueryType/Location/SiblingsTest.php @@ -30,6 +30,7 @@ use Netgen\IbexaSiteApi\Core\Site\Values\Location; use Netgen\IbexaSiteApi\Tests\Unit\Core\Site\ContentFieldsMockTrait; use Netgen\IbexaSiteApi\Tests\Unit\Core\Site\QueryType\QueryTypeBaseTest; +use Netgen\TagsBundle\API\Repository\Values\Content\Query\Criterion\TagId; use Psr\Log\NullLogger; /** @@ -265,6 +266,78 @@ public function providerForTestGetQuery(): array ], ]), ], + [ + true, + [ + 'location' => $location, + 'tag_id' => 223, + ], + new LocationQuery([ + 'filter' => new LogicalAnd([ + new TagId(223), + new ParentLocationId(42), + new LogicalNot(new LocationId(24)), + ]), + 'sortClauses' => [ + new Depth(Query::SORT_ASC), + ], + ]), + ], + [ + true, + [ + 'location' => $location, + 'tag_id' => [223, 224, 1], + ], + new LocationQuery([ + 'filter' => new LogicalAnd([ + new TagId([223, 224, 1]), + new ParentLocationId(42), + new LogicalNot(new LocationId(24)), + ]), + 'sortClauses' => [ + new Depth(Query::SORT_ASC), + ], + ]), + ], + [ + true, + [ + 'location' => $location, + 'tag_id' => [ + 'eq' => 225, + ], + ], + new LocationQuery([ + 'filter' => new LogicalAnd([ + new TagId(225), + new ParentLocationId(42), + new LogicalNot(new LocationId(24)), + ]), + 'sortClauses' => [ + new Depth(Query::SORT_ASC), + ], + ]), + ], + [ + true, + [ + 'location' => $location, + 'tag_id' => [ + 'in' => [225, 226], + ], + ], + new LocationQuery([ + 'filter' => new LogicalAnd([ + new TagId([225, 226]), + new ParentLocationId(42), + new LogicalNot(new LocationId(24)), + ]), + 'sortClauses' => [ + new Depth(Query::SORT_ASC), + ], + ]), + ], ]; } @@ -303,6 +376,12 @@ public function providerForTestGetQueryWithInvalidOptions(): array 'offset' => 'ten', ], ], + [ + [ + 'location' => $location, + 'tag_id' => 'ten', + ], + ], ]; } @@ -417,6 +496,7 @@ protected function getSupportedParameters(): array 'section', 'state', 'visible', + 'tag_id', 'sort', 'limit', 'offset', diff --git a/tests/lib/Unit/Core/Site/QueryType/Location/SubtreeTest.php b/tests/lib/Unit/Core/Site/QueryType/Location/SubtreeTest.php index 96088d7c..a26746d3 100644 --- a/tests/lib/Unit/Core/Site/QueryType/Location/SubtreeTest.php +++ b/tests/lib/Unit/Core/Site/QueryType/Location/SubtreeTest.php @@ -28,6 +28,7 @@ use Netgen\IbexaSiteApi\Core\Site\Values\Location; use Netgen\IbexaSiteApi\Tests\Unit\Core\Site\ContentFieldsMockTrait; use Netgen\IbexaSiteApi\Tests\Unit\Core\Site\QueryType\QueryTypeBaseTest; +use Netgen\TagsBundle\API\Repository\Values\Content\Query\Criterion\TagId; use Psr\Log\NullLogger; /** @@ -322,6 +323,66 @@ public function providerForTestGetQuery(): array ], ]), ], + [ + true, + [ + 'location' => $location, + 'tag_id' => 223, + ], + new LocationQuery([ + 'filter' => new LogicalAnd([ + new TagId(223), + new SubtreeCriterion('/3/5/7/11/'), + new LogicalNot(new LocationId(42)), + ]), + ]), + ], + [ + true, + [ + 'location' => $location, + 'tag_id' => [223, 224, 1], + ], + new LocationQuery([ + 'filter' => new LogicalAnd([ + new TagId([223, 224, 1]), + new SubtreeCriterion('/3/5/7/11/'), + new LogicalNot(new LocationId(42)), + ]), + ]), + ], + [ + true, + [ + 'location' => $location, + 'tag_id' => [ + 'eq' => 225, + ], + ], + new LocationQuery([ + 'filter' => new LogicalAnd([ + new TagId(225), + new SubtreeCriterion('/3/5/7/11/'), + new LogicalNot(new LocationId(42)), + ]), + ]), + ], + [ + true, + [ + 'location' => $location, + 'tag_id' => [ + 'in' => [225, 226], + ], + ], + new LocationQuery([ + 'filter' => new LogicalAnd([ + new TagId([225, 226]), + new SubtreeCriterion('/3/5/7/11/'), + new LogicalNot(new LocationId(42)), + ]), + ]), + ], ]; } @@ -360,6 +421,12 @@ public function providerForTestGetQueryWithInvalidOptions(): array 'offset' => 'ten', ], ], + [ + [ + 'location' => $location, + 'tag_id' => '223', + ], + ], ]; } @@ -448,6 +515,7 @@ protected function getSupportedParameters(): array 'section', 'state', 'visible', + 'tag_id', 'sort', 'limit', 'offset', diff --git a/tests/lib/Unit/Core/Site/QueryType/SortClauseParserTest.php b/tests/lib/Unit/Core/Site/QueryType/SortClauseParserTest.php index 4527b6ca..3589bb74 100644 --- a/tests/lib/Unit/Core/Site/QueryType/SortClauseParserTest.php +++ b/tests/lib/Unit/Core/Site/QueryType/SortClauseParserTest.php @@ -152,7 +152,7 @@ public function testParseInvalid(string $stringDefinition, string $message): voi { $this->expectException(InvalidArgumentException::class); $message = preg_quote($message, '/'); - self::matchesRegularExpression("/$message/"); + self::matchesRegularExpression("/{$message}/"); $parser = $this->getParserUnderTest(); $parser->parse($stringDefinition);