2 declare(strict_types = 1);
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
38 'content' =>
't3://page?uid=42',
39 'elementKey' =>
'8695f308356bcca1acac2749152a44a9:0',
40 'matchString' =>
't3://page?uid=42',
43 'content' =>
'<p><a href="t3://page?uid=42">Click here</a></p>',
45 'matchString' =>
'<a href="t3://page?uid=42">',
51 'recordRef' =>
'pages:42',
56 'link to page with properties' => [
59 'content' =>
'<p><a class="link-page" href="t3://page?uid=42" target="_top" title="Foo">Click here</a></p>',
61 'matchString' =>
'<a class="link-page" href="t3://page?uid=42" target="_top" title="Foo">',
67 'recordRef' =>
'pages:42',
72 'link to page with just a number' => [
76 'elementKey' =>
'8695f308356bcca1acac2749152a44a9:0',
77 'matchString' =>
'42',
83 'recordRef' =>
'pages:42',
88 'link to page with just a number and type comma-separated' => [
91 'content' =>
'42,100',
92 'elementKey' =>
'8695f308356bcca1acac2749152a44a9:0',
93 'matchString' =>
'42,100',
99 'recordRef' =>
'pages:42',
100 'tokenValue' =>
'42',
104 'link to external URL without scheme' => [
107 'content' =>
'www.example.com',
108 'elementKey' =>
'8695f308356bcca1acac2749152a44a9:0',
109 'matchString' =>
'www.example.com',
112 'content' =>
'<p><a class="link-page" href="www.example.com" target="_top" title="Foo">Click here</a></p>',
114 'matchString' =>
'<a class="link-page" href="www.example.com" target="_top" title="Foo">',
119 'type' =>
'external',
120 'tokenValue' =>
'http://www.example.com',
124 'link to external URL with scheme' => [
127 'content' =>
'https://www.example.com',
128 'elementKey' =>
'8695f308356bcca1acac2749152a44a9:0',
129 'matchString' =>
'https://www.example.com',
132 'content' =>
'<p><a class="link-page" href="https://www.example.com" target="_top" title="Foo">Click here</a></p>',
134 'matchString' =>
'<a class="link-page" href="https://www.example.com" target="_top" title="Foo">',
139 'type' =>
'external',
140 'tokenValue' =>
'https://www.example.com',
147 'content' =>
'mailto:test@example.com',
148 'elementKey' =>
'8695f308356bcca1acac2749152a44a9:0',
149 'matchString' =>
'mailto:test@example.com',
152 'content' =>
'<p><a href="mailto:test@example.com">Click here</a></p>',
154 'matchString' =>
'<a href="mailto:test@example.com">',
160 'tokenValue' =>
'test@example.com',
164 'link to email without schema' => [
167 'content' =>
'test@example.com',
168 'elementKey' =>
'8695f308356bcca1acac2749152a44a9:0',
169 'matchString' =>
'test@example.com',
172 'content' =>
'<p><a href="test@example.com">Click here</a></p>',
174 'matchString' =>
'<a href="test@example.com">',
180 'tokenValue' =>
'test@example.com',
195 foreach ($softrefConfiguration as $softrefKey => $configuration) {
197 $result = $subject->findRef(
201 $configuration[
'content'],
206 self::assertArrayHasKey(
'elements', $result);
207 self::assertArrayHasKey($configuration[
'elementKey'], $result[
'elements']);
210 unset($result[
'elements'][$configuration[
'elementKey']][
'subst'][
'tokenID']);
212 $expectedElement[
'matchString'] = $configuration[
'matchString'];
213 self::assertEquals($expectedElement, $result[
'elements'][$configuration[
'elementKey']]);
223 'content' =>
't3://file?uid=42',
224 'elementKey' =>
'8695f308356bcca1acac2749152a44a9:0',
225 'matchString' =>
't3://file?uid=42',
228 'content' =>
'<p><a href="t3://file?uid=42">Click here</a></p>',
230 'matchString' =>
'<a href="t3://file?uid=42">',
236 'recordRef' =>
'sys_file:42',
237 'tokenValue' =>
'file:42',
241 'file with t3 mixed syntax' => [
244 'content' =>
't3://file?identifier=42',
245 'elementKey' =>
'8695f308356bcca1acac2749152a44a9:0',
246 'matchString' =>
't3://file?identifier=42',
252 'recordRef' =>
'sys_file:42',
253 'tokenValue' =>
'file:42',
257 'link to file with old FAL object syntax' => [
260 'content' =>
'file:42',
261 'elementKey' =>
'8695f308356bcca1acac2749152a44a9:0',
262 'matchString' =>
'file:42',
268 'recordRef' =>
'sys_file:42',
269 'tokenValue' =>
'file:42',
273 'link to file with simple file path' => [
276 'content' =>
'fileadmin/download.jpg',
277 'elementKey' =>
'8695f308356bcca1acac2749152a44a9:0',
278 'matchString' =>
'fileadmin/download.jpg',
284 'recordRef' =>
'sys_file:42',
285 'tokenValue' =>
'file:42',
300 $fileObject = $this->prophesize(File::class);
301 $fileObject->getUid()->willReturn(42)->shouldBeCalledTimes(count($softrefConfiguration));
303 $resourceFactory = $this->prophesize(ResourceFactory::class);
304 $resourceFactory->getFileObject(
'42')->willReturn($fileObject->reveal());
306 $resourceFactory->getFileObjectFromCombinedIdentifier(
'42')->willReturn($fileObject->reveal());
308 $resourceFactory->retrieveFileOrFolderObject(
'42')->willReturn($fileObject->reveal());
310 $resourceFactory->retrieveFileOrFolderObject(
'fileadmin/download.jpg')->willReturn($fileObject->reveal());
312 GeneralUtility::setSingletonInstance(ResourceFactory::class, $resourceFactory->reveal());
314 foreach ($softrefConfiguration as $softrefKey => $configuration) {
316 $result = $subject->findRef(
320 $configuration[
'content'],
325 self::assertArrayHasKey(
'elements', $result);
326 self::assertArrayHasKey($configuration[
'elementKey'], $result[
'elements']);
329 unset($result[
'elements'][$configuration[
'elementKey']][
'subst'][
'tokenID']);
331 $expectedElement[
'matchString'] = $configuration[
'matchString'];
332 self::assertEquals($expectedElement, $result[
'elements'][$configuration[
'elementKey']]);
339 'link to folder' => [
342 'content' =>
't3://folder?storage=1&identifier=%2Ffoo%2Fbar%2Fbaz',
345 'content' =>
'<p><a href="t3://folder?storage=1&identifier=%2Ffoo%2Fbar%2Fbaz">Click here</a></p>',
349 'link to folder with properties' => [
352 'content' =>
'<p><a class="link-page" href="t3://folder?storage=1&identifier=%2Ffoo%2Fbar%2Fbaz" target="_top" title="Foo">Click here</a></p>',
366 $folderObject = $this->prophesize(Folder::class);
368 $resourceFactory = $this->prophesize(ResourceFactory::class);
369 $resourceFactory->getFolderObjectFromCombinedIdentifier(
'1:/foo/bar/baz')->willReturn($folderObject->reveal())->shouldBeCalledTimes(count($softrefConfiguration));
370 GeneralUtility::setSingletonInstance(ResourceFactory::class, $resourceFactory->reveal());
372 foreach ($softrefConfiguration as $softrefKey => $configuration) {
374 $result = $subject->findRef(
378 $configuration[
'content'],
383 self::assertNull($result);
390 'URL encoded local' => [
391 'phar%3a//some-file.jpg',
393 'URL encoded absolute' => [
394 'phar%3a///path/some-file.jpg',
396 'not URL encoded local' => [
397 'phar://some-file.jpg',
399 'not URL encoded absolute' => [
400 'phar:///path/some-file.jpg',
411 $this->expectException(\RuntimeException::class);
412 $this->expectExceptionCode(1530030672);