2 namespace TYPO3\CMS\Install\Tests\Unit\FolderStructure;
25 public function getNameReturnsSetName()
28 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\AbstractNode::class, array(
'dummy'), array(),
'',
false);
29 $name = $this->getUniqueId(
'name_');
30 $node->_set(
'name', $name);
31 $this->assertSame($name, $node->getName());
37 public function getTargetPermissionReturnsSetTargetPermission()
40 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\AbstractNode::class, array(
'dummy'), array(),
'',
false);
42 $node->_set(
'targetPermission', $permission);
43 $this->assertSame($permission, $node->_call(
'getTargetPermission'));
49 public function getChildrenReturnsSetChildren()
52 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\AbstractNode::class, array(
'dummy'), array(),
'',
false);
53 $children = array(
'1234');
54 $node->_set(
'children', $children);
55 $this->assertSame($children, $node->_call(
'getChildren'));
61 public function getParentReturnsSetParent()
64 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\AbstractNode::class, array(
'dummy'), array(),
'',
false);
65 $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class, array(), array(),
'',
false);
66 $node->_set(
'parent', $parent);
67 $this->assertSame($parent, $node->_call(
'getParent'));
73 public function getAbsolutePathCallsParentForPathAndAppendsOwnName()
76 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\AbstractNode::class, array(
'dummy'), array(),
'',
false);
77 $parent = $this->getMock(\TYPO3\CMS\Install\FolderStructure\RootNodeInterface::class, array(), array(),
'',
false);
78 $parentPath =
'/foo/bar';
79 $parent->expects($this->once())->method(
'getAbsolutePath')->will($this->returnValue($parentPath));
80 $name = $this->getUniqueId(
'test_');
81 $node->_set(
'parent', $parent);
82 $node->_set(
'name', $name);
83 $this->assertSame($parentPath .
'/' . $name, $node->getAbsolutePath());
89 public function isWritableCallsParentIsWritable()
92 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\AbstractNode::class, array(
'dummy'), array(),
'',
false);
93 $parentMock = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class, array(), array(),
'',
false);
94 $parentMock->expects($this->once())->method(
'isWritable');
95 $node->_set(
'parent', $parentMock);
102 public function isWritableReturnsWritableStatusOfParent()
105 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\AbstractNode::class, array(
'dummy'), array(),
'',
false);
106 $parentMock = $this->getMock(\TYPO3\CMS\Install\FolderStructure\NodeInterface::class, array(), array(),
'',
false);
107 $parentMock->expects($this->once())->method(
'isWritable')->will($this->returnValue(
true));
108 $node->_set(
'parent', $parentMock);
109 $this->assertTrue($node->isWritable());
115 public function existsReturnsTrueIfNodeExists()
118 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\AbstractNode::class, array(
'getAbsolutePath'), array(),
'',
false);
120 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
121 $this->assertTrue($node->_call(
'exists'));
128 public function existsReturnsTrueIfIsLinkAndTargetIsDead()
130 if (TYPO3_OS ===
'WIN') {
131 $this->markTestSkipped(
'Test not available on Windows OS.');
134 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\AbstractNode::class, array(
'getAbsolutePath'), array(),
'',
false);
135 $path = PATH_site .
'typo3temp/' . $this->getUniqueId(
'link_');
136 $target = PATH_site .
'typo3temp/' . $this->getUniqueId(
'notExists_');
137 symlink($target, $path);
138 $this->testFilesToDelete[] = $path;
139 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
140 $this->assertTrue($node->_call(
'exists'));
146 public function existsReturnsFalseIfNodeNotExists()
149 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\AbstractNode::class, array(
'getAbsolutePath'), array(),
'',
false);
151 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
152 $this->assertFalse($node->_call(
'exists'));
159 public function fixPermissionThrowsExceptionIfPermissionAreAlreadyCorrect()
162 $node = $this->getAccessibleMock(
163 \TYPO3\CMS\Install\FolderStructure\AbstractNode::class,
164 array(
'isPermissionCorrect',
'getAbsolutePath'),
169 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue(
''));
170 $node->expects($this->once())->method(
'isPermissionCorrect')->will($this->returnValue(
true));
171 $node->_call(
'fixPermission');
177 public function fixPermissionReturnsNoticeStatusIfPermissionCanNotBeChanged()
179 if (TYPO3_OS ===
'WIN') {
180 $this->markTestSkipped(
'Test not available on Windows OS.');
182 if (function_exists(
'posix_getegid') && posix_getegid() === 0) {
183 $this->markTestSkipped(
'Test skipped if run on linux as root');
186 $node = $this->getAccessibleMock(
187 \TYPO3\CMS\Install\FolderStructure\AbstractNode::class,
188 array(
'isPermissionCorrect',
'getRelativePathBelowSiteRoot',
'getAbsolutePath'),
193 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue(
''));
194 $node->expects($this->once())->method(
'isPermissionCorrect')->will($this->returnValue(
false));
196 $subPath = $path .
'/' . $this->getUniqueId(
'dir_');
199 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($subPath));
200 $node->_set(
'targetPermission',
'2770');
201 $this->assertInstanceOf(\TYPO3\CMS\Install\Status\NoticeStatus::class, $node->_call(
'fixPermission'));
208 public function fixPermissionReturnsNoticeStatusIfPermissionsCanNotBeChanged()
210 if (TYPO3_OS ===
'WIN') {
211 $this->markTestSkipped(
'Test not available on Windows OS.');
213 if (function_exists(
'posix_getegid') && posix_getegid() === 0) {
214 $this->markTestSkipped(
'Test skipped if run on linux as root');
217 $node = $this->getAccessibleMock(
218 \TYPO3\CMS\Install\FolderStructure\AbstractNode::class,
219 array(
'isPermissionCorrect',
'getRelativePathBelowSiteRoot',
'getAbsolutePath'),
224 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue(
''));
225 $node->expects($this->once())->method(
'isPermissionCorrect')->will($this->returnValue(
false));
227 $subPath = $path .
'/' . $this->getUniqueId(
'dir_');
230 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($subPath));
231 $node->_set(
'targetPermission',
'2770');
232 $this->assertInstanceOf(\TYPO3\CMS\Install\Status\NoticeStatus::class, $node->_call(
'fixPermission'));
239 public function fixPermissionReturnsOkStatusIfPermissionCanBeFixedAndSetsPermissionToCorrectValue()
241 if (TYPO3_OS ===
'WIN') {
242 $this->markTestSkipped(
'Test not available on Windows OS.');
245 $node = $this->getAccessibleMock(
246 \TYPO3\CMS\Install\FolderStructure\AbstractNode::class,
247 array(
'isPermissionCorrect',
'getRelativePathBelowSiteRoot',
'getAbsolutePath'),
252 $node->expects($this->any())->method(
'getRelativePathBelowSiteRoot')->will($this->returnValue(
''));
253 $node->expects($this->once())->method(
'isPermissionCorrect')->will($this->returnValue(
false));
255 $subPath = $path .
'/' . $this->getUniqueId(
'dir_');
258 $node->_set(
'targetPermission',
'2770');
259 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($subPath));
260 $this->assertInstanceOf(\TYPO3\CMS\Install\Status\OkStatus::class, $node->_call(
'fixPermission'));
261 $resultDirectoryPermissions = substr(decoct(fileperms($subPath)), 1);
262 $this->assertSame(
'2770', $resultDirectoryPermissions);
268 public function isPermissionCorrectReturnsTrueOnWindowsOs()
271 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\AbstractNode::class, array(
'isWindowsOs'), array(),
'',
false);
272 $node->expects($this->once())->method(
'isWindowsOs')->will($this->returnValue(
true));
273 $this->assertTrue($node->_call(
'isPermissionCorrect'));
279 public function isPermissionCorrectReturnsFalseIfTargetPermissionAndCurrentPermissionAreNotIdentical()
282 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\AbstractNode::class, array(
'isWindowsOs',
'getCurrentPermission'), array(),
'',
false);
283 $node->expects($this->any())->method(
'isWindowsOs')->will($this->returnValue(
false));
284 $node->expects($this->any())->method(
'getCurrentPermission')->will($this->returnValue(
'foo'));
285 $node->_set(
'targetPermission',
'bar');
286 $this->assertFalse($node->_call(
'isPermissionCorrect'));
292 public function getCurrentPermissionReturnsCurrentDirectoryPermission()
294 if (TYPO3_OS ===
'WIN') {
295 $this->markTestSkipped(
'Test not available on Windows OS.');
298 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\AbstractNode::class, array(
'getAbsolutePath'), array(),
'',
false);
302 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($path));
303 $this->assertSame(
'2775', $node->_call(
'getCurrentPermission'));
309 public function getCurrentPermissionReturnsCurrentFilePermission()
311 if (TYPO3_OS ===
'WIN') {
312 $this->markTestSkipped(
'Test not available on Windows OS.');
315 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\AbstractNode::class, array(
'getAbsolutePath'), array(),
'',
false);
320 $node->expects($this->any())->method(
'getAbsolutePath')->will($this->returnValue($file));
321 $this->assertSame(
'0770', $node->_call(
'getCurrentPermission'));
328 public function getRelativePathBelowSiteRootThrowsExceptionIfGivenPathIsNotBelowPathSiteConstant()
331 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\AbstractNode::class, array(
'dummy'), array(),
'',
false);
332 $node->_call(
'getRelativePathBelowSiteRoot',
'/tmp');
338 public function getRelativePathCallsGetAbsolutePathIfPathIsNull()
341 $node = $this->getAccessibleMock(
342 \TYPO3\CMS\Install\FolderStructure\AbstractNode::class,
343 array(
'getAbsolutePath'),
348 $node->expects($this->once())->method(
'getAbsolutePath')->will($this->returnValue(PATH_site));
349 $node->_call(
'getRelativePathBelowSiteRoot', null);
355 public function getRelativePathBelowSiteRootReturnsSingleForwardSlashIfGivenPathEqualsPathSiteConstant()
358 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\AbstractNode::class, array(
'dummy'), array(),
'',
false);
359 $result = $node->_call(
'getRelativePathBelowSiteRoot', PATH_site);
360 $this->assertSame(
'/', $result);
366 public function getRelativePathBelowSiteRootReturnsSubPath()
369 $node = $this->getAccessibleMock(\TYPO3\CMS\Install\FolderStructure\AbstractNode::class, array(
'dummy'), array(),
'',
false);
370 $result = $node->_call(
'getRelativePathBelowSiteRoot', PATH_site .
'foo/bar');
371 $this->assertSame(
'/foo/bar', $result);