‪TYPO3CMS  9.5
FolderTest.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 
17 use org\bovigo\vfs\vfsStream;
18 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
19 
23 class ‪FolderTest extends UnitTestCase
24 {
28  protected ‪$resetSingletonInstances = true;
29 
30  protected ‪$basedir = 'basedir';
31 
32  protected function ‪setUp()
33  {
34  vfsStream::setup($this->basedir);
35  }
36 
37  protected function ‪createFolderFixture($path, $name, $mockedStorage = null)
38  {
39  if ($mockedStorage === null) {
40  $mockedStorage = $this->createMock(\‪TYPO3\CMS\Core\Resource\ResourceStorage::class);
41  }
42  return new \TYPO3\CMS\Core\Resource\Folder($mockedStorage, $path, $name);
43  }
44 
49  {
50  $path = $this->getUniqueId();
51  $name = $this->getUniqueId();
52  $mockedStorage = $this->createMock(\‪TYPO3\CMS\Core\Resource\ResourceStorage::class);
53  $fixture = $this->‪createFolderFixture($path, $name, $mockedStorage);
54  $this->assertSame($mockedStorage, $fixture->getStorage());
55  $this->assertStringStartsWith($path, $fixture->getIdentifier());
56  $this->assertSame($name, $fixture->getName());
57  }
58 
62  public function ‪propertiesCanBeUpdated()
63  {
64  $fixture = $this->‪createFolderFixture('/somePath', 'someName');
65  $fixture->updateProperties(['identifier' => '/someOtherPath', 'name' => 'someNewName']);
66  $this->assertSame('someNewName', $fixture->getName());
67  $this->assertSame('/someOtherPath', $fixture->getIdentifier());
68  }
69 
74  {
75  $fixture = $this->‪createFolderFixture('/somePath/someName/', 'someName');
76  $fixture->updateProperties(['identifier' => '/someOtherPath']);
77  $this->assertSame('someName', $fixture->getName());
78  }
79 
84  {
85  $mockedStorage = $this->createMock(\‪TYPO3\CMS\Core\Resource\ResourceStorage::class);
86  $mockedStorage->expects($this->once())->method('getFilesInFolder')->will($this->returnValue(
87  [
88  'somefile.png' => [
89  'name' => 'somefile.png'
90  ],
91  'somefile.jpg' => [
92  'name' => 'somefile.jpg'
93  ]
94  ]
95  ));
96  $fixture = $this->‪createFolderFixture('/somePath', 'someName', $mockedStorage);
97 
98  $fileList = $fixture->getFiles();
99 
100  $this->assertSame(['somefile.png', 'somefile.jpg'], array_keys($fileList));
101  }
102 
107  {
108  $mockedStorage = $this->createMock(\‪TYPO3\CMS\Core\Resource\ResourceStorage::class);
109  $mockedStorage
110  ->expects($this->once())
111  ->method('getFilesInFolder')
112  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), false)
113  ->will($this->returnValue([]));
114 
115  $fixture = $this->‪createFolderFixture('/somePath', 'someName', $mockedStorage);
116  $fixture->getFiles();
117  }
118 
123  {
124  $mockedStorage = $this->createMock(\‪TYPO3\CMS\Core\Resource\ResourceStorage::class);
125  $mockedStorage
126  ->expects($this->once())
127  ->method('getFilesInFolder')
128  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), true)
129  ->will($this->returnValue([]));
130 
131  $fixture = $this->‪createFolderFixture('/somePath', 'someName', $mockedStorage);
132  $fixture->getFiles(0, 0, \‪TYPO3\CMS\Core\Resource\‪Folder::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS, true);
133  }
134 
139  {
140  $mockedStorage = $this->createMock(\‪TYPO3\CMS\Core\Resource\ResourceStorage::class);
141  $mockedStorage->expects($this->once())->method('hasFolderInFolder')->with($this->equalTo('someSubfolder'))->will($this->returnValue(true));
143  $mockedFactory = $this->createMock(\‪TYPO3\CMS\Core\Resource\ResourceFactory::class);
144  $folderFixture = $this->‪createFolderFixture(
145  '/somePath/someFolder/',
146  'someFolder',
147  $mockedStorage
148  );
149  $subfolderFixture = $this->‪createFolderFixture(
150  '/somePath/someSubfolder/',
151  'someSubfolder',
152  $mockedStorage
153  );
154  $mockedStorage->expects($this->once())->method('getFolderInFolder')->will($this->returnValue($subfolderFixture));
155  \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance(
156  \‪TYPO3\CMS\Core\Resource\ResourceFactory::class,
157  $mockedFactory
158  );
159  $this->assertEquals($subfolderFixture, $folderFixture->getSubfolder('someSubfolder'));
160  }
161 
166  {
167  $parentIdentifier = '/parent/';
168  $currentIdentifier = '/parent/current/';
169 
170  $parentFolderFixture = $this->‪createFolderFixture($parentIdentifier, 'parent');
171  $mockedStorage = $this->getMockBuilder(\‪TYPO3\CMS\Core\Resource\ResourceStorage::class)
172  ->setMethods(['getFolderIdentifierFromFileIdentifier', 'getFolder'])
173  ->disableOriginalConstructor()
174  ->getMock();
175  $mockedStorage->expects($this->once())->method('getFolderIdentifierFromFileIdentifier')->with($currentIdentifier)->will($this->returnValue($parentIdentifier));
176  $mockedStorage->expects($this->once())->method('getFolder')->with($parentIdentifier)->will($this->returnValue($parentFolderFixture));
177 
178  $currentFolderFixture = $this->‪createFolderFixture($currentIdentifier, 'current', $mockedStorage);
179 
180  $this->assertSame($parentFolderFixture, $currentFolderFixture->getParentFolder());
181  }
182 }
‪TYPO3\CMS\Core\Tests\Unit\Resource\FolderTest\constructorArgumentsAreAvailableAtRuntime
‪constructorArgumentsAreAvailableAtRuntime()
Definition: FolderTest.php:47
‪TYPO3\CMS\Core\Tests\Unit\Resource\FolderTest\getSubfolderCallsFactoryWithCorrectArguments
‪getSubfolderCallsFactoryWithCorrectArguments()
Definition: FolderTest.php:137
‪TYPO3\CMS\Core\Tests\Unit\Resource\FolderTest\propertiesAreNotUpdatedIfNotSetInInput
‪propertiesAreNotUpdatedIfNotSetInInput()
Definition: FolderTest.php:72
‪TYPO3\CMS\Core\Tests\Unit\Resource\FolderTest\propertiesCanBeUpdated
‪propertiesCanBeUpdated()
Definition: FolderTest.php:61
‪TYPO3
‪TYPO3\CMS\Core\Tests\Unit\Resource
Definition: AbstractFileTest.php:3
‪TYPO3\CMS\Core\Resource\Folder\FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS
‪const FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS
Definition: Folder.php:66
‪TYPO3\CMS\Core\Tests\Unit\Resource\FolderTest\getParentFolderGetsParentFolderFromStorage
‪getParentFolderGetsParentFolderFromStorage()
Definition: FolderTest.php:164
‪TYPO3\CMS\Core\Tests\Unit\Resource\FolderTest\getFilesReturnsArrayWithFilenamesAsKeys
‪getFilesReturnsArrayWithFilenamesAsKeys()
Definition: FolderTest.php:82
‪TYPO3\CMS\Core\Tests\Unit\Resource\FolderTest\getFilesHandsOverRecursiveFALSEifNotExplicitlySet
‪getFilesHandsOverRecursiveFALSEifNotExplicitlySet()
Definition: FolderTest.php:105
‪TYPO3\CMS\Core\Tests\Unit\Resource\FolderTest\createFolderFixture
‪createFolderFixture($path, $name, $mockedStorage=null)
Definition: FolderTest.php:36
‪TYPO3\CMS\Core\Tests\Unit\Resource\FolderTest\$basedir
‪$basedir
Definition: FolderTest.php:29
‪TYPO3\CMS\Core\Tests\Unit\Resource\FolderTest\setUp
‪setUp()
Definition: FolderTest.php:31
‪TYPO3\CMS\Core\Tests\Unit\Resource\FolderTest
Definition: FolderTest.php:24
‪TYPO3\CMS\Core\Tests\Unit\Resource\FolderTest\getFilesHandsOverRecursiveTRUEifSet
‪getFilesHandsOverRecursiveTRUEifSet()
Definition: FolderTest.php:121
‪TYPO3\CMS\Core\Tests\Unit\Resource\FolderTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: FolderTest.php:27