‪TYPO3CMS  9.5
FileLinkHandlerTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
25 class ‪FileLinkHandlerTest extends UnitTestCase
26 {
39  {
40  return [
41  'file without FAL - cool style' => [
42  [
43  'identifier' => 'fileadmin/deep/down.jpg'
44  ],
45  [
46  'file' => 'fileadmin/deep/down.jpg'
47  ],
48  't3://file?identifier=fileadmin%2Fdeep%2Fdown.jpg'
49  ],
50  'file without FAL and anchor - cool style' => [
51  [
52  'identifier' => 'fileadmin/deep/down.jpg',
53  'fragment' => 'page-13'
54  ],
55  [
56  'file' => 'fileadmin/deep/down.jpg',
57  'fragment' => 'page-13'
58  ],
59  't3://file?identifier=fileadmin%2Fdeep%2Fdown.jpg#page-13'
60  ],
61  'file with FAL uid - cool style' => [
62  [
63  'uid' => 23
64  ],
65  [
66  'file' => 23
67  ],
68  't3://file?uid=23'
69  ],
70  'file with FAL uid and anchor - cool style' => [
71  [
72  'uid' => 23,
73  'fragment' => 'page-13'
74  ],
75  [
76  'file' => 23,
77  'fragment' => 'page-13'
78  ],
79  't3://file?uid=23#page-13'
80  ],
81  ];
82  }
83 
95  public function ‪resolveFileReferencesToSplitParameters($input, $expected, $finalString)
96  {
98  $storage = $this->getMockBuilder(ResourceStorage::class)
99  ->disableOriginalConstructor()
100  ->getMock();
102  $factory = $this->getMockBuilder(ResourceFactory::class)
103  ->disableOriginalConstructor()
104  ->getMock();
105 
106  // fake methods to return proper objects
107  $fileObject = new ‪File(['identifier' => $expected['file'], 'name' => 'foobar.txt'], $storage);
108  $factory->expects($this->any())->method('getFileObject')->with($expected['file'])->willReturn($fileObject);
109  $factory->expects($this->any())->method('getFileObjectFromCombinedIdentifier')->with($expected['file'])->willReturn($fileObject);
110  $expected['file'] = $fileObject;
111 
113  $subject = $this->getAccessibleMock(FileLinkHandler::class, ['dummy']);
114  $subject->_set('resourceFactory', $factory);
115  $this->assertEquals($expected, $subject->resolveHandlerData($input));
116  }
117 
129  public function ‪splitParametersToUnifiedIdentifierForFiles($input, $parameters, $expected)
130  {
131  $fileObject = $this->getMockBuilder(File::class)
132  ->setMethods(['getUid', 'getIdentifier'])
133  ->disableOriginalConstructor()
134  ->getMock();
135 
136  $uid = 0;
137  if (‪MathUtility::canBeInterpretedAsInteger($parameters['file'])) {
138  $uid = $parameters['file'];
139  }
140  $fileObject->expects($this->once())->method('getUid')->willReturn($uid);
141  $fileObject->expects($this->any())->method('getIdentifier')->willReturn($parameters['file']);
142  $parameters['file'] = $fileObject;
143 
144  $subject = new ‪FileLinkHandler();
145  $this->assertEquals($expected, $subject->asString($parameters));
146  }
147 }
‪TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger
‪static bool canBeInterpretedAsInteger($var)
Definition: MathUtility.php:73
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:33
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:23
‪TYPO3\CMS\Core\Resource\ResourceStorage
Definition: ResourceStorage.php:74
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:21