Skip to content

Commit

Permalink
Added support for raw location ids in LocationConfigResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwojs committed Aug 21, 2019
1 parent 674c567 commit da587f1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/lib/ConfigResolver/LocationConfigResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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;
}
}
35 changes: 35 additions & 0 deletions tests/lib/ConfigResolver/LocationConfigResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
}

0 comments on commit da587f1

Please sign in to comment.