TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
FolderLinkHandlerTest.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\LinkHandling;
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 
23 {
24 
37  {
38  return [
39  'folder without FAL - cool style' => [
40  [
41  'storage' => 0,
42  'identifier' => '/fileadmin/myimages/'
43  ],
44  [
45  'folder' => '0:/fileadmin/myimages/'
46  ],
47  't3://folder?storage=0&identifier=%2Ffileadmin%2Fmyimages%2F'
48  ],
49  'folder with combined identifier and file prefix (FAL) - cool style' => [
50  [
51  'storage' => 2,
52  'identifier' => '/myimages/'
53  ],
54  [
55  'folder' => '2:/myimages/'
56  ],
57  't3://folder?storage=2&identifier=%2Fmyimages%2F'
58  ],
59  ];
60  }
61 
73  public function resolveFileReferencesToSplitParameters($input, $expected, $finalString)
74  {
75  $storage = $this->getMockBuilder(ResourceStorage::class)
76  ->disableOriginalConstructor()
77  ->getMock();
78 
79  $factory = $this->getMockBuilder(ResourceFactory::class)
80  ->disableOriginalConstructor()
81  ->getMock();
82 
83  // fake methods to return proper objects
84  $folderObject = new Folder($storage, $expected['folder'], $expected['folder']);
85  $factory->expects($this->once())->method('getFolderObjectFromCombinedIdentifier')->with($expected['folder'])
86  ->willReturn($folderObject);
87  $expected['folder'] = $folderObject;
88 
90  $subject = $this->getAccessibleMock(FolderLinkHandler::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  $folderObject = $this->getMockBuilder(Folder::class)
109  ->setMethods(['getCombinedIdentifier', 'getStorage', 'getIdentifier'])
110  ->disableOriginalConstructor()
111  ->getMock();
112 
113  $folderObject->expects($this->any())->method('getCombinedIdentifier')->willReturn($parameters['folder']);
114  $folderData = explode(':', $parameters['folder']);
116  $storage = $this->getMockBuilder(ResourceStorage::class)
117  ->disableOriginalConstructor()
118  ->getMock(['getUid']);
119  $storage->method('getUid')->willReturn($folderData[0]);
120  $folderObject->expects($this->any())->method('getStorage')->willReturn($storage);
121  $folderObject->expects($this->any())->method('getIdentifier')->willReturn($folderData[1]);
122  $parameters['folder'] = $folderObject;
123 
124  $subject = new FolderLinkHandler();
125  $this->assertEquals($expected, $subject->asString($parameters));
126  }
127 }
getAccessibleMock($originalClassName, $methods=[], array $arguments=[], $mockClassName= '', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)