Mercurial > hg > Members > shoshi > webvirt
comparison cake/tests/cases/libs/folder.test.php @ 0:261e66bd5a0c
hg init
author | Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 24 Jul 2011 21:08:31 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:261e66bd5a0c |
---|---|
1 <?php | |
2 /** | |
3 * FolderTest file | |
4 * | |
5 * PHP versions 4 and 5 | |
6 * | |
7 * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing> | |
8 * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) | |
9 * | |
10 * Licensed under The Open Group Test Suite License | |
11 * Redistributions of files must retain the above copyright notice. | |
12 * | |
13 * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) | |
14 * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests | |
15 * @package cake | |
16 * @subpackage cake.tests.cases.libs | |
17 * @since CakePHP(tm) v 1.2.0.4206 | |
18 * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License | |
19 */ | |
20 App::import('Core', 'File'); | |
21 | |
22 /** | |
23 * FolderTest class | |
24 * | |
25 * @package cake | |
26 * @subpackage cake.tests.cases.libs | |
27 */ | |
28 class FolderTest extends CakeTestCase { | |
29 | |
30 /** | |
31 * testBasic method | |
32 * | |
33 * @access public | |
34 * @return void | |
35 */ | |
36 function testBasic() { | |
37 $path = dirname(__FILE__); | |
38 $Folder =& new Folder($path); | |
39 | |
40 $result = $Folder->pwd(); | |
41 $this->assertEqual($result, $path); | |
42 | |
43 $result = Folder::addPathElement($path, 'test'); | |
44 $expected = $path . DS . 'test'; | |
45 $this->assertEqual($result, $expected); | |
46 | |
47 $result = $Folder->cd(ROOT); | |
48 $expected = ROOT; | |
49 $this->assertEqual($result, $expected); | |
50 | |
51 $result = $Folder->cd(ROOT . DS . 'non-existent'); | |
52 $this->assertFalse($result); | |
53 } | |
54 | |
55 /** | |
56 * testInPath method | |
57 * | |
58 * @access public | |
59 * @return void | |
60 */ | |
61 function testInPath() { | |
62 $path = dirname(dirname(__FILE__)); | |
63 $inside = dirname($path) . DS; | |
64 | |
65 $Folder =& new Folder($path); | |
66 | |
67 $result = $Folder->pwd(); | |
68 $this->assertEqual($result, $path); | |
69 | |
70 $result = Folder::isSlashTerm($inside); | |
71 $this->assertTrue($result); | |
72 | |
73 $result = $Folder->realpath('tests/'); | |
74 $this->assertEqual($result, $path . DS .'tests' . DS); | |
75 | |
76 $result = $Folder->inPath('tests' . DS); | |
77 $this->assertTrue($result); | |
78 | |
79 $result = $Folder->inPath(DS . 'non-existing' . $inside); | |
80 $this->assertFalse($result); | |
81 } | |
82 | |
83 /** | |
84 * test creation of single and mulitple paths. | |
85 * | |
86 * @return void | |
87 */ | |
88 function testCreation() { | |
89 $folder =& new Folder(TMP . 'tests'); | |
90 $result = $folder->create(TMP . 'tests' . DS . 'first' . DS . 'second' . DS . 'third'); | |
91 $this->assertTrue($result); | |
92 | |
93 rmdir(TMP . 'tests' . DS . 'first' . DS . 'second' . DS . 'third'); | |
94 rmdir(TMP . 'tests' . DS . 'first' . DS . 'second'); | |
95 rmdir(TMP . 'tests' . DS . 'first'); | |
96 | |
97 $folder =& new Folder(TMP . 'tests'); | |
98 $result = $folder->create(TMP . 'tests' . DS . 'first'); | |
99 $this->assertTrue($result); | |
100 rmdir(TMP . 'tests' . DS . 'first'); | |
101 } | |
102 | |
103 /** | |
104 * test that creation of folders with trailing ds works | |
105 * | |
106 * @return void | |
107 */ | |
108 function testCreateWithTrailingDs() { | |
109 $folder =& new Folder(TMP); | |
110 $path = TMP . 'tests' . DS . 'trailing' . DS . 'dir' . DS; | |
111 $result = $folder->create($path); | |
112 $this->assertTrue($result); | |
113 | |
114 $this->assertTrue(is_dir($path), 'Folder was not made'); | |
115 | |
116 $folder =& new Folder(TMP . 'tests' . DS . 'trailing'); | |
117 $this->assertTrue($folder->delete()); | |
118 } | |
119 | |
120 /** | |
121 * test recurisve directory create failure. | |
122 * | |
123 * @return void | |
124 */ | |
125 function testRecursiveCreateFailure() { | |
126 if ($this->skipIf(DS == '\\', 'Cant perform operations using permissions on windows. %s')) { | |
127 return; | |
128 } | |
129 $path = TMP . 'tests' . DS . 'one'; | |
130 mkdir($path); | |
131 chmod($path, '0444'); | |
132 | |
133 $this->expectError(); | |
134 | |
135 $folder =& new Folder($path); | |
136 $result = $folder->create($path . DS . 'two' . DS . 'three'); | |
137 $this->assertFalse($result); | |
138 | |
139 chmod($path, '0777'); | |
140 rmdir($path); | |
141 } | |
142 /** | |
143 * testOperations method | |
144 * | |
145 * @access public | |
146 * @return void | |
147 */ | |
148 function testOperations() { | |
149 $path = TEST_CAKE_CORE_INCLUDE_PATH . 'console' . DS . 'templates' . DS . 'skel'; | |
150 $Folder =& new Folder($path); | |
151 | |
152 $result = is_dir($Folder->pwd()); | |
153 $this->assertTrue($result); | |
154 | |
155 $new = TMP . 'test_folder_new'; | |
156 $result = $Folder->create($new); | |
157 $this->assertTrue($result); | |
158 | |
159 $copy = TMP . 'test_folder_copy'; | |
160 $result = $Folder->copy($copy); | |
161 $this->assertTrue($result); | |
162 | |
163 $copy = TMP . 'test_folder_copy'; | |
164 $result = $Folder->copy($copy); | |
165 $this->assertTrue($result); | |
166 | |
167 $copy = TMP . 'test_folder_copy'; | |
168 $result = $Folder->chmod($copy, 0755, false); | |
169 $this->assertTrue($result); | |
170 | |
171 $result = $Folder->cd($copy); | |
172 $this->assertTrue($result); | |
173 | |
174 $mv = TMP . 'test_folder_mv'; | |
175 $result = $Folder->move($mv); | |
176 $this->assertTrue($result); | |
177 | |
178 $mv = TMP . 'test_folder_mv_2'; | |
179 $result = $Folder->move($mv); | |
180 $this->assertTrue($result); | |
181 | |
182 $result = $Folder->delete($new); | |
183 $this->assertTrue($result); | |
184 | |
185 $result = $Folder->delete($mv); | |
186 $this->assertTrue($result); | |
187 | |
188 $result = $Folder->delete($mv); | |
189 $this->assertTrue($result); | |
190 | |
191 $new = APP . 'index.php'; | |
192 $result = $Folder->create($new); | |
193 $this->assertFalse($result); | |
194 | |
195 $expected = $new . ' is a file'; | |
196 $result = array_pop($Folder->errors()); | |
197 $this->assertEqual($result, $expected); | |
198 | |
199 $new = TMP . 'test_folder_new'; | |
200 $result = $Folder->create($new); | |
201 $this->assertTrue($result); | |
202 | |
203 $result = $Folder->cd($new); | |
204 $this->assertTrue($result); | |
205 | |
206 $result = $Folder->delete(); | |
207 $this->assertTrue($result); | |
208 | |
209 $Folder =& new Folder('non-existent'); | |
210 $result = $Folder->pwd(); | |
211 $this->assertNull($result); | |
212 } | |
213 | |
214 /** | |
215 * testChmod method | |
216 * | |
217 * @return void | |
218 * @access public | |
219 */ | |
220 function testChmod() { | |
221 $this->skipIf(DIRECTORY_SEPARATOR === '\\', '%s Folder permissions tests not supported on Windows'); | |
222 | |
223 $path = TEST_CAKE_CORE_INCLUDE_PATH . 'console' . DS . 'templates' . DS . 'skel'; | |
224 $Folder =& new Folder($path); | |
225 | |
226 $subdir = 'test_folder_new'; | |
227 $new = TMP . $subdir; | |
228 | |
229 $this->assertTrue($Folder->create($new)); | |
230 $this->assertTrue($Folder->create($new . DS . 'test1')); | |
231 $this->assertTrue($Folder->create($new . DS . 'test2')); | |
232 | |
233 $filePath = $new . DS . 'test1.php'; | |
234 $File =& new File($filePath); | |
235 $this->assertTrue($File->create()); | |
236 $copy = TMP . 'test_folder_copy'; | |
237 | |
238 $this->assertTrue($Folder->chmod($new, 0777, true)); | |
239 $this->assertEqual($File->perms(), '0777'); | |
240 | |
241 $Folder->delete($new); | |
242 } | |
243 | |
244 /** | |
245 * testRealPathForWebroot method | |
246 * | |
247 * @access public | |
248 * @return void | |
249 */ | |
250 function testRealPathForWebroot() { | |
251 $Folder = new Folder('files/'); | |
252 $this->assertEqual(realpath('files/'), $Folder->path); | |
253 } | |
254 | |
255 /** | |
256 * testZeroAsDirectory method | |
257 * | |
258 * @access public | |
259 * @return void | |
260 */ | |
261 function testZeroAsDirectory() { | |
262 $Folder =& new Folder(TMP); | |
263 $new = TMP . '0'; | |
264 $this->assertTrue($Folder->create($new)); | |
265 | |
266 $result = $Folder->read(true, true); | |
267 $expected = array('0', 'cache', 'logs', 'sessions', 'tests'); | |
268 $this->assertEqual($expected, $result[0]); | |
269 | |
270 $result = $Folder->read(true, array('.', '..', 'logs', '.svn')); | |
271 $expected = array('0', 'cache', 'sessions', 'tests'); | |
272 $this->assertEqual($expected, $result[0]); | |
273 | |
274 $result = $Folder->delete($new); | |
275 $this->assertTrue($result); | |
276 } | |
277 | |
278 /** | |
279 * test Adding path elements to a path | |
280 * | |
281 * @return void | |
282 */ | |
283 function testAddPathElement() { | |
284 $result = Folder::addPathElement(DS . 'some' . DS . 'dir', 'another_path'); | |
285 $this->assertEqual($result, DS . 'some' . DS . 'dir' . DS . 'another_path'); | |
286 | |
287 $result = Folder::addPathElement(DS . 'some' . DS . 'dir' . DS, 'another_path'); | |
288 $this->assertEqual($result, DS . 'some' . DS . 'dir' . DS . 'another_path'); | |
289 } | |
290 /** | |
291 * testFolderRead method | |
292 * | |
293 * @access public | |
294 * @return void | |
295 */ | |
296 function testFolderRead() { | |
297 $Folder =& new Folder(TMP); | |
298 | |
299 $expected = array('cache', 'logs', 'sessions', 'tests'); | |
300 $result = $Folder->read(true, true); | |
301 $this->assertEqual($result[0], $expected); | |
302 | |
303 $Folder->path = TMP . DS . 'non-existent'; | |
304 $expected = array(array(), array()); | |
305 $result = $Folder->read(true, true); | |
306 $this->assertEqual($result, $expected); | |
307 } | |
308 | |
309 /** | |
310 * testFolderTree method | |
311 * | |
312 * @access public | |
313 * @return void | |
314 */ | |
315 function testFolderTree() { | |
316 $Folder =& new Folder(); | |
317 $expected = array( | |
318 array( | |
319 TEST_CAKE_CORE_INCLUDE_PATH . 'config', | |
320 TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode', | |
321 TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' | |
322 ), | |
323 array( | |
324 TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php', | |
325 TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'paths.php', | |
326 TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0080_00ff.php', | |
327 TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0100_017f.php', | |
328 TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0180_024F.php', | |
329 TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0250_02af.php', | |
330 TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0370_03ff.php', | |
331 TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0400_04ff.php', | |
332 TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0500_052f.php', | |
333 TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0530_058f.php', | |
334 TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '1e00_1eff.php', | |
335 TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '1f00_1fff.php', | |
336 TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '2100_214f.php', | |
337 TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '2150_218f.php', | |
338 TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '2460_24ff.php', | |
339 TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '2c00_2c5f.php', | |
340 TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '2c60_2c7f.php', | |
341 TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '2c80_2cff.php', | |
342 TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . 'ff00_ffef.php' | |
343 ) | |
344 ); | |
345 | |
346 $result = $Folder->tree(TEST_CAKE_CORE_INCLUDE_PATH . 'config', false); | |
347 $this->assertIdentical(array_diff($expected[0], $result[0]), array()); | |
348 $this->assertIdentical(array_diff($result[0], $expected[0]), array()); | |
349 | |
350 $result = $Folder->tree(TEST_CAKE_CORE_INCLUDE_PATH . 'config', false, 'dir'); | |
351 $this->assertIdentical(array_diff($expected[0], $result), array()); | |
352 $this->assertIdentical(array_diff($result, $expected[0]), array()); | |
353 | |
354 $result = $Folder->tree(TEST_CAKE_CORE_INCLUDE_PATH . 'config', false, 'files'); | |
355 $this->assertIdentical(array_diff($expected[1], $result), array()); | |
356 $this->assertIdentical(array_diff($result, $expected[1]), array()); | |
357 } | |
358 | |
359 /** | |
360 * testWindowsPath method | |
361 * | |
362 * @access public | |
363 * @return void | |
364 */ | |
365 function testWindowsPath() { | |
366 $this->assertFalse(Folder::isWindowsPath('0:\\cake\\is\\awesome')); | |
367 $this->assertTrue(Folder::isWindowsPath('C:\\cake\\is\\awesome')); | |
368 $this->assertTrue(Folder::isWindowsPath('d:\\cake\\is\\awesome')); | |
369 $this->assertTrue(Folder::isWindowsPath('\\\\vmware-host\\Shared Folders\\file')); | |
370 } | |
371 | |
372 /** | |
373 * testIsAbsolute method | |
374 * | |
375 * @access public | |
376 * @return void | |
377 */ | |
378 function testIsAbsolute() { | |
379 $this->assertFalse(Folder::isAbsolute('path/to/file')); | |
380 $this->assertFalse(Folder::isAbsolute('cake/')); | |
381 $this->assertFalse(Folder::isAbsolute('path\\to\\file')); | |
382 $this->assertFalse(Folder::isAbsolute('0:\\path\\to\\file')); | |
383 $this->assertFalse(Folder::isAbsolute('\\path/to/file')); | |
384 $this->assertFalse(Folder::isAbsolute('\\path\\to\\file')); | |
385 | |
386 $this->assertTrue(Folder::isAbsolute('/usr/local')); | |
387 $this->assertTrue(Folder::isAbsolute('//path/to/file')); | |
388 $this->assertTrue(Folder::isAbsolute('C:\\cake')); | |
389 $this->assertTrue(Folder::isAbsolute('C:\\path\\to\\file')); | |
390 $this->assertTrue(Folder::isAbsolute('d:\\path\\to\\file')); | |
391 $this->assertTrue(Folder::isAbsolute('\\\\vmware-host\\Shared Folders\\file')); | |
392 } | |
393 | |
394 /** | |
395 * testIsSlashTerm method | |
396 * | |
397 * @access public | |
398 * @return void | |
399 */ | |
400 function testIsSlashTerm() { | |
401 $this->assertFalse(Folder::isSlashTerm('cake')); | |
402 | |
403 $this->assertTrue(Folder::isSlashTerm('C:\\cake\\')); | |
404 $this->assertTrue(Folder::isSlashTerm('/usr/local/')); | |
405 } | |
406 | |
407 /** | |
408 * testStatic method | |
409 * | |
410 * @access public | |
411 * @return void | |
412 */ | |
413 function testSlashTerm() { | |
414 $result = Folder::slashTerm('/path/to/file'); | |
415 $this->assertEqual($result, '/path/to/file/'); | |
416 } | |
417 | |
418 /** | |
419 * testNormalizePath method | |
420 * | |
421 * @access public | |
422 * @return void | |
423 */ | |
424 function testNormalizePath() { | |
425 $path = '/path/to/file'; | |
426 $result = Folder::normalizePath($path); | |
427 $this->assertEqual($result, '/'); | |
428 | |
429 $path = '\\path\\\to\\\file'; | |
430 $result = Folder::normalizePath($path); | |
431 $this->assertEqual($result, '/'); | |
432 | |
433 $path = 'C:\\path\\to\\file'; | |
434 $result = Folder::normalizePath($path); | |
435 $this->assertEqual($result, '\\'); | |
436 } | |
437 | |
438 /** | |
439 * correctSlashFor method | |
440 * | |
441 * @access public | |
442 * @return void | |
443 */ | |
444 function testCorrectSlashFor() { | |
445 $path = '/path/to/file'; | |
446 $result = Folder::correctSlashFor($path); | |
447 $this->assertEqual($result, '/'); | |
448 | |
449 $path = '\\path\\to\\file'; | |
450 $result = Folder::correctSlashFor($path); | |
451 $this->assertEqual($result, '/'); | |
452 | |
453 $path = 'C:\\path\to\\file'; | |
454 $result = Folder::correctSlashFor($path); | |
455 $this->assertEqual($result, '\\'); | |
456 } | |
457 | |
458 /** | |
459 * testInCakePath method | |
460 * | |
461 * @access public | |
462 * @return void | |
463 */ | |
464 function testInCakePath() { | |
465 $Folder =& new Folder(); | |
466 $Folder->cd(ROOT); | |
467 $path = 'C:\\path\\to\\file'; | |
468 $result = $Folder->inCakePath($path); | |
469 $this->assertFalse($result); | |
470 | |
471 $path = ROOT; | |
472 $Folder->cd(ROOT); | |
473 $result = $Folder->inCakePath($path); | |
474 $this->assertFalse($result); | |
475 | |
476 // WHY DOES THIS FAIL ?? | |
477 $path = DS . 'cake' . DS . 'config'; | |
478 $Folder->cd(ROOT . DS . 'cake' . DS . 'config'); | |
479 $result = $Folder->inCakePath($path); | |
480 $this->assertTrue($result); | |
481 } | |
482 | |
483 /** | |
484 * testFind method | |
485 * | |
486 * @access public | |
487 * @return void | |
488 */ | |
489 function testFind() { | |
490 $Folder =& new Folder(); | |
491 $Folder->cd(TEST_CAKE_CORE_INCLUDE_PATH . 'config'); | |
492 $result = $Folder->find(); | |
493 $expected = array('config.php', 'paths.php'); | |
494 $this->assertIdentical(array_diff($expected, $result), array()); | |
495 $this->assertIdentical(array_diff($result, $expected), array()); | |
496 | |
497 $result = $Folder->find('.*', true); | |
498 $expected = array('config.php', 'paths.php'); | |
499 $this->assertIdentical($result, $expected); | |
500 | |
501 $result = $Folder->find('.*\.php'); | |
502 $expected = array('config.php', 'paths.php'); | |
503 $this->assertIdentical(array_diff($expected, $result), array()); | |
504 $this->assertIdentical(array_diff($result, $expected), array()); | |
505 | |
506 $result = $Folder->find('.*\.php', true); | |
507 $expected = array('config.php', 'paths.php'); | |
508 $this->assertIdentical($result, $expected); | |
509 | |
510 $result = $Folder->find('.*ig\.php'); | |
511 $expected = array('config.php'); | |
512 $this->assertIdentical($result, $expected); | |
513 | |
514 $result = $Folder->find('paths\.php'); | |
515 $expected = array('paths.php'); | |
516 $this->assertIdentical($result, $expected); | |
517 | |
518 $Folder->cd(TMP); | |
519 $file = new File($Folder->pwd() . DS . 'paths.php', true); | |
520 $Folder->create($Folder->pwd() . DS . 'testme'); | |
521 $Folder->cd('testme'); | |
522 $result = $Folder->find('paths\.php'); | |
523 $expected = array(); | |
524 $this->assertIdentical($result, $expected); | |
525 | |
526 $Folder->cd($Folder->pwd() . '/..'); | |
527 $result = $Folder->find('paths\.php'); | |
528 $expected = array('paths.php'); | |
529 $this->assertIdentical($result, $expected); | |
530 | |
531 $Folder->cd(TMP); | |
532 $Folder->delete($Folder->pwd() . DS . 'testme'); | |
533 $file->delete(); | |
534 } | |
535 | |
536 /** | |
537 * testFindRecursive method | |
538 * | |
539 * @access public | |
540 * @return void | |
541 */ | |
542 function testFindRecursive() { | |
543 $Folder =& new Folder(); | |
544 $Folder->cd(TEST_CAKE_CORE_INCLUDE_PATH); | |
545 $result = $Folder->findRecursive('(config|paths)\.php'); | |
546 $expected = array( | |
547 TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php', | |
548 TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'paths.php' | |
549 ); | |
550 $this->assertIdentical(array_diff($expected, $result), array()); | |
551 $this->assertIdentical(array_diff($result, $expected), array()); | |
552 | |
553 $result = $Folder->findRecursive('(config|paths)\.php', true); | |
554 $expected = array( | |
555 TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php', | |
556 TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'paths.php' | |
557 ); | |
558 $this->assertIdentical($result, $expected); | |
559 | |
560 $Folder->cd(TMP); | |
561 $Folder->create($Folder->pwd() . DS . 'testme'); | |
562 $Folder->cd('testme'); | |
563 $File =& new File($Folder->pwd() . DS . 'paths.php'); | |
564 $File->create(); | |
565 $Folder->cd(TMP . 'sessions'); | |
566 $result = $Folder->findRecursive('paths\.php'); | |
567 $expected = array(); | |
568 $this->assertIdentical($result, $expected); | |
569 | |
570 $Folder->cd(TMP . 'testme'); | |
571 $File =& new File($Folder->pwd() . DS . 'my.php'); | |
572 $File->create(); | |
573 $Folder->cd($Folder->pwd() . '/../..'); | |
574 | |
575 $result = $Folder->findRecursive('(paths|my)\.php'); | |
576 $expected = array( | |
577 TMP . 'testme' . DS . 'my.php', | |
578 TMP . 'testme' . DS . 'paths.php' | |
579 ); | |
580 $this->assertIdentical(array_diff($expected, $result), array()); | |
581 $this->assertIdentical(array_diff($result, $expected), array()); | |
582 | |
583 $result = $Folder->findRecursive('(paths|my)\.php', true); | |
584 $expected = array( | |
585 TMP . 'testme' . DS . 'my.php', | |
586 TMP . 'testme' . DS . 'paths.php' | |
587 ); | |
588 $this->assertIdentical($result, $expected); | |
589 | |
590 $Folder->cd(TEST_CAKE_CORE_INCLUDE_PATH . 'config'); | |
591 $Folder->cd(TMP); | |
592 $Folder->delete($Folder->pwd() . DS . 'testme'); | |
593 $File->delete(); | |
594 } | |
595 | |
596 /** | |
597 * testConstructWithNonExistantPath method | |
598 * | |
599 * @access public | |
600 * @return void | |
601 */ | |
602 function testConstructWithNonExistantPath() { | |
603 $Folder =& new Folder(TMP . 'config_non_existant', true); | |
604 $this->assertTrue(is_dir(TMP . 'config_non_existant')); | |
605 $Folder->cd(TMP); | |
606 $Folder->delete($Folder->pwd() . 'config_non_existant'); | |
607 } | |
608 | |
609 /** | |
610 * testDirSize method | |
611 * | |
612 * @access public | |
613 * @return void | |
614 */ | |
615 function testDirSize() { | |
616 $Folder =& new Folder(TMP . 'config_non_existant', true); | |
617 $this->assertEqual($Folder->dirSize(), 0); | |
618 | |
619 $File =& new File($Folder->pwd() . DS . 'my.php', true, 0777); | |
620 $File->create(); | |
621 $File->write('something here'); | |
622 $File->close(); | |
623 $this->assertEqual($Folder->dirSize(), 14); | |
624 | |
625 $Folder->cd(TMP); | |
626 $Folder->delete($Folder->pwd() . 'config_non_existant'); | |
627 } | |
628 | |
629 /** | |
630 * testDelete method | |
631 * | |
632 * @access public | |
633 * @return void | |
634 */ | |
635 function testDelete() { | |
636 $path = TMP . 'folder_delete_test'; | |
637 $Folder =& new Folder($path, true); | |
638 touch(TMP . 'folder_delete_test' . DS . 'file1'); | |
639 touch(TMP . 'folder_delete_test' . DS . 'file2'); | |
640 | |
641 $return = $Folder->delete(); | |
642 $this->assertTrue($return); | |
643 | |
644 $messages = $Folder->messages(); | |
645 $errors = $Folder->errors(); | |
646 $this->assertEqual($errors, array()); | |
647 | |
648 $expected = array( | |
649 $path . ' created', | |
650 $path . DS . 'file1 removed', | |
651 $path . DS . 'file2 removed', | |
652 $path . ' removed' | |
653 ); | |
654 $this->assertEqual($expected, $messages); | |
655 } | |
656 | |
657 /** | |
658 * testCopy method | |
659 * | |
660 * Verify that directories and files are copied recursively | |
661 * even if the destination directory already exists. | |
662 * Subdirectories existing in both destination and source directory | |
663 * are skipped and not merged or overwritten. | |
664 * | |
665 * @return void | |
666 * @access public | |
667 * @link https://trac.cakephp.org/ticket/6259 | |
668 */ | |
669 function testCopy() { | |
670 $path = TMP . 'folder_test'; | |
671 $folder1 = $path . DS . 'folder1'; | |
672 $folder2 = $folder1 . DS . 'folder2'; | |
673 $folder3 = $path . DS . 'folder3'; | |
674 $file1 = $folder1 . DS . 'file1.php'; | |
675 $file2 = $folder2 . DS . 'file2.php'; | |
676 | |
677 new Folder($path, true); | |
678 new Folder($folder1, true); | |
679 new Folder($folder2, true); | |
680 new Folder($folder3, true); | |
681 touch($file1); | |
682 touch($file2); | |
683 | |
684 $Folder =& new Folder($folder1); | |
685 $result = $Folder->copy($folder3); | |
686 $this->assertTrue($result); | |
687 $this->assertTrue(file_exists($folder3 . DS . 'file1.php')); | |
688 $this->assertTrue(file_exists($folder3 . DS . 'folder2' . DS . 'file2.php')); | |
689 | |
690 $Folder =& new Folder($folder3); | |
691 $Folder->delete(); | |
692 | |
693 $Folder =& new Folder($folder1); | |
694 $result = $Folder->copy($folder3); | |
695 $this->assertTrue($result); | |
696 $this->assertTrue(file_exists($folder3 . DS . 'file1.php')); | |
697 $this->assertTrue(file_exists($folder3 . DS . 'folder2' . DS . 'file2.php')); | |
698 | |
699 $Folder =& new Folder($folder3); | |
700 $Folder->delete(); | |
701 | |
702 new Folder($folder3, true); | |
703 new Folder($folder3 . DS . 'folder2', true); | |
704 file_put_contents($folder3 . DS . 'folder2' . DS . 'file2.php', 'untouched'); | |
705 | |
706 $Folder =& new Folder($folder1); | |
707 $result = $Folder->copy($folder3); | |
708 $this->assertTrue($result); | |
709 $this->assertTrue(file_exists($folder3 . DS . 'file1.php')); | |
710 $this->assertEqual(file_get_contents($folder3 . DS . 'folder2' . DS . 'file2.php'), 'untouched'); | |
711 | |
712 $Folder =& new Folder($path); | |
713 $Folder->delete(); | |
714 } | |
715 | |
716 /** | |
717 * testMove method | |
718 * | |
719 * Verify that directories and files are moved recursively | |
720 * even if the destination directory already exists. | |
721 * Subdirectories existing in both destination and source directory | |
722 * are skipped and not merged or overwritten. | |
723 * | |
724 * @return void | |
725 * @access public | |
726 * @link https://trac.cakephp.org/ticket/6259 | |
727 */ | |
728 function testMove() { | |
729 $path = TMP . 'folder_test'; | |
730 $folder1 = $path . DS . 'folder1'; | |
731 $folder2 = $folder1 . DS . 'folder2'; | |
732 $folder3 = $path . DS . 'folder3'; | |
733 $file1 = $folder1 . DS . 'file1.php'; | |
734 $file2 = $folder2 . DS . 'file2.php'; | |
735 | |
736 new Folder($path, true); | |
737 new Folder($folder1, true); | |
738 new Folder($folder2, true); | |
739 new Folder($folder3, true); | |
740 touch($file1); | |
741 touch($file2); | |
742 | |
743 $Folder =& new Folder($folder1); | |
744 $result = $Folder->move($folder3); | |
745 $this->assertTrue($result); | |
746 $this->assertTrue(file_exists($folder3 . DS . 'file1.php')); | |
747 $this->assertTrue(is_dir($folder3 . DS . 'folder2')); | |
748 $this->assertTrue(file_exists($folder3 . DS . 'folder2' . DS . 'file2.php')); | |
749 $this->assertFalse(file_exists($file1)); | |
750 $this->assertFalse(file_exists($folder2)); | |
751 $this->assertFalse(file_exists($file2)); | |
752 | |
753 $Folder =& new Folder($folder3); | |
754 $Folder->delete(); | |
755 | |
756 new Folder($folder1, true); | |
757 new Folder($folder2, true); | |
758 touch($file1); | |
759 touch($file2); | |
760 | |
761 $Folder =& new Folder($folder1); | |
762 $result = $Folder->move($folder3); | |
763 $this->assertTrue($result); | |
764 $this->assertTrue(file_exists($folder3 . DS . 'file1.php')); | |
765 $this->assertTrue(is_dir($folder3 . DS . 'folder2')); | |
766 $this->assertTrue(file_exists($folder3 . DS . 'folder2' . DS . 'file2.php')); | |
767 $this->assertFalse(file_exists($file1)); | |
768 $this->assertFalse(file_exists($folder2)); | |
769 $this->assertFalse(file_exists($file2)); | |
770 | |
771 $Folder =& new Folder($folder3); | |
772 $Folder->delete(); | |
773 | |
774 new Folder($folder1, true); | |
775 new Folder($folder2, true); | |
776 new Folder($folder3, true); | |
777 new Folder($folder3 . DS . 'folder2', true); | |
778 touch($file1); | |
779 touch($file2); | |
780 file_put_contents($folder3 . DS . 'folder2' . DS . 'file2.php', 'untouched'); | |
781 | |
782 $Folder =& new Folder($folder1); | |
783 $result = $Folder->move($folder3); | |
784 $this->assertTrue($result); | |
785 $this->assertTrue(file_exists($folder3 . DS . 'file1.php')); | |
786 $this->assertEqual(file_get_contents($folder3 . DS . 'folder2' . DS . 'file2.php'), 'untouched'); | |
787 $this->assertFalse(file_exists($file1)); | |
788 $this->assertFalse(file_exists($folder2)); | |
789 $this->assertFalse(file_exists($file2)); | |
790 | |
791 $Folder =& new Folder($path); | |
792 $Folder->delete(); | |
793 } | |
794 } |