TYPO3 CMS  TYPO3_6-2
RootNodeTest.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 
43  public function constructorThrowsExceptionIfParentIsNotNull() {
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 
60  public function constructorThrowsExceptionIfAbsolutePathIsNotSet() {
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 
73  public function constructorThrowsExceptionIfAbsolutePathIsNotAbsoluteOnWindows() {
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 
90  public function constructorThrowsExceptionIfAbsolutePathIsNotAbsoluteOnUnix() {
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 
106  public function constructorSetsParentToNull() {
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 
123  public function getChildrenReturnsChildCreatedByConstructor() {
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 = $this->getUniqueId('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');
143  $child = $children[0];
144  $this->assertInstanceOf('TYPO3\\CMS\\install\\FolderStructure\\DirectoryNode', $child);
145  $this->assertSame($childName, $child->getName());
146  }
147 
151  public function constructorSetsTargetPermission() {
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 
170  public function constructorSetsName() {
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 = '/' . $this->getUniqueId('test_');
178  $node->__construct(array('name' => $name), NULL);
179  $this->assertSame($name, $node->getName());
180  }
181 
185  public function getStatusReturnsArrayWithOkStatusAndCallsOwnStatusMethods() {
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/' . $this->getUniqueId('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();
204  $status = $statusArray[0];
205  $this->assertInstanceOf('\TYPO3\CMS\Install\Status\OkStatus', $status);
206  }
207 
211  public function getStatusCallsGetChildrenStatusForStatus() {
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/' . $this->getUniqueId('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();
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 
241  public function getAbsolutePathReturnsGivenName() {
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 }
static rmdir($path, $removeNonEmpty=FALSE)
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)