TYPO3 CMS  TYPO3_7-6
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 
18 
23 {
27  protected $singletonInstances = [];
28 
29  protected $basedir = 'basedir';
30 
31  protected function setUp()
32  {
34  vfsStream::setup($this->basedir);
35  }
36 
37  protected function tearDown()
38  {
40  parent::tearDown();
41  }
42 
43  protected function createFolderFixture($path, $name, $mockedStorage = null)
44  {
45  if ($mockedStorage === null) {
46  $mockedStorage = $this->getMock(\TYPO3\CMS\Core\Resource\ResourceStorage::class, [], [], '', false);
47  }
48  return new \TYPO3\CMS\Core\Resource\Folder($mockedStorage, $path, $name, 0);
49  }
50 
55  {
56  $path = $this->getUniqueId();
57  $name = $this->getUniqueId();
58  $mockedStorage = $this->getMock(\TYPO3\CMS\Core\Resource\ResourceStorage::class, [], [], '', false);
59  $fixture = $this->createFolderFixture($path, $name, $mockedStorage);
60  $this->assertSame($mockedStorage, $fixture->getStorage());
61  $this->assertStringStartsWith($path, $fixture->getIdentifier());
62  $this->assertSame($name, $fixture->getName());
63  }
64 
68  public function propertiesCanBeUpdated()
69  {
70  $fixture = $this->createFolderFixture('/somePath', 'someName');
71  $fixture->updateProperties(['identifier' => '/someOtherPath', 'name' => 'someNewName']);
72  $this->assertSame('someNewName', $fixture->getName());
73  $this->assertSame('/someOtherPath', $fixture->getIdentifier());
74  }
75 
80  {
81  $fixture = $this->createFolderFixture('/somePath/someName/', 'someName');
82  $fixture->updateProperties(['identifier' => '/someOtherPath']);
83  $this->assertSame('someName', $fixture->getName());
84  }
85 
90  {
91  $mockedStorage = $this->getMock(\TYPO3\CMS\Core\Resource\ResourceStorage::class, [], [], '', false);
92  $mockedStorage->expects($this->once())->method('getFilesInFolder')->will($this->returnValue([
93  'somefile.png' => [
94  'name' => 'somefile.png'
95  ],
96  'somefile.jpg' => [
97  'name' => 'somefile.jpg'
98  ]
99  ]
100  ));
101  $fixture = $this->createFolderFixture('/somePath', 'someName', $mockedStorage);
102 
103  $fileList = $fixture->getFiles();
104 
105  $this->assertSame(['somefile.png', 'somefile.jpg'], array_keys($fileList));
106  }
107 
112  {
113  $mockedStorage = $this->getMock(\TYPO3\CMS\Core\Resource\ResourceStorage::class, [], [], '', false);
114  $mockedStorage
115  ->expects($this->once())
116  ->method('getFilesInFolder')
117  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), false)
118  ->will($this->returnValue([]));
119 
120  $fixture = $this->createFolderFixture('/somePath', 'someName', $mockedStorage);
121  $fixture->getFiles();
122  }
123 
128  {
129  $mockedStorage = $this->getMock(\TYPO3\CMS\Core\Resource\ResourceStorage::class, [], [], '', false);
130  $mockedStorage
131  ->expects($this->once())
132  ->method('getFilesInFolder')
133  ->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), true)
134  ->will($this->returnValue([]));
135 
136  $fixture = $this->createFolderFixture('/somePath', 'someName', $mockedStorage);
137  $fixture->getFiles(0, 0, \TYPO3\CMS\Core\Resource\Folder::FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS, true);
138  }
139 
144  {
145  $parentIdentifier = '/parent/';
146  $currentIdentifier = '/parent/current/';
147 
148  $parentFolderFixture = $this->createFolderFixture($parentIdentifier, 'parent');
149  $mockedStorage = $this->getMock(\TYPO3\CMS\Core\Resource\ResourceStorage::class, ['getFolderIdentifierFromFileIdentifier', 'getFolder'], [], '', false);
150  $mockedStorage->expects($this->once())->method('getFolderIdentifierFromFileIdentifier')->with($currentIdentifier)->will($this->returnValue($parentIdentifier));
151  $mockedStorage->expects($this->once())->method('getFolder')->with($parentIdentifier)->will($this->returnValue($parentFolderFixture));
152 
153  $currentFolderFixture = $this->createFolderFixture($currentIdentifier, 'current', $mockedStorage);
154 
155  $this->assertSame($parentFolderFixture, $currentFolderFixture->getParentFolder());
156  }
157 }
static resetSingletonInstances(array $newSingletonInstances)
const FILTER_MODE_USE_OWN_AND_STORAGE_FILTERS
Definition: Folder.php:68
createFolderFixture($path, $name, $mockedStorage=null)
Definition: FolderTest.php:43