TYPO3 CMS  TYPO3_8-7
FileLinkHandlerTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
22 
23 class FileLinkHandlerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
24 {
25 
38  {
39  return [
40  'file without FAL - cool style' => [
41  [
42  'identifier' => 'fileadmin/deep/down.jpg'
43  ],
44  [
45  'file' => 'fileadmin/deep/down.jpg'
46  ],
47  't3://file?identifier=fileadmin%2Fdeep%2Fdown.jpg'
48  ],
49  'file with FAL uid - cool style' => [
50  [
51  'uid' => 23
52  ],
53  [
54  'file' => 23
55  ],
56  't3://file?uid=23'
57  ],
58  ];
59  }
60 
72  public function resolveFileReferencesToSplitParameters($input, $expected, $finalString)
73  {
75  $storage = $this->getMockBuilder(ResourceStorage::class)
76  ->disableOriginalConstructor()
77  ->getMock();
79  $factory = $this->getMockBuilder(ResourceFactory::class)
80  ->disableOriginalConstructor()
81  ->getMock();
82 
83  // fake methods to return proper objects
84  $fileObject = new File(['identifier' => $expected['file']], $storage);
85  $factory->expects($this->any())->method('getFileObject')->with($expected['file'])->willReturn($fileObject);
86  $factory->expects($this->any())->method('getFileObjectFromCombinedIdentifier')->with($expected['file'])->willReturn($fileObject);
87  $expected['file'] = $fileObject;
88 
90  $subject = $this->getAccessibleMock(FileLinkHandler::class, ['dummy']);
91  $subject->_set('resourceFactory', $factory);
92  $this->assertEquals($expected, $subject->resolveHandlerData($input));
93  }
94 
106  public function splitParametersToUnifiedIdentifierForFiles($input, $parameters, $expected)
107  {
108  $fileObject = $this->getMockBuilder(File::class)
109  ->setMethods(['getUid', 'getIdentifier'])
110  ->disableOriginalConstructor()
111  ->getMock();
112 
113  $uid = 0;
114  if (MathUtility::canBeInterpretedAsInteger($parameters['file'])) {
115  $uid = $parameters['file'];
116  }
117  $fileObject->expects($this->once())->method('getUid')->willReturn($uid);
118  $fileObject->expects($this->any())->method('getIdentifier')->willReturn($parameters['file']);
119  $parameters['file'] = $fileObject;
120 
121  $subject = new FileLinkHandler();
122  $this->assertEquals($expected, $subject->asString($parameters));
123  }
124 }