[TASK] Re-work/simplify copyright header in PHP files - Part 2
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Tests / Unit / FolderStructure / RootNodeTest.php
1 <?php
2 namespace TYPO3\CMS\Install\Tests\Unit\FolderStructure;
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
17 /**
18 * Test case
19 */
20 class RootNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
21
22 /**
23 * @var array Directories or files in typo3temp/ created during tests to delete afterwards
24 */
25 protected $testNodesToDelete = array();
26
27 /**
28 * Tear down
29 */
30 public function tearDown() {
31 foreach ($this->testNodesToDelete as $node) {
32 if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($node, PATH_site . 'typo3temp/')) {
33 \TYPO3\CMS\Core\Utility\GeneralUtility::rmdir($node, TRUE);
34 }
35 }
36 parent::tearDown();
37 }
38
39 /**
40 * @test
41 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\RootNodeException
42 */
43 public function constructorThrowsExceptionIfParentIsNotNull() {
44 /** @var $node \TYPO3\CMS\Install\FolderStructure\RootNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
45 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\RootNode', array('isWindowsOs'), array(), '', FALSE);
46 $falseParent = $this->getMock(
47 'TYPO3\CMS\Install\FolderStructure\RootNodeInterface',
48 array(),
49 array(),
50 '',
51 FALSE
52 );
53 $node->__construct(array(), $falseParent);
54 }
55
56 /**
57 * @test
58 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
59 */
60 public function constructorThrowsExceptionIfAbsolutePathIsNotSet() {
61 /** @var $node \TYPO3\CMS\Install\FolderStructure\RootNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
62 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\RootNode', array('isWindowsOs'), array(), '', FALSE);
63 $structure = array(
64 'type' => 'root',
65 );
66 $node->__construct($structure, NULL);
67 }
68
69 /**
70 * @test
71 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
72 */
73 public function constructorThrowsExceptionIfAbsolutePathIsNotAbsoluteOnWindows() {
74 /** @var $node \TYPO3\CMS\Install\FolderStructure\RootNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
75 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\RootNode', array('isWindowsOs'), array(), '', FALSE);
76 $node
77 ->expects($this->any())
78 ->method('isWindowsOs')
79 ->will($this->returnValue(TRUE));
80 $structure = array(
81 'name' => '/bar'
82 );
83 $node->__construct($structure, NULL);
84 }
85
86 /**
87 * @test
88 * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
89 */
90 public function constructorThrowsExceptionIfAbsolutePathIsNotAbsoluteOnUnix() {
91 /** @var $node \TYPO3\CMS\Install\FolderStructure\RootNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
92 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\RootNode', array('isWindowsOs'), array(), '', FALSE);
93 $node
94 ->expects($this->any())
95 ->method('isWindowsOs')
96 ->will($this->returnValue(FALSE));
97 $structure = array(
98 'name' => 'C:/bar'
99 );
100 $node->__construct($structure, NULL);
101 }
102
103 /**
104 * @test
105 */
106 public function constructorSetsParentToNull() {
107 /** @var $node \TYPO3\CMS\Install\FolderStructure\RootNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
108 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\RootNode', array('isWindowsOs'), array(), '', FALSE);
109 $node
110 ->expects($this->any())
111 ->method('isWindowsOs')
112 ->will($this->returnValue(FALSE));
113 $structure = array(
114 'name' => '/bar'
115 );
116 $node->__construct($structure, NULL);
117 $this->assertNull($node->_call('getParent'));
118 }
119
120 /**
121 * @test
122 */
123 public function getChildrenReturnsChildCreatedByConstructor() {
124 /** @var $node \TYPO3\CMS\Install\FolderStructure\RootNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
125 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\RootNode', array('isWindowsOs'), array(), '', FALSE);
126 $node
127 ->expects($this->any())
128 ->method('isWindowsOs')
129 ->will($this->returnValue(FALSE));
130 $childName = uniqid('test_');
131 $structure = array(
132 'name' => '/foo',
133 'children' => array(
134 array(
135 'type' => 'TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode',
136 'name' => $childName,
137 ),
138 ),
139 );
140 $node->__construct($structure, NULL);
141 $children = $node->_call('getChildren');
142 /** @var $child \TYPO3\CMS\install\FolderStructure\NodeInterface */
143 $child = $children[0];
144 $this->assertInstanceOf('TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode', $child);
145 $this->assertSame($childName, $child->getName());
146 }
147
148 /**
149 * @test
150 */
151 public function constructorSetsTargetPermission() {
152 /** @var $node \TYPO3\CMS\Install\FolderStructure\RootNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
153 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\RootNode', array('isWindowsOs'), array(), '', FALSE);
154 $node
155 ->expects($this->any())
156 ->method('isWindowsOs')
157 ->will($this->returnValue(FALSE));
158 $targetPermission = '2550';
159 $structure = array(
160 'name' => '/foo',
161 'targetPermission' => $targetPermission,
162 );
163 $node->__construct($structure, NULL);
164 $this->assertSame($targetPermission, $node->_call('getTargetPermission'));
165 }
166
167 /**
168 * @test
169 */
170 public function constructorSetsName() {
171 /** @var $node \TYPO3\CMS\Install\FolderStructure\RootNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
172 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\RootNode', array('isWindowsOs'), array(), '', FALSE);
173 $node
174 ->expects($this->any())
175 ->method('isWindowsOs')
176 ->will($this->returnValue(FALSE));
177 $name = '/' . uniqid('test_');
178 $node->__construct(array('name' => $name), NULL);
179 $this->assertSame($name, $node->getName());
180 }
181
182 /**
183 * @test
184 */
185 public function getStatusReturnsArrayWithOkStatusAndCallsOwnStatusMethods() {
186 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
187 $node = $this->getAccessibleMock(
188 'TYPO3\\CMS\\Install\\FolderStructure\\RootNode',
189 array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect'),
190 array(),
191 '',
192 FALSE
193 );
194 $path = PATH_site . 'typo3temp/' . uniqid('dir_');
195 touch ($path);
196 $this->testNodesToDelete[] = $path;
197 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
198 $node->expects($this->once())->method('exists')->will($this->returnValue(TRUE));
199 $node->expects($this->once())->method('isDirectory')->will($this->returnValue(TRUE));
200 $node->expects($this->once())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
201 $node->expects($this->once())->method('isWritable')->will($this->returnValue(TRUE));
202 $statusArray = $node->getStatus();
203 /** @var $status \TYPO3\CMS\Install\Status\StatusInterface */
204 $status = $statusArray[0];
205 $this->assertInstanceOf('\TYPO3\CMS\Install\Status\OkStatus', $status);
206 }
207
208 /**
209 * @test
210 */
211 public function getStatusCallsGetChildrenStatusForStatus() {
212 /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
213 $node = $this->getAccessibleMock(
214 'TYPO3\\CMS\\Install\\FolderStructure\\RootNode',
215 array('getAbsolutePath', 'exists', 'isDirectory', 'isWritable', 'isPermissionCorrect', 'getChildrenStatus'),
216 array(),
217 '',
218 FALSE
219 );
220 $path = PATH_site . 'typo3temp/' . uniqid('dir_');
221 touch ($path);
222 $this->testNodesToDelete[] = $path;
223 $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
224 $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE));
225 $node->expects($this->any())->method('isDirectory')->will($this->returnValue(TRUE));
226 $node->expects($this->any())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
227 $node->expects($this->any())->method('isWritable')->will($this->returnValue(TRUE));
228 $childStatusMock = $this->getMock('TYPO3\\CMS\\Install\\Status\\ErrorStatus', array(), array(), '', FALSE);
229 $node->expects($this->once())->method('getChildrenStatus')->will($this->returnValue(array($childStatusMock)));
230 $statusArray = $node->getStatus();
231 /** @var $status \TYPO3\CMS\Install\Status\StatusInterface */
232 $statusSelf = $statusArray[0];
233 $statusOfChild = $statusArray[1];
234 $this->assertInstanceOf('\TYPO3\CMS\Install\Status\OkStatus', $statusSelf);
235 $this->assertInstanceOf('\TYPO3\CMS\Install\Status\ErrorStatus', $statusOfChild);
236 }
237
238 /**
239 * @test
240 */
241 public function getAbsolutePathReturnsGivenName() {
242 /** @var $node \TYPO3\CMS\Install\FolderStructure\RootNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
243 $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\RootNode', array('isWindowsOs'), array(), '', FALSE);
244 $node
245 ->expects($this->any())
246 ->method('isWindowsOs')
247 ->will($this->returnValue(FALSE));
248 $path = '/foo/bar';
249 $structure = array(
250 'name' => $path,
251 );
252 $node->__construct($structure, NULL);
253 $this->assertSame($path, $node->getAbsolutePath());
254 }
255 }