‪TYPO3CMS  10.4
FolderLinkHandlerTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
25 class ‪FolderLinkHandlerTest extends UnitTestCase
26 {
27  protected function ‪setUp(): void
28  {
29  parent::setUp();
30  $this->resetSingletonInstances = true;
31  }
32 
41  {
42  return [
43  'folder without FAL - cool style' => [
44  [
45  'storage' => 0,
46  'identifier' => '/fileadmin/myimages/'
47  ],
48  [
49  'folder' => '0:/fileadmin/myimages/'
50  ],
51  't3://folder?storage=0&identifier=%2Ffileadmin%2Fmyimages%2F'
52  ],
53  'folder with combined identifier and file prefix (FAL) - cool style' => [
54  [
55  'storage' => 2,
56  'identifier' => '/myimages/'
57  ],
58  [
59  'folder' => '2:/myimages/'
60  ],
61  't3://folder?storage=2&identifier=%2Fmyimages%2F'
62  ],
63  ];
64  }
65 
76  public function ‪resolveFileReferencesToSplitParameters(array $input, array $expected): void
77  {
78  $storage = $this->getMockBuilder(ResourceStorage::class)
79  ->disableOriginalConstructor()
80  ->getMock();
81 
82  $factory = $this->getMockBuilder(ResourceFactory::class)
83  ->disableOriginalConstructor()
84  ->getMock();
85 
86  // fake methods to return proper objects
87  $folderObject = new ‪Folder($storage, $expected['folder'], $expected['folder']);
88  $factory->expects(self::once())->method('getFolderObjectFromCombinedIdentifier')->with($expected['folder'])
89  ->willReturn($folderObject);
90  $expected['folder'] = $folderObject;
91  GeneralUtility::setSingletonInstance(ResourceFactory::class, $factory);
92 
93  $subject = new ‪FolderLinkHandler();
94 
95  self::assertEquals($expected, $subject->resolveHandlerData($input));
96  }
97 
109  public function ‪splitParametersToUnifiedIdentifierForFiles(array $input, array $parameters, string $expected): void
110  {
111  $folderObject = $this->getMockBuilder(Folder::class)
112  ->onlyMethods(['getCombinedIdentifier', 'getStorage', 'getIdentifier'])
113  ->disableOriginalConstructor()
114  ->getMock();
115 
116  $folderObject->expects(self::any())->method('getCombinedIdentifier')->willReturn($parameters['folder']);
117  $folderData = explode(':', $parameters['folder']);
119  $storage = $this->getMockBuilder(ResourceStorage::class)
120  ->disableOriginalConstructor()
121  ->getMock(['getUid']);
122  $storage->method('getUid')->willReturn($folderData[0]);
123  $folderObject->method('getStorage')->willReturn($storage);
124  $folderObject->method('getIdentifier')->willReturn($folderData[1]);
125  $parameters['folder'] = $folderObject;
126 
127  $subject = new ‪FolderLinkHandler();
128  self::assertEquals($expected, $subject->asString($parameters));
129  }
130 }
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:37
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:41
‪TYPO3\CMS\Core\Resource\ResourceStorage
Definition: ResourceStorage.php:122
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46