From da587f173709e29aaa5e7495a382d0c8bab2674e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20W=C3=B3js?= Date: Wed, 21 Aug 2019 18:42:50 +0200 Subject: [PATCH] Added support for raw location ids in LocationConfigResolver --- .../ConfigResolver/LocationConfigResolver.php | 16 ++++++--- .../LocationConfigResolverTest.php | 35 +++++++++++++++++++ 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/src/lib/ConfigResolver/LocationConfigResolver.php b/src/lib/ConfigResolver/LocationConfigResolver.php index 710dd64..4511958 100644 --- a/src/lib/ConfigResolver/LocationConfigResolver.php +++ b/src/lib/ConfigResolver/LocationConfigResolver.php @@ -27,9 +27,7 @@ public function __construct( public function getLocation(string $name, ?string $namespace = null, ?string $scope = null): Location { - return $this->referenceResolver->resolve( - $this->configResolver->getParameter($name, $namespace, $scope) - ); + return $this->referenceResolver->resolve($this->getReference($name, $namespace, $scope)); } public function getLocationReference( @@ -39,7 +37,17 @@ public function getLocationReference( ): LocationReference { return new LocationReference( $this->referenceResolver, - $this->configResolver->getParameter($name, $namespace, $scope) + $this->getReference($name, $namespace, $scope) ); } + + private function getReference(string $name, ?string $namespace, ?string $scope) + { + $reference = $this->configResolver->getParameter($name, $namespace, $scope); + if (is_int($reference)) { + $reference = (string)$reference; + } + + return $reference; + } } diff --git a/tests/lib/ConfigResolver/LocationConfigResolverTest.php b/tests/lib/ConfigResolver/LocationConfigResolverTest.php index 998c6dd..0dea594 100644 --- a/tests/lib/ConfigResolver/LocationConfigResolverTest.php +++ b/tests/lib/ConfigResolver/LocationConfigResolverTest.php @@ -14,6 +14,7 @@ final class LocationConfigResolverTest extends TestCase { private const EXAMPLE_REFERENCE = 'remote_id("babe4a915b1dd5d369e79adb9d6c0c6a")'; + private const EXAMPLE_LOCATION_ID = 2; private const EXAMPLE_PARAMETER = ['tree_root', 'content', 'default']; /** @var \eZ\Publish\Core\MVC\ConfigResolverInterface|\PHPUnit\Framework\MockObject\MockObject */ @@ -55,6 +56,25 @@ public function testGetLocation(): void )); } + public function testGetLocationAcceptLocationId(): void + { + $location = $this->createMock(Location::class); + + $this->configResolver + ->method('getParameter') + ->with(...self::EXAMPLE_PARAMETER) + ->willReturn(self::EXAMPLE_LOCATION_ID); + + $this->referenceResolver + ->method('resolve') + ->with((string) self::EXAMPLE_LOCATION_ID) + ->willReturn($location); + + $this->assertEquals($location, $this->locationConfigResolver->getLocation( + ...self::EXAMPLE_PARAMETER + )); + } + public function testGetLocationReference(): void { $this->configResolver @@ -69,4 +89,19 @@ public function testGetLocationReference(): void $this->assertInstanceOf(LocationReference::class, $reference); $this->assertEquals(self::EXAMPLE_REFERENCE, (string)$reference); } + + public function testGetLocationReferenceAcceptLocationId(): void + { + $this->configResolver + ->method('getParameter') + ->with(...self::EXAMPLE_PARAMETER) + ->willReturn(self::EXAMPLE_LOCATION_ID); + + $reference = $this->locationConfigResolver->getLocationReference( + ...self::EXAMPLE_PARAMETER + ); + + $this->assertInstanceOf(LocationReference::class, $reference); + $this->assertEquals((string)self::EXAMPLE_LOCATION_ID, (string)$reference); + } }