‪TYPO3CMS  9.5
FolderLinkHandlerTest.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 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
23 class ‪FolderLinkHandlerTest extends UnitTestCase
24 {
25 
38  {
39  return [
40  'folder without FAL - cool style' => [
41  [
42  'storage' => 0,
43  'identifier' => '/fileadmin/myimages/'
44  ],
45  [
46  'folder' => '0:/fileadmin/myimages/'
47  ],
48  't3://folder?storage=0&identifier=%2Ffileadmin%2Fmyimages%2F'
49  ],
50  'folder with combined identifier and file prefix (FAL) - cool style' => [
51  [
52  'storage' => 2,
53  'identifier' => '/myimages/'
54  ],
55  [
56  'folder' => '2:/myimages/'
57  ],
58  't3://folder?storage=2&identifier=%2Fmyimages%2F'
59  ],
60  ];
61  }
62 
74  public function ‪resolveFileReferencesToSplitParameters($input, $expected, $finalString)
75  {
76  $storage = $this->getMockBuilder(ResourceStorage::class)
77  ->disableOriginalConstructor()
78  ->getMock();
79 
80  $factory = $this->getMockBuilder(ResourceFactory::class)
81  ->disableOriginalConstructor()
82  ->getMock();
83 
84  // fake methods to return proper objects
85  $folderObject = new ‪Folder($storage, $expected['folder'], $expected['folder']);
86  $factory->expects($this->once())->method('getFolderObjectFromCombinedIdentifier')->with($expected['folder'])
87  ->willReturn($folderObject);
88  $expected['folder'] = $folderObject;
89 
91  $subject = $this->getAccessibleMock(FolderLinkHandler::class, ['dummy']);
92  $subject->_set('resourceFactory', $factory);
93  $this->assertEquals($expected, $subject->resolveHandlerData($input));
94  }
95 
107  public function ‪splitParametersToUnifiedIdentifierForFiles($input, $parameters, $expected)
108  {
109  $folderObject = $this->getMockBuilder(Folder::class)
110  ->setMethods(['getCombinedIdentifier', 'getStorage', 'getIdentifier'])
111  ->disableOriginalConstructor()
112  ->getMock();
113 
114  $folderObject->expects($this->any())->method('getCombinedIdentifier')->willReturn($parameters['folder']);
115  $folderData = explode(':', $parameters['folder']);
117  $storage = $this->getMockBuilder(ResourceStorage::class)
118  ->disableOriginalConstructor()
119  ->getMock(['getUid']);
120  $storage->method('getUid')->willReturn($folderData[0]);
121  $folderObject->expects($this->any())->method('getStorage')->willReturn($storage);
122  $folderObject->expects($this->any())->method('getIdentifier')->willReturn($folderData[1]);
123  $parameters['folder'] = $folderObject;
124 
125  $subject = new ‪FolderLinkHandler();
126  $this->assertEquals($expected, $subject->asString($parameters));
127  }
128 }
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:34
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:33
‪TYPO3\CMS\Core\Resource\ResourceStorage
Definition: ResourceStorage.php:74