[BUGFIX] Fix the unit tests to work with PHPUnit 3.6
[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 tearDown() {
49 t3lib_div::purgeInstances();
50 }
51
52 protected function createFolderFixture($path, $name, $mockedStorage = NULL) {
53 if ($mockedStorage === NULL) {
54 $mockedStorage = $this->getMock('t3lib_file_Storage', array(), array(), '', FALSE);
55 }
56
57 return new t3lib_file_Folder($mockedStorage, $path, $name, 0);
58 }
59 /**
60 * @test
61 */
62 public function constructorArgumentsAreAvailableAtRuntime() {
63 $path = uniqid();
64 $name = uniqid();
65 $mockedStorage = $this->getMock('t3lib_file_Storage', array(), array(), '', FALSE);
66 $fixture = $this->createFolderFixture($path, $name, $mockedStorage);
67
68 $this->assertSame($mockedStorage, $fixture->getStorage());
69 $this->assertStringStartsWith($path, $fixture->getIdentifier());
70 $this->assertEquals($name, $fixture->getName());
71 }
72
73 /**
74 * @test
75 */
76 public function propertiesCanBeUpdated() {
77 $fixture = $this->createFolderFixture('/somePath', 'someName');
78 $fixture->updateProperties(array('identifier' => '/someOtherPath', 'name' => 'someNewName'));
79
80 $this->assertEquals('someNewName', $fixture->getName());
81 $this->assertEquals('/someOtherPath', $fixture->getIdentifier());
82 }
83
84 /**
85 * @test
86 */
87 public function propertiesAreNotUpdatedIfNotSetInInput() {
88 $fixture = $this->createFolderFixture('/somePath/someName/', 'someName');
89 $fixture->updateProperties(array('identifier' => '/someOtherPath'));
90
91 $this->assertEquals('someName', $fixture->getName());
92 }
93
94 /**
95 * @test
96 */
97 public function getSubfolderCallsFactoryWithCorrectArguments() {
98 $mockedStorage = $this->getMock('t3lib_file_Storage', array(), array(), '', FALSE);
99 $mockedStorage->expects($this->once())->method('hasFolderInFolder')->with($this->equalTo('someSubfolder'))
100 ->will($this->returnValue(TRUE));
101
102 $mockedFactory = $this->getMock('t3lib_file_Factory');
103 $mockedFactory->expects($this->once())->method('createFolderObject')->with($mockedStorage,
104 '/somePath/someFolder/someSubfolder/', 'someSubfolder');
105 t3lib_div::setSingletonInstance('t3lib_file_Factory', $mockedFactory);
106
107 $fixture = $this->createFolderFixture('/somePath/someFolder/', 'someFolder', $mockedStorage);
108 $fixture->getSubfolder('someSubfolder');
109 }
110 }
111 ?>