diff --git a/src/Metadata/Resource/Factory/ParameterResourceMetadataCollectionFactory.php b/src/Metadata/Resource/Factory/ParameterResourceMetadataCollectionFactory.php index 656d82ca21..cd9929f91a 100644 --- a/src/Metadata/Resource/Factory/ParameterResourceMetadataCollectionFactory.php +++ b/src/Metadata/Resource/Factory/ParameterResourceMetadataCollectionFactory.php @@ -259,10 +259,6 @@ private function setDefaults(string $key, Parameter $parameter, ?object $filter, $parameter = $parameter->withProperty($key); } - if ($this->nameConverter && $property = $parameter->getProperty()) { - $parameter = $parameter->withProperty($this->nameConverter->normalize($property)); - } - if (isset($properties[$currentKey]) && ($eloquentRelation = ($properties[$currentKey]->getExtraProperties()['eloquent_relation'] ?? null)) && isset($eloquentRelation['foreign_key'])) { $parameter = $parameter->withProperty($eloquentRelation['foreign_key']); } diff --git a/tests/Fixtures/TestBundle/Document/Chicken.php b/tests/Fixtures/TestBundle/Document/Chicken.php index 2fe846ecae..32d394a4a1 100644 --- a/tests/Fixtures/TestBundle/Document/Chicken.php +++ b/tests/Fixtures/TestBundle/Document/Chicken.php @@ -33,6 +33,10 @@ filter: new PartialSearchFilter(), property: 'name', ), + 'nameConverted' => new QueryParameter(filter: new ExactFilter()), + 'nameConvertedAlias' => new QueryParameter(filter: new ExactFilter(), property: 'nameConverted'), + 'nameNotConverted' => new QueryParameter(filter: new ExactFilter()), + 'nameNotConvertedAlias' => new QueryParameter(filter: new ExactFilter(), property: 'nameNotConverted'), 'autocomplete' => new QueryParameter(filter: new FreeTextQueryFilter(new OrFilter(new ExactFilter())), properties: ['name', 'ean']), 'q' => new QueryParameter(filter: new FreeTextQueryFilter(new PartialSearchFilter()), properties: ['name', 'ean']), ], @@ -45,6 +49,12 @@ class Chicken #[ODM\Field(type: 'string')] private string $name; + #[ODM\Field(type: 'string')] + private string $nameConverted; + + #[ODM\Field(type: 'string')] + private string $nameNotConverted; + #[ODM\Field(type: 'string', nullable: true)] private ?string $ean; @@ -64,10 +74,22 @@ public function getName(): ?string public function setName(string $name): self { $this->name = $name; + $this->nameConverted = $name; + $this->nameNotConverted = $name; return $this; } + public function getNameConverted(): ?string + { + return $this->nameConverted; + } + + public function getNameNotConverted(): ?string + { + return $this->nameNotConverted; + } + public function getEan(): ?string { return $this->ean; diff --git a/tests/Fixtures/TestBundle/Document/FilteredBooleanParameter.php b/tests/Fixtures/TestBundle/Document/FilteredBooleanParameter.php index 8964c3d49d..b6b78fce77 100644 --- a/tests/Fixtures/TestBundle/Document/FilteredBooleanParameter.php +++ b/tests/Fixtures/TestBundle/Document/FilteredBooleanParameter.php @@ -33,11 +33,35 @@ property: 'active', nativeType: new BuiltinType(TypeIdentifier::BOOL), ), + 'nameConverted' => new QueryParameter( + filter: new BooleanFilter(), + nativeType: new BuiltinType(TypeIdentifier::BOOL), + ), + 'nameNotConverted' => new QueryParameter( + filter: new BooleanFilter(), + nativeType: new BuiltinType(TypeIdentifier::BOOL), + ), + 'aliasWithNameConverter' => new QueryParameter( + filter: new BooleanFilter(), + property: 'nameConverted', + nativeType: new BuiltinType(TypeIdentifier::BOOL), + ), + 'aliasWithoutNameConverter' => new QueryParameter( + filter: new BooleanFilter(), + property: 'nameNotConverted', + nativeType: new BuiltinType(TypeIdentifier::BOOL), + ), ], )] #[ODM\Document] class FilteredBooleanParameter { + #[ODM\Field(type: 'bool', nullable: true)] + private ?bool $nameConverted; + + #[ODM\Field(type: 'bool', nullable: true)] + private ?bool $nameNotConverted; + public function __construct( #[ODM\Id(type: 'int', strategy: 'INCREMENT')] public ?int $id = null, @@ -45,6 +69,8 @@ public function __construct( #[ODM\Field(type: 'bool', nullable: true)] public ?bool $active = null, ) { + $this->nameConverted = $this->active; + $this->nameNotConverted = $this->active; } public function getId(): ?int @@ -60,5 +86,7 @@ public function isActive(): bool public function setActive(?bool $active): void { $this->active = $active; + $this->nameConverted = $active; + $this->nameNotConverted = $active; } } diff --git a/tests/Fixtures/TestBundle/Entity/Chicken.php b/tests/Fixtures/TestBundle/Entity/Chicken.php index f3533f5980..d8b339b4a7 100644 --- a/tests/Fixtures/TestBundle/Entity/Chicken.php +++ b/tests/Fixtures/TestBundle/Entity/Chicken.php @@ -33,6 +33,10 @@ filter: new PartialSearchFilter(), property: 'name', ), + 'nameConverted' => new QueryParameter(filter: new ExactFilter()), + 'nameConvertedAlias' => new QueryParameter(filter: new ExactFilter(), property: 'nameConverted'), + 'nameNotConverted' => new QueryParameter(filter: new ExactFilter()), + 'nameNotConvertedAlias' => new QueryParameter(filter: new ExactFilter(), property: 'nameNotConverted'), 'autocomplete' => new QueryParameter(filter: new FreeTextQueryFilter(new OrFilter(new ExactFilter())), properties: ['name', 'ean']), 'q' => new QueryParameter(filter: new FreeTextQueryFilter(new PartialSearchFilter()), properties: ['name', 'ean']), ], @@ -47,6 +51,12 @@ class Chicken #[ORM\Column(type: 'string', length: 255)] private string $name; + #[ORM\Column(type: 'string', length: 255)] + private string $nameConverted; + + #[ORM\Column(type: 'string', length: 255)] + private string $nameNotConverted; + #[ORM\Column(type: 'string', length: 255, nullable: true)] private ?string $ean; @@ -67,10 +77,22 @@ public function getName(): ?string public function setName(string $name): self { $this->name = $name; + $this->nameConverted = $name; + $this->nameNotConverted = $name; return $this; } + public function getNameConverted(): ?string + { + return $this->nameConverted; + } + + public function getNameNotConverted(): ?string + { + return $this->nameNotConverted; + } + public function getEan(): ?string { return $this->ean; diff --git a/tests/Fixtures/TestBundle/Entity/FilteredBooleanParameter.php b/tests/Fixtures/TestBundle/Entity/FilteredBooleanParameter.php index 259c2aafa4..da335f9263 100644 --- a/tests/Fixtures/TestBundle/Entity/FilteredBooleanParameter.php +++ b/tests/Fixtures/TestBundle/Entity/FilteredBooleanParameter.php @@ -33,11 +33,35 @@ property: 'active', nativeType: new BuiltinType(TypeIdentifier::BOOL), ), + 'nameConverted' => new QueryParameter( + filter: new BooleanFilter(), + nativeType: new BuiltinType(TypeIdentifier::BOOL), + ), + 'nameNotConverted' => new QueryParameter( + filter: new BooleanFilter(), + nativeType: new BuiltinType(TypeIdentifier::BOOL), + ), + 'aliasWithNameConverter' => new QueryParameter( + filter: new BooleanFilter(), + property: 'nameConverted', + nativeType: new BuiltinType(TypeIdentifier::BOOL), + ), + 'aliasWithoutNameConverter' => new QueryParameter( + filter: new BooleanFilter(), + property: 'nameNotConverted', + nativeType: new BuiltinType(TypeIdentifier::BOOL), + ), ], )] #[ORM\Entity] class FilteredBooleanParameter { + #[ORM\Column(nullable: true)] + private ?bool $nameConverted; + + #[ORM\Column(nullable: true)] + private ?bool $nameNotConverted; + public function __construct( #[ORM\Column] #[ORM\Id] @@ -47,6 +71,8 @@ public function __construct( #[ORM\Column(nullable: true)] public ?bool $active = null, ) { + $this->nameConverted = $this->active; + $this->nameNotConverted = $this->active; } public function getId(): ?int @@ -62,5 +88,7 @@ public function isActive(): bool public function setActive(?bool $isActive): void { $this->active = $isActive; + $this->nameConverted = $isActive; + $this->nameNotConverted = $isActive; } } diff --git a/tests/Functional/Parameters/BooleanFilterTest.php b/tests/Functional/Parameters/BooleanFilterTest.php index a856ea3379..fed061151a 100644 --- a/tests/Functional/Parameters/BooleanFilterTest.php +++ b/tests/Functional/Parameters/BooleanFilterTest.php @@ -74,6 +74,22 @@ public static function booleanFilterScenariosProvider(): \Generator yield 'enabled_alias_false' => ['/filtered_boolean_parameters?enabled=false', 1, false]; yield 'enabled_alias_numeric_1' => ['/filtered_boolean_parameters?enabled=1', 2, true]; yield 'enabled_alias_numeric_0' => ['/filtered_boolean_parameters?enabled=0', 1, false]; + yield 'name_converted_true' => ['/filtered_boolean_parameters?nameConverted=true', 2, true]; + yield 'name_converted_false' => ['/filtered_boolean_parameters?nameConverted=false', 1, false]; + yield 'name_converted_numeric_1' => ['/filtered_boolean_parameters?nameConverted=1', 2, true]; + yield 'name_converted_numeric_0' => ['/filtered_boolean_parameters?nameConverted=0', 1, false]; + yield 'name_not_converted_true' => ['/filtered_boolean_parameters?nameNotConverted=true', 2, true]; + yield 'name_not_converted_false' => ['/filtered_boolean_parameters?nameNotConverted=false', 1, false]; + yield 'name_not_converted_numeric_1' => ['/filtered_boolean_parameters?nameNotConverted=1', 2, true]; + yield 'name_not_converted_numeric_0' => ['/filtered_boolean_parameters?nameNotConverted=0', 1, false]; + yield 'alias_name_converted_true' => ['/filtered_boolean_parameters?aliasWithNameConverter=true', 2, true]; + yield 'alias_name_converted_false' => ['/filtered_boolean_parameters?aliasWithNameConverter=false', 1, false]; + yield 'alias_name_converted_numeric_1' => ['/filtered_boolean_parameters?aliasWithNameConverter=1', 2, true]; + yield 'alias_name_converted_numeric_0' => ['/filtered_boolean_parameters?aliasWithNameConverter=0', 1, false]; + yield 'alias_name_not_converted_true' => ['/filtered_boolean_parameters?aliasWithoutNameConverter=true', 2, true]; + yield 'alias_name_not_converted_false' => ['/filtered_boolean_parameters?aliasWithoutNameConverter=false', 1, false]; + yield 'alias_name_not_converted_numeric_1' => ['/filtered_boolean_parameters?aliasWithoutNameConverter=1', 2, true]; + yield 'alias_name_not_converted_numeric_0' => ['/filtered_boolean_parameters?aliasWithoutNameConverter=0', 1, false]; } #[DataProvider('booleanFilterNullAndEmptyScenariosProvider')] diff --git a/tests/Functional/Parameters/ExactFilterTest.php b/tests/Functional/Parameters/ExactFilterTest.php index 61e16f9bdd..9badad6c4d 100644 --- a/tests/Functional/Parameters/ExactFilterTest.php +++ b/tests/Functional/Parameters/ExactFilterTest.php @@ -103,6 +103,30 @@ public static function exactSearchFilterProvider(): \Generator 0, [], ]; + + yield 'filter by nameConverted' => [ + '/chickens?nameConverted=Gertrude', + 1, + ['Gertrude'], + ]; + + yield 'filter by nameConvertedAlias' => [ + '/chickens?nameConvertedAlias=Gertrude', + 1, + ['Gertrude'], + ]; + + yield 'filter by nameNotConverted' => [ + '/chickens?nameNotConverted=Gertrude', + 1, + ['Gertrude'], + ]; + + yield 'filter by nameNotConvertedAlias' => [ + '/chickens?nameNotConvertedAlias=Gertrude', + 1, + ['Gertrude'], + ]; } /**