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