TYPO3 CMS  TYPO3_6-2
AbstractNodeTest.php
Go to the documentation of this file.
1 <?php
3 
21 
25  protected $testNodesToDelete = array();
26 
30  public function tearDown() {
31  foreach($this->testNodesToDelete as $node) {
32  if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($node, PATH_site . 'typo3temp/')) {
34  }
35  }
36  parent::tearDown();
37  }
38 
42  public function getNameReturnsSetName() {
44  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\AbstractNode', array('dummy'), array(), '', FALSE);
45  $name = $this->getUniqueId('name_');
46  $node->_set('name', $name);
47  $this->assertSame($name, $node->getName());
48  }
49 
53  public function getTargetPermissionReturnsSetTargetPermission() {
55  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\AbstractNode', array('dummy'), array(), '', FALSE);
56  $permission = '1234';
57  $node->_set('targetPermission', $permission);
58  $this->assertSame($permission, $node->_call('getTargetPermission'));
59  }
60 
64  public function getChildrenReturnsSetChildren() {
66  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\AbstractNode', array('dummy'), array(), '', FALSE);
67  $children = array('1234');
68  $node->_set('children', $children);
69  $this->assertSame($children, $node->_call('getChildren'));
70  }
71 
75  public function getParentReturnsSetParent() {
77  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\AbstractNode', array('dummy'), array(), '', FALSE);
78  $parent = $this->getMock('TYPO3\CMS\Install\FolderStructure\RootNodeInterface', array(), array(), '', FALSE);
79  $node->_set('parent', $parent);
80  $this->assertSame($parent, $node->_call('getParent'));
81  }
82 
86  public function getAbsolutePathCallsParentForPathAndAppendsOwnName() {
88  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\AbstractNode', array('dummy'), array(), '', FALSE);
89  $parent = $this->getMock('TYPO3\CMS\Install\FolderStructure\RootNodeInterface', array(), array(), '', FALSE);
90  $parentPath = '/foo/bar';
91  $parent->expects($this->once())->method('getAbsolutePath')->will($this->returnValue($parentPath));
92  $name = $this->getUniqueId('test_');
93  $node->_set('parent', $parent);
94  $node->_set('name', $name);
95  $this->assertSame($parentPath . '/' . $name, $node->getAbsolutePath());
96  }
97 
101  public function isWritableCallsParentIsWritable() {
103  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\AbstractNode', array('dummy'), array(), '', FALSE);
104  $parentMock = $this->getMock('TYPO3\\CMS\\Install\\FolderStructure\\NodeInterface', array(), array(), '', FALSE);
105  $parentMock->expects($this->once())->method('isWritable');
106  $node->_set('parent', $parentMock);
107  $node->isWritable();
108  }
109 
113  public function isWritableReturnsWritableStatusOfParent() {
115  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\AbstractNode', array('dummy'), array(), '', FALSE);
116  $parentMock = $this->getMock('TYPO3\\CMS\\Install\\FolderStructure\\NodeInterface', array(), array(), '', FALSE);
117  $parentMock->expects($this->once())->method('isWritable')->will($this->returnValue(TRUE));
118  $node->_set('parent', $parentMock);
119  $this->assertTrue($node->isWritable());
120  }
121 
125  public function existsReturnsTrueIfNodeExists() {
127  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\AbstractNode', array('getAbsolutePath'), array(), '', FALSE);
128  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_');
130  $this->testNodesToDelete[] = $path;
131  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
132  $this->assertTrue($node->_call('exists'));
133  }
134 
138  public function existsReturnsTrueIfIsLinkAndTargetIsDead() {
139  if (TYPO3_OS === 'WIN') {
140  $this->markTestSkipped('Test not available on Windows OS.');
141  }
143  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\AbstractNode', array('getAbsolutePath'), array(), '', FALSE);
144  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('link_');
145  $target = PATH_site . 'typo3temp/' . $this->getUniqueId('notExists_');
146  symlink($target, $path);
147  $this->testNodesToDelete[] = $path;
148  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
149  $this->assertTrue($node->_call('exists'));
150  }
151 
155  public function existsReturnsFalseIfNodeNotExists() {
157  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\AbstractNode', array('getAbsolutePath'), array(), '', FALSE);
158  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_');
159  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
160  $this->assertFalse($node->_call('exists'));
161  }
162 
167  public function fixPermissionThrowsExceptionIfPermissionAreAlreadyCorrect() {
169  $node = $this->getAccessibleMock(
170  'TYPO3\\CMS\\Install\\FolderStructure\\AbstractNode',
171  array('isPermissionCorrect', 'getAbsolutePath'),
172  array(),
173  '',
174  FALSE
175  );
176  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue(''));
177  $node->expects($this->once())->method('isPermissionCorrect')->will($this->returnValue(TRUE));
178  $node->_call('fixPermission');
179  }
180 
184  public function fixPermissionReturnsNoticeStatusIfPermissionCanNotBeChanged() {
185  if (TYPO3_OS === 'WIN') {
186  $this->markTestSkipped('Test not available on Windows OS.');
187  }
188  if (function_exists('posix_getegid') && posix_getegid() === 0) {
189  $this->markTestSkipped('Test skipped if run on linux as root');
190  }
192  $node = $this->getAccessibleMock(
193  'TYPO3\\CMS\\Install\\FolderStructure\\AbstractNode',
194  array('isPermissionCorrect', 'getRelativePathBelowSiteRoot', 'getAbsolutePath'),
195  array(),
196  '',
197  FALSE
198  );
199  $node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue(''));
200  $node->expects($this->once())->method('isPermissionCorrect')->will($this->returnValue(FALSE));
201  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('root_');
202  mkdir($path);
203  $subPath = $path . '/' . $this->getUniqueId('dir_');
204  mkdir($subPath);
205  chmod($path, 02000);
206  $this->testNodesToDelete[] = $path;
207  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($subPath));
208  $node->_set('targetPermission', '2770');
209  $this->assertInstanceOf('TYPO3\\CMS\\Install\\Status\\NoticeStatus', $node->_call('fixPermission'));
210  chmod($path, 02770);
211  }
212 
216  public function fixPermissionReturnsNoticeStatusIfPermissionsCanNotBeChanged() {
217  if (TYPO3_OS === 'WIN') {
218  $this->markTestSkipped('Test not available on Windows OS.');
219  }
220  if (function_exists('posix_getegid') && posix_getegid() === 0) {
221  $this->markTestSkipped('Test skipped if run on linux as root');
222  }
224  $node = $this->getAccessibleMock(
225  'TYPO3\\CMS\\Install\\FolderStructure\\AbstractNode',
226  array('isPermissionCorrect', 'getRelativePathBelowSiteRoot', 'getAbsolutePath'),
227  array(),
228  '',
229  FALSE
230  );
231  $node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue(''));
232  $node->expects($this->once())->method('isPermissionCorrect')->will($this->returnValue(FALSE));
233  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('root_');
234  mkdir($path);
235  $subPath = $path . '/' . $this->getUniqueId('dir_');
236  mkdir($subPath);
237  chmod($path, 02000);
238  $this->testNodesToDelete[] = $path;
239  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($subPath));
240  $node->_set('targetPermission', '2770');
241  $this->assertInstanceOf('TYPO3\\CMS\\Install\\Status\\NoticeStatus', $node->_call('fixPermission'));
242  chmod($path, 02770);
243  }
244 
248  public function fixPermissionReturnsOkStatusIfPermissionCanBeFixedAndSetsPermissionToCorrectValue() {
249  if (TYPO3_OS === 'WIN') {
250  $this->markTestSkipped('Test not available on Windows OS.');
251  }
253  $node = $this->getAccessibleMock(
254  'TYPO3\\CMS\\Install\\FolderStructure\\AbstractNode',
255  array('isPermissionCorrect', 'getRelativePathBelowSiteRoot', 'getAbsolutePath'),
256  array(),
257  '',
258  FALSE
259  );
260  $node->expects($this->any())->method('getRelativePathBelowSiteRoot')->will($this->returnValue(''));
261  $node->expects($this->once())->method('isPermissionCorrect')->will($this->returnValue(FALSE));
262  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('root_');
263  mkdir($path);
264  $subPath = $path . '/' . $this->getUniqueId('dir_');
265  mkdir($subPath);
266  chmod($path, 02770);
267  $this->testNodesToDelete[] = $path;
268  $node->_set('targetPermission', '2770');
269  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($subPath));
270  $this->assertInstanceOf('TYPO3\\CMS\\Install\\Status\\OkStatus', $node->_call('fixPermission'));
271  $resultDirectoryPermissions = substr(decoct(fileperms($subPath)), 1);
272  $this->assertSame('2770', $resultDirectoryPermissions);
273  }
274 
278  public function isPermissionCorrectReturnsTrueOnWindowsOs() {
280  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\AbstractNode', array('isWindowsOs'), array(), '', FALSE);
281  $node->expects($this->once())->method('isWindowsOs')->will($this->returnValue(TRUE));
282  $this->assertTrue($node->_call('isPermissionCorrect'));
283  }
284 
288  public function isPermissionCorrectReturnsFalseIfTargetPermissionAndCurrentPermissionAreNotIdentical() {
290  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\AbstractNode', array('isWindowsOs', 'getCurrentPermission'), array(), '', FALSE);
291  $node->expects($this->any())->method('isWindowsOs')->will($this->returnValue(FALSE));
292  $node->expects($this->any())->method('getCurrentPermission')->will($this->returnValue('foo'));
293  $node->_set('targetPermission', 'bar');
294  $this->assertFalse($node->_call('isPermissionCorrect'));
295  }
296 
300  public function getCurrentPermissionReturnsCurrentDirectoryPermission() {
301  if (TYPO3_OS === 'WIN') {
302  $this->markTestSkipped('Test not available on Windows OS.');
303  }
305  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\AbstractNode', array('getAbsolutePath'), array(), '', FALSE);
306  $path = PATH_site . 'typo3temp/' . $this->getUniqueId('dir_');
308  $this->testNodesToDelete[] = $path;
309  chmod($path, 02775);
310  clearstatcache();
311  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path));
312  $this->assertSame('2775', $node->_call('getCurrentPermission'));
313  }
314 
318  public function getCurrentPermissionReturnsCurrentFilePermission() {
319  if (TYPO3_OS === 'WIN') {
320  $this->markTestSkipped('Test not available on Windows OS.');
321  }
323  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\AbstractNode', array('getAbsolutePath'), array(), '', FALSE);
324  $file = PATH_site . 'typo3temp/' . $this->getUniqueId('file_');
325  touch($file);
326  $this->testNodesToDelete[] = $file;
327  chmod($file, 0770);
328  clearstatcache();
329  $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($file));
330  $this->assertSame('0770', $node->_call('getCurrentPermission'));
331  }
332 
337  public function getRelativePathBelowSiteRootThrowsExceptionIfGivenPathIsNotBelowPathSiteConstant() {
339  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\AbstractNode', array('dummy'), array(), '', FALSE);
340  $node->_call('getRelativePathBelowSiteRoot', '/tmp');
341  }
342 
346  public function getRelativePathCallsGetAbsolutePathIfPathIsNull() {
348  $node = $this->getAccessibleMock(
349  'TYPO3\\CMS\\Install\\FolderStructure\\AbstractNode',
350  array('getAbsolutePath'),
351  array(),
352  '',
353  FALSE
354  );
355  $node->expects($this->once())->method('getAbsolutePath')->will($this->returnValue(PATH_site));
356  $node->_call('getRelativePathBelowSiteRoot', NULL);
357  }
358 
362  public function getRelativePathBelowSiteRootReturnsSingleForwardSlashIfGivenPathEqualsPathSiteConstant() {
364  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\AbstractNode', array('dummy'), array(), '', FALSE);
365  $result = $node->_call('getRelativePathBelowSiteRoot', PATH_site);
366  $this->assertSame('/', $result);
367  }
368 
372  public function getRelativePathBelowSiteRootReturnsSubPath() {
374  $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\AbstractNode', array('dummy'), array(), '', FALSE);
375  $result = $node->_call('getRelativePathBelowSiteRoot', PATH_site . 'foo/bar');
376  $this->assertSame('/foo/bar', $result);
377  }
378 
379 }
static mkdir_deep($directory, $deepDirectory='')
static rmdir($path, $removeNonEmpty=FALSE)
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.