2 namespace TYPO3\CMS\Install\Tests\Unit\FolderStructure
;
4 /***************************************************************
7 * (c) 2013 Christian Kuhn <lolli@schwarzbu.ch>
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.
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
30 class RootNodeTest
extends \TYPO3\CMS\Core\Tests\UnitTestCase
{
33 * @var array Directories or files in typo3temp/ created during tests to delete afterwards
35 protected $testNodesToDelete = array();
40 public function tearDown() {
41 foreach ($this->testNodesToDelete
as $node) {
42 if (\TYPO3\CMS\Core\Utility\GeneralUtility
::isFirstPartOfStr($node, PATH_site
. 'typo3temp/')) {
43 \TYPO3\CMS\Core\Utility\GeneralUtility
::rmdir($node, TRUE);
50 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\RootNodeException
52 public function constructorThrowsExceptionIfParentIsNotNull() {
53 /** @var $node \TYPO3\CMS\Install\FolderStructure\RootNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
54 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\RootNode', array('isWindowsOs'), array(), '', FALSE);
55 $falseParent = $this->getMock(
56 'TYPO3\CMS\Install\FolderStructure\RootNodeInterface',
62 $node->__construct(array(), $falseParent);
67 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
69 public function constructorThrowsExceptionIfAbsolutePathIsNotSet() {
70 /** @var $node \TYPO3\CMS\Install\FolderStructure\RootNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
71 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\RootNode', array('isWindowsOs'), array(), '', FALSE);
75 $node->__construct($structure, NULL);
80 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
82 public function constructorThrowsExceptionIfAbsolutePathIsNotAbsoluteOnWindows() {
83 /** @var $node \TYPO3\CMS\Install\FolderStructure\RootNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
84 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\RootNode', array('isWindowsOs'), array(), '', FALSE);
86 ->expects($this->any())
87 ->method('isWindowsOs')
88 ->will($this->returnValue(TRUE));
92 $node->__construct($structure, NULL);
97 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
99 public function constructorThrowsExceptionIfAbsolutePathIsNotAbsoluteOnUnix() {
100 /** @var $node \TYPO3\CMS\Install\FolderStructure\RootNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
101 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\RootNode', array('isWindowsOs'), array(), '', FALSE);
103 ->expects($this->any())
104 ->method('isWindowsOs')
105 ->will($this->returnValue(FALSE));
109 $node->__construct($structure, NULL);
115 public function constructorSetsParentToNull() {
116 /** @var $node \TYPO3\CMS\Install\FolderStructure\RootNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
117 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\RootNode', array('isWindowsOs'), array(), '', FALSE);
119 ->expects($this->any())
120 ->method('isWindowsOs')
121 ->will($this->returnValue(FALSE));
125 $node->__construct($structure, NULL);
126 $this->assertNull($node->getParent());
132 public function getChildrenReturnsChildCreatedByConstructor() {
133 /** @var $node \TYPO3\CMS\Install\FolderStructure\RootNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
134 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\RootNode', array('isWindowsOs'), array(), '', FALSE);
136 ->expects($this->any())
137 ->method('isWindowsOs')
138 ->will($this->returnValue(FALSE));
139 $childName = uniqid('test_');
144 'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
145 'name' => $childName,
149 $node->__construct($structure, NULL);
150 $children = $node->getChildren();
151 /** @var $child \TYPO3\CMS\install\FolderStructure\NodeInterface */
152 $child = $children[0];
153 $this->assertInstanceOf('TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode', $child);
154 $this->assertSame($childName, $child->getName());
160 public function constructorSetsTargetPermission() {
161 /** @var $node \TYPO3\CMS\Install\FolderStructure\RootNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
162 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\RootNode', array('isWindowsOs'), array(), '', FALSE);
164 ->expects($this->any())
165 ->method('isWindowsOs')
166 ->will($this->returnValue(FALSE));
167 $targetPermission = '2550';
170 'targetPermission' => $targetPermission,
172 $node->__construct($structure, NULL);
173 $this->assertSame($targetPermission, $node->getTargetPermission());
179 public function constructorSetsName() {
180 /** @var $node \TYPO3\CMS\Install\FolderStructure\RootNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
181 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\RootNode', array('isWindowsOs'), array(), '', FALSE);
183 ->expects($this->any())
184 ->method('isWindowsOs')
185 ->will($this->returnValue(FALSE));
186 $name = '/' . uniqid('test_');
187 $node->__construct(array('name' => $name), NULL);
188 $this->assertSame($name, $node->getName());
194 public function getStatusReturnsArrayWithOkStatusAndCallsOwnStatusMethods() {
195 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
196 $node = $this->getAccessibleMock(
197 'TYPO3\\CMS\\Install\\FolderStructure\\RootNode',
198 array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'),
203 $path = PATH_site
. 'typo3temp/' . uniqid('dir_');
205 $this->testNodesToDelete
[] = $path;
206 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
207 $node->expects($this->once())->method('exists')->will($this->returnValue(TRUE));
208 $node->expects($this->once())->method('isDirectory')->will($this->returnValue(TRUE));
209 $node->expects($this->once())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
210 $node->expects($this->once())->method('isWritable')->will($this->returnValue(TRUE));
211 $statusArray = $node->getStatus();
212 /** @var $status \TYPO3\CMS\Install\Status\StatusInterface */
213 $status = $statusArray[0];
214 $this->assertInstanceOf('\TYPO3\CMS\Install\Status\OkStatus', $status);
220 public function getStatusCallsGetChildrenStatusForStatus() {
221 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
222 $node = $this->getAccessibleMock(
223 'TYPO3\\CMS\\Install\\FolderStructure\\RootNode',
224 array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect', 'getChildrenStatus'),
229 $path = PATH_site
. 'typo3temp/' . uniqid('dir_');
231 $this->testNodesToDelete
[] = $path;
232 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
233 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
234 $node->expects($this->any())->method('isDirectory')->will($this->returnValue(TRUE));
235 $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
236 $node->expects($this->any())->method('isWritable')->will($this->returnValue(TRUE));
237 $childStatusMock = $this->getMock('TYPO3\\CMS\\Install\\Status\\ErrorStatus', array(), array(), '', FALSE);
238 $node->expects($this->once())->method('getChildrenStatus')->will($this->returnValue(array($childStatusMock)));
239 $statusArray = $node->getStatus();
240 /** @var $status \TYPO3\CMS\Install\Status\StatusInterface */
241 $statusSelf = $statusArray[0];
242 $statusOfChild = $statusArray[1];
243 $this->assertInstanceOf('\TYPO3\CMS\Install\Status\OkStatus', $statusSelf);
244 $this->assertInstanceOf('\TYPO3\CMS\Install\Status\ErrorStatus', $statusOfChild);
250 public function getAbsolutePathReturnsGivenName() {
251 /** @var $node \TYPO3\CMS\Install\FolderStructure\RootNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
252 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\RootNode', array('isWindowsOs'), array(), '', FALSE);
254 ->expects($this->any())
255 ->method('isWindowsOs')
256 ->will($this->returnValue(FALSE));
261 $node->__construct($structure, NULL);
262 $this->assertSame($path, $node->getAbsolutePath());