diff --git a/src/bundle/Core/Converter/LocationArgumentResolver.php b/src/bundle/Core/ControllerArgumentResolver/LocationArgumentResolver.php similarity index 88% rename from src/bundle/Core/Converter/LocationArgumentResolver.php rename to src/bundle/Core/ControllerArgumentResolver/LocationArgumentResolver.php index c1905c6d80..fe4dd8d226 100644 --- a/src/bundle/Core/Converter/LocationArgumentResolver.php +++ b/src/bundle/Core/ControllerArgumentResolver/LocationArgumentResolver.php @@ -6,10 +6,11 @@ */ declare(strict_types=1); -namespace Ibexa\Bundle\Core\Converter; +namespace Ibexa\Bundle\Core\ControllerArgumentResolver; use Ibexa\Contracts\Core\Exception\InvalidArgumentException; use Ibexa\Contracts\Core\Repository\LocationService; +use Ibexa\Contracts\Core\Repository\Values\Content\Location; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface; use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata; @@ -30,7 +31,9 @@ public function __construct(LocationService $locationService) public function supports(Request $request, ArgumentMetadata $argument): bool { - return !$request->attributes->has(self::PARAMETER_LOCATION_ID) + return + Location::class === $argument->getType() + && !$request->attributes->has(self::PARAMETER_LOCATION_ID) && $request->query->has(self::PARAMETER_LOCATION_ID); } diff --git a/src/bundle/Core/Resources/config/services.yml b/src/bundle/Core/Resources/config/services.yml index f4f7187a59..e65c582af2 100644 --- a/src/bundle/Core/Resources/config/services.yml +++ b/src/bundle/Core/Resources/config/services.yml @@ -195,11 +195,11 @@ services: tags: - { name: request.param_converter, priority: '%ibexa.param_converter.location.priority%', converter: ez_location_converter } - Ibexa\Bundle\Core\Converter\LocationArgumentResolver: + Ibexa\Bundle\Core\ControllerArgumentResolver\LocationArgumentResolver: autowire: true autoconfigure: true tags: - - { name: controller.argument_value_resolver, priority: '%ibexa.param_converter.location.priority%' } + - { name: controller.argument_value_resolver, priority: 50 } Ibexa\Bundle\Core\EventListener\ExceptionListener: class: Ibexa\Bundle\Core\EventListener\ExceptionListener diff --git a/tests/bundle/Core/Converter/LocationArgumentResolverTest.php b/tests/bundle/Core/ControllerArgumentResolver/LocationArgumentResolverTest.php similarity index 81% rename from tests/bundle/Core/Converter/LocationArgumentResolverTest.php rename to tests/bundle/Core/ControllerArgumentResolver/LocationArgumentResolverTest.php index bfb0b845e0..cb8fc641db 100644 --- a/tests/bundle/Core/Converter/LocationArgumentResolverTest.php +++ b/tests/bundle/Core/ControllerArgumentResolver/LocationArgumentResolverTest.php @@ -6,10 +6,10 @@ */ declare(strict_types=1); -namespace Ibexa\Tests\Bundle\Core\Converter; +namespace Ibexa\Tests\Bundle\Core\ControllerArgumentResolver; use Generator; -use Ibexa\Bundle\Core\Converter\LocationArgumentResolver; +use Ibexa\Bundle\Core\ControllerArgumentResolver\LocationArgumentResolver; use Ibexa\Contracts\Core\Exception\InvalidArgumentException; use Ibexa\Contracts\Core\Repository\LocationService; use Ibexa\Contracts\Core\Repository\Values\Content\Location; @@ -96,27 +96,44 @@ public function testResolve(): void */ public function provideDataForTestSupports(): iterable { - $argumentMetadata = $this->createMock(ArgumentMetadata::class); + $locationBasedArgumentMetadata = $this->createArgumentMetadata(Location::class); yield 'Supported - locationId passed to request query' => [ true, $this->createRequest(true, false, 1), - $argumentMetadata, + $locationBasedArgumentMetadata, + ]; + + yield 'Not supported - type different than Ibexa\Contracts\Core\Repository\Values\Content\Location' => [ + false, + $this->createRequest(true, false, 1), + $this->createArgumentMetadata('foo'), ]; yield 'Not supported - locationId passed to request attributes' => [ false, $this->createRequest(false, true, 1), - $argumentMetadata, + $locationBasedArgumentMetadata, ]; yield 'Not supported - locationId passed to request attributes and query' => [ false, $this->createRequest(true, true, 1), - $argumentMetadata, + $locationBasedArgumentMetadata, ]; } + private function createArgumentMetadata(string $type): ArgumentMetadata + { + $argumentMetadata = $this->createMock(ArgumentMetadata::class); + $argumentMetadata + ->expects(self::atLeastOnce()) + ->method('getType') + ->willReturn($type); + + return $argumentMetadata; + } + private function createRequest( bool $addToQuery, bool $addToAttributes,