Skip to content

Commit

Permalink
IBX-5387: Handled not accessible Location in RelationProcessor (#60)
Browse files Browse the repository at this point in the history
* IBX-5387: Handled not accessible Location in `RelationProcessor`

* IBX-5387: BC

* IBX-5387: Fixed test

* IBX-5387: Changed assert
  • Loading branch information
barw4 authored Apr 12, 2023
1 parent 703ef47 commit 2faca6e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/lib/FieldTypeProcessor/BaseRelationProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
namespace Ibexa\Rest\FieldTypeProcessor;

use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException;
use Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException;
use Ibexa\Contracts\Core\Repository\LocationService;
use Ibexa\Contracts\Rest\FieldTypeProcessor;
use Ibexa\Core\FieldType\Relation\Type;
Expand Down Expand Up @@ -64,8 +66,14 @@ public function mapToContentHref($contentId)
*/
public function mapToLocationHref($locationId)
{
try {
$location = $this->locationService->loadLocation($locationId);
} catch (UnauthorizedException | NotFoundException $e) {
return '';
}

return $this->router->generate('ibexa.rest.load_location', [
'locationPath' => implode('/', $this->locationService->loadLocation($locationId)->path),
'locationPath' => implode('/', $location->path),
]);
}

Expand Down
28 changes: 28 additions & 0 deletions tests/lib/FieldTypeProcessor/RelationProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace Ibexa\Tests\Rest\FieldTypeProcessor;

use Ibexa\Contracts\Core\Repository\LocationService;
use Ibexa\Core\Base\Exceptions\NotFoundException;
use Ibexa\Core\Repository\Values\Content\Location;
use Ibexa\Rest\FieldTypeProcessor\RelationProcessor;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -127,6 +128,33 @@ public function testPostProcessFieldValueHashNullValue()
$this->assertArrayNotHasKey('destinationContentHref', $hash);
}

public function testPostProcessFieldValueHashNotAccessibleLocation(): void
{
$processor = $this->getProcessor();

$serviceLocationMock = $this->createMock(LocationService::class);
$processor->setLocationService($serviceLocationMock);

$serviceLocationMock
->method('loadLocation')
->with('-1')
->willThrowException(new NotFoundException('', ''));

$routerMock = $this->createMock(RouterInterface::class);
$processor->setRouter($routerMock);

$routerMock
->expects(self::never())
->method('generate');

$hash = $processor->postProcessFieldSettingsHash(['selectionRoot' => -1]);

self::assertSame([
'selectionRoot' => -1,
'selectionRootHref' => '',
], $hash);
}

/**
* @return \Ibexa\Rest\FieldTypeProcessor\RelationProcessor
*/
Expand Down

0 comments on commit 2faca6e

Please sign in to comment.