[BUGFIX] LocalDriver can be instantiated without basePath
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Resource / FolderTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Resource;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2011 Andreas Wolf <andreas.wolf@ikt-werk.de>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 require_once 'vfsStream/vfsStream.php';
31
32 /**
33 * Testcase for the storage collection class of the TYPO3 FAL
34 *
35 * @package TYPO3
36 * @subpackage t3lib
37 * @author Andreas Wolf <andreas.wolf@ikt-werk.de>
38 */
39 class FolderTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
40
41 /**
42 * @var array A backup of registered singleton instances
43 */
44 protected $singletonInstances = array();
45
46 private $basedir = 'basedir';
47
48 public function setUp() {
49 $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
50 \vfsStream::setup($this->basedir);
51 }
52
53 protected function tearDown() {
54 \TYPO3\CMS\Core\Utility\GeneralUtility::resetSingletonInstances($this->singletonInstances);
55 }
56
57 protected function createFolderFixture($path, $name, $mockedStorage = NULL) {
58 if ($mockedStorage === NULL) {
59 $mockedStorage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
60 }
61 return new \TYPO3\CMS\Core\Resource\Folder($mockedStorage, $path, $name, 0);
62 }
63
64 /**
65 * @test
66 */
67 public function constructorArgumentsAreAvailableAtRuntime() {
68 $path = uniqid();
69 $name = uniqid();
70 $mockedStorage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
71 $fixture = $this->createFolderFixture($path, $name, $mockedStorage);
72 $this->assertSame($mockedStorage, $fixture->getStorage());
73 $this->assertStringStartsWith($path, $fixture->getIdentifier());
74 $this->assertEquals($name, $fixture->getName());
75 }
76
77 /**
78 * @test
79 */
80 public function propertiesCanBeUpdated() {
81 $fixture = $this->createFolderFixture('/somePath', 'someName');
82 $fixture->updateProperties(array('identifier' => '/someOtherPath', 'name' => 'someNewName'));
83 $this->assertEquals('someNewName', $fixture->getName());
84 $this->assertEquals('/someOtherPath', $fixture->getIdentifier());
85 }
86
87 /**
88 * @test
89 */
90 public function propertiesAreNotUpdatedIfNotSetInInput() {
91 $fixture = $this->createFolderFixture('/somePath/someName/', 'someName');
92 $fixture->updateProperties(array('identifier' => '/someOtherPath'));
93 $this->assertEquals('someName', $fixture->getName());
94 }
95
96 /**
97 * @test
98 */
99 public function getSubfolderCallsFactoryWithCorrectArguments() {
100 $mockedStorage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
101 $mockedStorage->expects($this->once())->method('hasFolderInFolder')->with($this->equalTo('someSubfolder'))->will($this->returnValue(TRUE));
102 $mockedFactory = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceFactory');
103 $mockedFactory->expects($this->once())->method('createFolderObject')->with($mockedStorage, '/somePath/someFolder/someSubfolder/', 'someSubfolder');
104 \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Resource\\ResourceFactory', $mockedFactory);
105 $fixture = $this->createFolderFixture('/somePath/someFolder/', 'someFolder', $mockedStorage);
106 $fixture->getSubfolder('someSubfolder');
107 }
108
109 }
110
111 ?>