File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed
src/lib/FieldTypeProcessor
tests/lib/FieldTypeProcessor Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change 66 */
77namespace Ibexa \Rest \FieldTypeProcessor ;
88
9+ use Ibexa \Contracts \Core \Repository \Exceptions \NotFoundException ;
10+ use Ibexa \Contracts \Core \Repository \Exceptions \UnauthorizedException ;
911use Ibexa \Contracts \Core \Repository \LocationService ;
1012use Ibexa \Contracts \Rest \FieldTypeProcessor ;
1113use Ibexa \Core \FieldType \Relation \Type ;
@@ -64,8 +66,14 @@ public function mapToContentHref($contentId)
6466 */
6567 public function mapToLocationHref ($ locationId )
6668 {
69+ try {
70+ $ location = $ this ->locationService ->loadLocation ($ locationId );
71+ } catch (UnauthorizedException | NotFoundException $ e ) {
72+ return '' ;
73+ }
74+
6775 return $ this ->router ->generate ('ibexa.rest.load_location ' , [
68- 'locationPath ' => implode ('/ ' , $ this -> locationService -> loadLocation ( $ locationId ) ->path ),
76+ 'locationPath ' => implode ('/ ' , $ location ->path ),
6977 ]);
7078 }
7179
Original file line number Diff line number Diff line change 77namespace Ibexa \Tests \Rest \FieldTypeProcessor ;
88
99use Ibexa \Contracts \Core \Repository \LocationService ;
10+ use Ibexa \Core \Base \Exceptions \NotFoundException ;
1011use Ibexa \Core \Repository \Values \Content \Location ;
1112use Ibexa \Rest \FieldTypeProcessor \RelationProcessor ;
1213use PHPUnit \Framework \TestCase ;
@@ -127,6 +128,33 @@ public function testPostProcessFieldValueHashNullValue()
127128 $ this ->assertArrayNotHasKey ('destinationContentHref ' , $ hash );
128129 }
129130
131+ public function testPostProcessFieldValueHashNotAccessibleLocation (): void
132+ {
133+ $ processor = $ this ->getProcessor ();
134+
135+ $ serviceLocationMock = $ this ->createMock (LocationService::class);
136+ $ processor ->setLocationService ($ serviceLocationMock );
137+
138+ $ serviceLocationMock
139+ ->method ('loadLocation ' )
140+ ->with ('-1 ' )
141+ ->willThrowException (new NotFoundException ('' , '' ));
142+
143+ $ routerMock = $ this ->createMock (RouterInterface::class);
144+ $ processor ->setRouter ($ routerMock );
145+
146+ $ routerMock
147+ ->expects (self ::never ())
148+ ->method ('generate ' );
149+
150+ $ hash = $ processor ->postProcessFieldSettingsHash (['selectionRoot ' => -1 ]);
151+
152+ self ::assertSame ([
153+ 'selectionRoot ' => -1 ,
154+ 'selectionRootHref ' => '' ,
155+ ], $ hash );
156+ }
157+
130158 /**
131159 * @return \Ibexa\Rest\FieldTypeProcessor\RelationProcessor
132160 */
You can’t perform that action at this time.
0 commit comments