|
28 | 28 | class LinkTest extends TestCase |
29 | 29 | { |
30 | 30 | /** |
31 | | - * @return \PHPUnit\Framework\MockObject\MockObject |
| 31 | + * @return \PHPUnit\Framework\MockObject\MockObject&\Ibexa\Core\Repository\ContentService |
32 | 32 | */ |
33 | 33 | protected function getMockContentService() |
34 | 34 | { |
35 | 35 | return $this->createMock(ContentService::class); |
36 | 36 | } |
37 | 37 |
|
38 | 38 | /** |
39 | | - * @return \PHPUnit\Framework\MockObject\MockObject |
| 39 | + * @return \PHPUnit\Framework\MockObject\MockObject&\Ibexa\Core\Repository\LocationService |
40 | 40 | */ |
41 | 41 | protected function getMockLocationService() |
42 | 42 | { |
43 | 43 | return $this->createMock(LocationService::class); |
44 | 44 | } |
45 | 45 |
|
46 | 46 | /** |
47 | | - * @return \PHPUnit\Framework\MockObject\MockObject |
| 47 | + * @return \PHPUnit\Framework\MockObject\MockObject&\Symfony\Component\Routing\RouterInterface |
48 | 48 | */ |
49 | 49 | protected function getMockRouter() |
50 | 50 | { |
@@ -144,7 +144,7 @@ public function testLink($input, $output) |
144 | 144 | /** |
145 | 145 | * @return array |
146 | 146 | */ |
147 | | - public function providerLocationLink() |
| 147 | + public function providerLocationLink(): array |
148 | 148 | { |
149 | 149 | return [ |
150 | 150 | [ |
@@ -197,6 +197,24 @@ public function providerLocationLink() |
197 | 197 | <ezembed> |
198 | 198 | <ezlink xlink:href="ezlocation://106#anchor" href_resolved="test#anchor"/> |
199 | 199 | </ezembed> |
| 200 | +</section>', |
| 201 | + 106, |
| 202 | + 'test', |
| 203 | + ], |
| 204 | + [ |
| 205 | + '<?xml version="1.0" encoding="UTF-8"?> |
| 206 | +<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ezxhtml="http://ibexa.co/xmlns/dxp/docbook/xhtml" version="5.0-variant ezpublish-1.0"> |
| 207 | + <title>Link example with empty site access</title> |
| 208 | + <ezembed> |
| 209 | + <ezlink xlink:href="ezlocation://106#anchor" xlink:siteaccess=""/> |
| 210 | + </ezembed> |
| 211 | +</section>', |
| 212 | + '<?xml version="1.0" encoding="UTF-8"?> |
| 213 | +<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ezxhtml="http://ibexa.co/xmlns/dxp/docbook/xhtml" version="5.0-variant ezpublish-1.0"> |
| 214 | + <title>Link example with empty site access</title> |
| 215 | + <ezembed> |
| 216 | + <ezlink xlink:href="ezlocation://106#anchor" xlink:siteaccess="" href_resolved="test#anchor"/> |
| 217 | + </ezembed> |
200 | 218 | </section>', |
201 | 219 | 106, |
202 | 220 | 'test', |
@@ -240,10 +258,61 @@ public function testConvertLocationLink($input, $output, $locationId, $urlResolv |
240 | 258 | $this->assertEquals($expectedOutputDocument, $outputDocument); |
241 | 259 | } |
242 | 260 |
|
| 261 | + /** |
| 262 | + * Test conversion of ezlocation://<id> links with the 'siteaccess' attribute. |
| 263 | + */ |
| 264 | + public function testConvertLocationLinkWithSiteAccess(): void |
| 265 | + { |
| 266 | + $inputDocument = new DOMDocument(); |
| 267 | + $input = '<?xml version="1.0" encoding="UTF-8"?> |
| 268 | +<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ezxhtml="http://ibexa.co/xmlns/dxp/docbook/xhtml" version="5.0-variant ezpublish-1.0"> |
| 269 | + <title>Link example with site access</title> |
| 270 | + <ezembed> |
| 271 | + <ezlink xlink:href="ezlocation://106#anchor" xlink:siteaccess="site"/> |
| 272 | + </ezembed> |
| 273 | +</section>'; |
| 274 | + $output = '<?xml version="1.0" encoding="UTF-8"?> |
| 275 | +<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ezxhtml="http://ibexa.co/xmlns/dxp/docbook/xhtml" version="5.0-variant ezpublish-1.0"> |
| 276 | + <title>Link example with site access</title> |
| 277 | + <ezembed> |
| 278 | + <ezlink xlink:href="ezlocation://106#anchor" xlink:siteaccess="site" href_resolved="test#anchor"/> |
| 279 | + </ezembed> |
| 280 | +</section>'; |
| 281 | + $inputDocument->loadXML($input); |
| 282 | + |
| 283 | + $contentService = $this->getMockContentService(); |
| 284 | + $locationService = $this->getMockLocationService(); |
| 285 | + $router = $this->getMockRouter(); |
| 286 | + |
| 287 | + $location = $this->createMock(APILocation::class); |
| 288 | + |
| 289 | + $locationService->expects($this->once()) |
| 290 | + ->method('loadLocation') |
| 291 | + ->with($this->equalTo(106)) |
| 292 | + ->willReturn($location); |
| 293 | + |
| 294 | + $router->expects($this->once()) |
| 295 | + ->method('generate') |
| 296 | + ->with(UrlAliasRouter::URL_ALIAS_ROUTE_NAME, [ |
| 297 | + 'location' => $location, |
| 298 | + 'siteaccess' => 'site', |
| 299 | + ]) |
| 300 | + ->willReturn('test'); |
| 301 | + |
| 302 | + $converter = new Link($locationService, $contentService, $router); |
| 303 | + |
| 304 | + $outputDocument = $converter->convert($inputDocument); |
| 305 | + |
| 306 | + $expectedOutputDocument = new DOMDocument(); |
| 307 | + $expectedOutputDocument->loadXML($output); |
| 308 | + |
| 309 | + $this->assertEquals($expectedOutputDocument, $outputDocument); |
| 310 | + } |
| 311 | + |
243 | 312 | /** |
244 | 313 | * @return array |
245 | 314 | */ |
246 | | - public function providerBadLocationLink() |
| 315 | + public function providerBadLocationLink(): array |
247 | 316 | { |
248 | 317 | return [ |
249 | 318 | [ |
|
0 commit comments