‪TYPO3CMS  10.4
FileLinkHandlerTest.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27 
28 class ‪FileLinkHandlerTest extends UnitTestCase
29 {
30  protected function ‪setUp(): void
31  {
32  parent::setUp();
33  $this->resetSingletonInstances = true;
34  }
35 
44  {
45  return [
46  'file without FAL - cool style' => [
47  [
48  'identifier' => 'fileadmin/deep/down.jpg'
49  ],
50  [
51  'file' => 'fileadmin/deep/down.jpg'
52  ],
53  't3://file?identifier=fileadmin%2Fdeep%2Fdown.jpg'
54  ],
55  'file without FAL and anchor - cool style' => [
56  [
57  'identifier' => 'fileadmin/deep/down.jpg',
58  'fragment' => 'page-13'
59  ],
60  [
61  'file' => 'fileadmin/deep/down.jpg',
62  'fragment' => 'page-13'
63  ],
64  't3://file?identifier=fileadmin%2Fdeep%2Fdown.jpg#page-13'
65  ],
66  'file with FAL uid - cool style' => [
67  [
68  'uid' => 23
69  ],
70  [
71  'file' => 23
72  ],
73  't3://file?uid=23'
74  ],
75  'file with FAL uid and anchor - cool style' => [
76  [
77  'uid' => 23,
78  'fragment' => 'page-13'
79  ],
80  [
81  'file' => 23,
82  'fragment' => 'page-13'
83  ],
84  't3://file?uid=23#page-13'
85  ],
86  ];
87  }
88 
99  public function ‪resolveFileReferencesToSplitParameters(array $input, array $expected): void
100  {
102  $storage = $this->getMockBuilder(ResourceStorage::class)
103  ->disableOriginalConstructor()
104  ->getMock();
106  $factory = $this->getMockBuilder(ResourceFactory::class)
107  ->disableOriginalConstructor()
108  ->getMock();
109 
110  // fake methods to return proper objects
111  $fileObject = new ‪File(['identifier' => $expected['file'], 'name' => 'foobar.txt'], $storage);
112  $factory->method('getFileObject')->with($expected['file'])->willReturn($fileObject);
113  $factory->method('getFileObjectFromCombinedIdentifier')->with($expected['file'])->willReturn($fileObject);
114  $expected['file'] = $fileObject;
115  GeneralUtility::setSingletonInstance(ResourceFactory::class, $factory);
116 
117  $subject = new ‪FileLinkHandler();
118 
119  self::assertEquals($expected, $subject->resolveHandlerData($input));
120  }
121 
133  public function ‪splitParametersToUnifiedIdentifierForFiles(array $input, array $parameters, string $expected): void
134  {
135  $fileObject = $this->getMockBuilder(File::class)
136  ->onlyMethods(['getUid', 'getIdentifier'])
137  ->disableOriginalConstructor()
138  ->getMock();
139 
140  $uid = 0;
141  if (‪MathUtility::canBeInterpretedAsInteger($parameters['file'])) {
142  $uid = $parameters['file'];
143  }
144  $fileObject->expects(self::once())->method('getUid')->willReturn($uid);
145  $fileObject->method('getIdentifier')->willReturn($parameters['file']);
146  $parameters['file'] = $fileObject;
147 
148  $subject = new ‪FileLinkHandler();
149  self::assertEquals($expected, $subject->asString($parameters));
150  }
151 }
‪TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger
‪static bool canBeInterpretedAsInteger($var)
Definition: MathUtility.php:74
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:41
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:24
‪TYPO3\CMS\Core\Resource\ResourceStorage
Definition: ResourceStorage.php:122
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:22
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46