Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions lib/Limitation/DataTransformer/UDWBasedValueModelTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ class UDWBasedValueModelTransformer implements DataTransformerInterface
/** @var \eZ\Publish\API\Repository\LocationService */
private $locationService;

/**
* @param \eZ\Publish\API\Repository\LocationService $locationService
*/
public function __construct(LocationService $locationService)
{
$this->locationService = $locationService;
Expand All @@ -37,7 +34,7 @@ public function __construct(LocationService $locationService)
*/
public function transform($value)
{
if (!is_array($value)) {
if (!\is_array($value)) {
return null;
}

Expand All @@ -47,7 +44,9 @@ public function transform($value)
$this->extractLocationIdFromPath($path)
);
}, $value);
} catch (NotFoundException | UnauthorizedException $e) {
} catch (NotFoundException $e) {
return null;
} catch (UnauthorizedException $e) {
throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
}
}
Expand All @@ -57,7 +56,7 @@ public function transform($value)
*/
public function reverseTransform($value)
{
if (!is_array($value)) {
if (!\is_array($value)) {
return null;
}

Expand All @@ -66,10 +65,6 @@ public function reverseTransform($value)

/**
* Extracts and returns an item id from a path, e.g. /1/2/58/ => 58.
*
* @param string $path
*
* @return string|null
*/
private function extractLocationIdFromPath(string $path): ?string
{
Expand Down
17 changes: 5 additions & 12 deletions lib/Limitation/Templating/LimitationBlockRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
namespace EzSystems\RepositoryForms\Limitation\Templating;

use eZ\Publish\API\Repository\Exceptions\NotFoundException;
use eZ\Publish\API\Repository\Values\User\Limitation;
use EzSystems\RepositoryForms\Limitation\Exception\MissingLimitationBlockException;
use EzSystems\RepositoryForms\Limitation\Exception\ValueMapperNotFoundException;
Expand Down Expand Up @@ -36,9 +37,6 @@ class LimitationBlockRenderer implements LimitationBlockRendererInterface

/**
* LimitationRenderer constructor.
*
* @param LimitationValueMapperRegistryInterface $valueMapperRegistry
* @param Twig_Environment $twig
*/
public function __construct(LimitationValueMapperRegistryInterface $valueMapperRegistry, Twig_Environment $twig)
{
Expand All @@ -51,7 +49,7 @@ public function renderLimitationValue(Limitation $limitation, array $parameters
try {
$blockName = $this->getValueBlockName($limitation);
$parameters = $this->getValueBlockParameters($limitation, $parameters);
} catch (ValueMapperNotFoundException $exception) {
} catch (ValueMapperNotFoundException | NotFoundException $exception) {
$blockName = self::LIMITATION_VALUE_BLOCK_NAME_FALLBACK;
$parameters = $this->getValueFallbackBlockParameters($limitation, $parameters);
}
Expand Down Expand Up @@ -82,7 +80,6 @@ public function setLimitationValueResources(array $resources)
/**
* Generates value block name based on Limitation.
*
* @param Limitation $limitation
* @return string
*/
protected function getValueBlockName(Limitation $limitation)
Expand All @@ -95,12 +92,12 @@ protected function getValueBlockName(Limitation $limitation)
*
* @param string $blockName
* @param string|Twig_Template $localTemplate
* @return null|\Twig_TemplateWrapper
* @return \Twig_TemplateWrapper|null
*/
protected function findTemplateWithBlock($blockName, $localTemplate = null)
{
if ($localTemplate !== null) {
if (is_string($localTemplate)) {
if (\is_string($localTemplate)) {
$localTemplate = $this->twig->load($localTemplate);
}

Expand All @@ -110,7 +107,7 @@ protected function findTemplateWithBlock($blockName, $localTemplate = null)
}

foreach ($this->limitationValueResources as &$template) {
if (is_string($template)) {
if (\is_string($template)) {
// Load the template if it is necessary
$template = $this->twig->load($template);
}
Expand All @@ -126,8 +123,6 @@ protected function findTemplateWithBlock($blockName, $localTemplate = null)
/**
* Get parameters passed as context of value block render.
*
* @param Limitation $limitation
* @param array $parameters
* @return array
*/
protected function getValueBlockParameters(Limitation $limitation, array $parameters)
Expand All @@ -147,8 +142,6 @@ protected function getValueBlockParameters(Limitation $limitation, array $parame
/**
* Get parameters passed as context of value fallback block.
*
* @param Limitation $limitation
* @param array $parameters
* @return array
*/
protected function getValueFallbackBlockParameters(Limitation $limitation, array $parameters)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,36 @@ public function dataProviderForTransform(): array
];
}

/**
* @dataProvider dataProviderForTransformThrowsTransformationFailedException
*/
public function testTransformThrowsTransformationFailedException(string $exceptionClass)
public function testTransformThrowsTransformationFailedException()
Comment thread
barw4 marked this conversation as resolved.
Outdated
{
$this->expectException(TransformationFailedException::class);

$this->locationService
->expects($this->any())
->method('loadLocation')
->willThrowException(
$this->createMock($exceptionClass)
$this->createMock(UnauthorizedException::class)
);

$this->transformer->transform(['/1/2/54']);
}

public function testTransformWithDeletedLocation()
Comment thread
barw4 marked this conversation as resolved.
Outdated
{
$this->locationService
->expects($this->any())
Comment thread
barw4 marked this conversation as resolved.
Outdated
->method('loadLocation')
->willThrowException(
$this->createMock(NotFoundException::class)
);

self::assertNull($this->transformer->transform(['/1/2/54']));
}

public function dataProviderForTransformThrowsTransformationFailedException(): array
{
return [
[NotFoundException::class],
//[NotFoundException::class],
Comment thread
barw4 marked this conversation as resolved.
Outdated
[UnauthorizedException::class],
];
}
Expand Down