PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/cake/tests/cases/libs/folder.test.php

https://github.com/msadouni/cakephp2x
PHP | 736 lines | 637 code | 37 blank | 62 comment | 0 complexity | 632f0da3dac32550e15f073d536a5600 MD5 | raw file
  1. <?php
  2. /**
  3. * FolderTest file
  4. *
  5. * Long description for file
  6. *
  7. * PHP Version 5.x
  8. *
  9. * CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
  10. * Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. *
  12. * Licensed under The Open Group Test Suite License
  13. * Redistributions of files must retain the above copyright notice.
  14. *
  15. * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
  16. * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
  17. * @package cake
  18. * @subpackage cake.tests.cases.libs
  19. * @since CakePHP(tm) v 1.2.0.4206
  20. * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
  21. */
  22. App::import('Core', 'File');
  23. /**
  24. * FolderTest class
  25. *
  26. * @package cake
  27. * @subpackage cake.tests.cases.libs
  28. */
  29. class FolderTest extends CakeTestCase {
  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. $result = $Folder->pwd();
  40. $this->assertEqual($result, $path);
  41. $result = Folder::addPathElement($path, 'test');
  42. $expected = $path . DS . 'test';
  43. $this->assertEqual($result, $expected);
  44. $result = $Folder->cd(ROOT);
  45. $expected = ROOT;
  46. $this->assertEqual($result, $expected);
  47. $result = $Folder->cd(ROOT . DS . 'non-existent');
  48. $this->assertFalse($result);
  49. }
  50. /**
  51. * testInPath method
  52. *
  53. * @access public
  54. * @return void
  55. */
  56. function testInPath() {
  57. $path = dirname(dirname(__FILE__));
  58. $inside = dirname($path) . DS;
  59. $Folder = new Folder($path);
  60. $result = $Folder->pwd();
  61. $this->assertEqual($result, $path);
  62. $result = Folder::isSlashTerm($inside);
  63. $this->assertTrue($result);
  64. $result = $Folder->realpath('tests/');
  65. $this->assertEqual($result, $path . DS .'tests' . DS);
  66. $result = $Folder->inPath('tests' . DS);
  67. $this->assertTrue($result);
  68. $result = $Folder->inPath(DS . 'non-existing' . $inside);
  69. $this->assertFalse($result);
  70. }
  71. /**
  72. * testOperations method
  73. *
  74. * @access public
  75. * @return void
  76. */
  77. function testOperations() {
  78. $path = TEST_CAKE_CORE_INCLUDE_PATH . 'console' . DS . 'templates' . DS . 'skel';
  79. $Folder = new Folder($path);
  80. $result = is_dir($Folder->pwd());
  81. $this->assertTrue($result);
  82. $new = TMP . 'test_folder_new';
  83. $result = $Folder->create($new);
  84. $this->assertTrue($result);
  85. $copy = TMP . 'test_folder_copy';
  86. $result = $Folder->copy($copy);
  87. $this->assertTrue($result);
  88. $copy = TMP . 'test_folder_copy';
  89. $result = $Folder->copy($copy);
  90. $this->assertTrue($result);
  91. $copy = TMP . 'test_folder_copy';
  92. $result = $Folder->chmod($copy, 0755, false);
  93. $this->assertTrue($result);
  94. $result = $Folder->cd($copy);
  95. $this->assertTrue($result);
  96. $mv = TMP . 'test_folder_mv';
  97. $result = $Folder->move($mv);
  98. $this->assertTrue($result);
  99. $mv = TMP . 'test_folder_mv_2';
  100. $result = $Folder->move($mv);
  101. $this->assertTrue($result);
  102. $result = $Folder->delete($new);
  103. $this->assertTrue($result);
  104. $result = $Folder->delete($mv);
  105. $this->assertTrue($result);
  106. $result = $Folder->delete($mv);
  107. $this->assertTrue($result);
  108. $new = APP . 'index.php';
  109. $result = $Folder->create($new);
  110. $this->assertFalse($result);
  111. $expected = $new . ' is a file';
  112. $result = array_pop($Folder->errors());
  113. $this->assertEqual($result, $expected);
  114. $new = TMP . 'test_folder_new';
  115. $result = $Folder->create($new);
  116. $this->assertTrue($result);
  117. $result = $Folder->cd($new);
  118. $this->assertTrue($result);
  119. $result = $Folder->delete();
  120. $this->assertTrue($result);
  121. $Folder = new Folder('non-existent');
  122. $result = $Folder->pwd();
  123. $this->assertNull($result);
  124. }
  125. /**
  126. * testChmod method
  127. *
  128. * @return void
  129. * @access public
  130. */
  131. function testChmod() {
  132. $this->skipIf(DIRECTORY_SEPARATOR === '\\', '%s Folder permissions tests not supported on Windows');
  133. $path = TEST_CAKE_CORE_INCLUDE_PATH . 'console' . DS . 'templates' . DS . 'skel';
  134. $Folder = new Folder($path);
  135. $subdir = 'test_folder_new';
  136. $new = TMP . $subdir;
  137. $this->assertTrue($Folder->create($new));
  138. $this->assertTrue($Folder->create($new . DS . 'test1'));
  139. $this->assertTrue($Folder->create($new . DS . 'test2'));
  140. $filePath = $new . DS . 'test1.php';
  141. $File = new File($filePath);
  142. $this->assertTrue($File->create());
  143. $copy = TMP . 'test_folder_copy';
  144. $this->assertTrue($Folder->chmod($new, 0777, true));
  145. $this->assertEqual($File->perms(), '0777');
  146. $Folder->delete($new);
  147. }
  148. /**
  149. * testRealPathForWebroot method
  150. *
  151. * @access public
  152. * @return void
  153. */
  154. function testRealPathForWebroot() {
  155. $Folder = new Folder('files/');
  156. $this->assertEqual(realpath('files/'), $Folder->path);
  157. }
  158. /**
  159. * testZeroAsDirectory method
  160. *
  161. * @access public
  162. * @return void
  163. */
  164. function testZeroAsDirectory() {
  165. $Folder = new Folder(TMP);
  166. $new = TMP . '0';
  167. $this->assertTrue($Folder->create($new));
  168. $result = $Folder->read(true, true);
  169. $expected = array('0', 'cache', 'logs', 'sessions', 'tests');
  170. $this->assertEqual($expected, $result[0]);
  171. $result = $Folder->read(true, array('.', '..', 'logs', '.svn'));
  172. $expected = array('0', 'cache', 'sessions', 'tests');
  173. $this->assertEqual($expected, $result[0]);
  174. $result = $Folder->delete($new);
  175. $this->assertTrue($result);
  176. }
  177. /**
  178. * test Adding path elements to a path
  179. *
  180. * @return void
  181. */
  182. function testAddPathElement() {
  183. $result = Folder::addPathElement(DS . 'some' . DS . 'dir', 'another_path');
  184. $this->assertEqual($result, DS . 'some' . DS . 'dir' . DS . 'another_path');
  185. $result = Folder::addPathElement(DS . 'some' . DS . 'dir' . DS, 'another_path');
  186. $this->assertEqual($result, DS . 'some' . DS . 'dir' . DS . 'another_path');
  187. }
  188. /**
  189. * testFolderRead method
  190. *
  191. * @access public
  192. * @return void
  193. */
  194. function testFolderRead() {
  195. $Folder = new Folder(TMP);
  196. $expected = array('cache', 'logs', 'sessions', 'tests');
  197. $result = $Folder->read(true, true);
  198. $this->assertEqual($result[0], $expected);
  199. $Folder->path = TMP . DS . 'non-existent';
  200. $expected = array(array(), array());
  201. $result = $Folder->read(true, true);
  202. $this->assertEqual($result, $expected);
  203. }
  204. /**
  205. * testFolderTree method
  206. *
  207. * @access public
  208. * @return void
  209. */
  210. function testFolderTree() {
  211. $Folder = new Folder();
  212. $expected = array(
  213. array(
  214. TEST_CAKE_CORE_INCLUDE_PATH . 'config',
  215. TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode',
  216. TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding'
  217. ),
  218. array(
  219. TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php',
  220. TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'paths.php',
  221. TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0080_00ff.php',
  222. TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0100_017f.php',
  223. TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0180_024F.php',
  224. TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0250_02af.php',
  225. TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0370_03ff.php',
  226. TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0400_04ff.php',
  227. TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0500_052f.php',
  228. TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0530_058f.php',
  229. TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '1e00_1eff.php',
  230. TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '1f00_1fff.php',
  231. TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '2100_214f.php',
  232. TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '2150_218f.php',
  233. TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '2460_24ff.php',
  234. TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '2c00_2c5f.php',
  235. TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '2c60_2c7f.php',
  236. TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '2c80_2cff.php',
  237. TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . 'ff00_ffef.php'
  238. )
  239. );
  240. $result = $Folder->tree(TEST_CAKE_CORE_INCLUDE_PATH . 'config', false);
  241. $this->assertIdentical(array_diff($expected[0], $result[0]), array());
  242. $this->assertIdentical(array_diff($result[0], $expected[0]), array());
  243. $result = $Folder->tree(TEST_CAKE_CORE_INCLUDE_PATH . 'config', false, 'dir');
  244. $this->assertIdentical(array_diff($expected[0], $result), array());
  245. $this->assertIdentical(array_diff($result, $expected[0]), array());
  246. $result = $Folder->tree(TEST_CAKE_CORE_INCLUDE_PATH . 'config', false, 'files');
  247. $this->assertIdentical(array_diff($expected[1], $result), array());
  248. $this->assertIdentical(array_diff($result, $expected[1]), array());
  249. }
  250. /**
  251. * testWindowsPath method
  252. *
  253. * @access public
  254. * @return void
  255. */
  256. function testWindowsPath() {
  257. $this->assertFalse(Folder::isWindowsPath('0:\\cake\\is\\awesome'));
  258. $this->assertTrue(Folder::isWindowsPath('C:\\cake\\is\\awesome'));
  259. $this->assertTrue(Folder::isWindowsPath('d:\\cake\\is\\awesome'));
  260. }
  261. /**
  262. * testIsAbsolute method
  263. *
  264. * @access public
  265. * @return void
  266. */
  267. function testIsAbsolute() {
  268. $this->assertFalse(Folder::isAbsolute('path/to/file'));
  269. $this->assertFalse(Folder::isAbsolute('cake/'));
  270. $this->assertFalse(Folder::isAbsolute('path\\to\\file'));
  271. $this->assertFalse(Folder::isAbsolute('0:\\path\\to\\file'));
  272. $this->assertFalse(Folder::isAbsolute('\\path/to/file'));
  273. $this->assertFalse(Folder::isAbsolute('\\path\\to\\file'));
  274. $this->assertTrue(Folder::isAbsolute('/usr/local'));
  275. $this->assertTrue(Folder::isAbsolute('//path/to/file'));
  276. $this->assertTrue(Folder::isAbsolute('C:\\cake'));
  277. $this->assertTrue(Folder::isAbsolute('C:\\path\\to\\file'));
  278. $this->assertTrue(Folder::isAbsolute('d:\\path\\to\\file'));
  279. }
  280. /**
  281. * testIsSlashTerm method
  282. *
  283. * @access public
  284. * @return void
  285. */
  286. function testIsSlashTerm() {
  287. $this->assertFalse(Folder::isSlashTerm('cake'));
  288. $this->assertTrue(Folder::isSlashTerm('C:\\cake\\'));
  289. $this->assertTrue(Folder::isSlashTerm('/usr/local/'));
  290. }
  291. /**
  292. * testStatic method
  293. *
  294. * @access public
  295. * @return void
  296. */
  297. function testSlashTerm() {
  298. $result = Folder::slashTerm('/path/to/file');
  299. $this->assertEqual($result, '/path/to/file/');
  300. }
  301. /**
  302. * testNormalizePath method
  303. *
  304. * @access public
  305. * @return void
  306. */
  307. function testNormalizePath() {
  308. $path = '/path/to/file';
  309. $result = Folder::normalizePath($path);
  310. $this->assertEqual($result, '/');
  311. $path = '\\path\\\to\\\file';
  312. $result = Folder::normalizePath($path);
  313. $this->assertEqual($result, '/');
  314. $path = 'C:\\path\\to\\file';
  315. $result = Folder::normalizePath($path);
  316. $this->assertEqual($result, '\\');
  317. }
  318. /**
  319. * correctSlashFor method
  320. *
  321. * @access public
  322. * @return void
  323. */
  324. function testCorrectSlashFor() {
  325. $path = '/path/to/file';
  326. $result = Folder::correctSlashFor($path);
  327. $this->assertEqual($result, '/');
  328. $path = '\\path\\to\\file';
  329. $result = Folder::correctSlashFor($path);
  330. $this->assertEqual($result, '/');
  331. $path = 'C:\\path\to\\file';
  332. $result = Folder::correctSlashFor($path);
  333. $this->assertEqual($result, '\\');
  334. }
  335. /**
  336. * testInCakePath method
  337. *
  338. * @access public
  339. * @return void
  340. */
  341. function testInCakePath() {
  342. $Folder = new Folder();
  343. $Folder->cd(ROOT);
  344. $path = 'C:\\path\\to\\file';
  345. $result = $Folder->inCakePath($path);
  346. $this->assertFalse($result);
  347. $path = ROOT;
  348. $Folder->cd(ROOT);
  349. $result = $Folder->inCakePath($path);
  350. $this->assertFalse($result);
  351. // WHY DOES THIS FAIL ??
  352. $path = DS . 'cake' . DS . 'config';
  353. $Folder->cd(ROOT . DS . 'cake' . DS . 'config');
  354. $result = $Folder->inCakePath($path);
  355. $this->assertTrue($result);
  356. }
  357. /**
  358. * testFind method
  359. *
  360. * @access public
  361. * @return void
  362. */
  363. function testFind() {
  364. $Folder = new Folder();
  365. $Folder->cd(TEST_CAKE_CORE_INCLUDE_PATH . 'config');
  366. $result = $Folder->find();
  367. $expected = array('config.php', 'paths.php');
  368. $this->assertIdentical(array_diff($expected, $result), array());
  369. $this->assertIdentical(array_diff($result, $expected), array());
  370. $result = $Folder->find('.*', true);
  371. $expected = array('config.php', 'paths.php');
  372. $this->assertIdentical($result, $expected);
  373. $result = $Folder->find('.*\.php');
  374. $expected = array('config.php', 'paths.php');
  375. $this->assertIdentical(array_diff($expected, $result), array());
  376. $this->assertIdentical(array_diff($result, $expected), array());
  377. $result = $Folder->find('.*\.php', true);
  378. $expected = array('config.php', 'paths.php');
  379. $this->assertIdentical($result, $expected);
  380. $result = $Folder->find('.*ig\.php');
  381. $expected = array('config.php');
  382. $this->assertIdentical($result, $expected);
  383. $result = $Folder->find('paths\.php');
  384. $expected = array('paths.php');
  385. $this->assertIdentical($result, $expected);
  386. $Folder->cd(TMP);
  387. $file = new File($Folder->pwd() . DS . 'paths.php', true);
  388. $Folder->create($Folder->pwd() . DS . 'testme');
  389. $Folder->cd('testme');
  390. $result = $Folder->find('paths\.php');
  391. $expected = array();
  392. $this->assertIdentical($result, $expected);
  393. $Folder->cd($Folder->pwd() . '/..');
  394. $result = $Folder->find('paths\.php');
  395. $expected = array('paths.php');
  396. $this->assertIdentical($result, $expected);
  397. $Folder->cd(TMP);
  398. $Folder->delete($Folder->pwd() . DS . 'testme');
  399. $file->delete();
  400. }
  401. /**
  402. * testFindRecursive method
  403. *
  404. * @access public
  405. * @return void
  406. */
  407. function testFindRecursive() {
  408. $Folder = new Folder();
  409. $Folder->cd(TEST_CAKE_CORE_INCLUDE_PATH);
  410. $result = $Folder->findRecursive('(config|paths)\.php');
  411. $expected = array(
  412. TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php',
  413. TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'paths.php'
  414. );
  415. $this->assertIdentical(array_diff($expected, $result), array());
  416. $this->assertIdentical(array_diff($result, $expected), array());
  417. $result = $Folder->findRecursive('(config|paths)\.php', true);
  418. $expected = array(
  419. TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php',
  420. TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'paths.php'
  421. );
  422. $this->assertIdentical($result, $expected);
  423. $Folder->cd(TMP);
  424. $Folder->create($Folder->pwd() . DS . 'testme');
  425. $Folder->cd('testme');
  426. $File = new File($Folder->pwd() . DS . 'paths.php');
  427. $File->create();
  428. $Folder->cd(TMP . 'sessions');
  429. $result = $Folder->findRecursive('paths\.php');
  430. $expected = array();
  431. $this->assertIdentical($result, $expected);
  432. $Folder->cd(TMP . 'testme');
  433. $File = new File($Folder->pwd() . DS . 'my.php');
  434. $File->create();
  435. $Folder->cd($Folder->pwd() . '/../..');
  436. $result = $Folder->findRecursive('(paths|my)\.php');
  437. $expected = array(
  438. TMP . 'testme' . DS . 'my.php',
  439. TMP . 'testme' . DS . 'paths.php'
  440. );
  441. $this->assertIdentical(array_diff($expected, $result), array());
  442. $this->assertIdentical(array_diff($result, $expected), array());
  443. $result = $Folder->findRecursive('(paths|my)\.php', true);
  444. $expected = array(
  445. TMP . 'testme' . DS . 'my.php',
  446. TMP . 'testme' . DS . 'paths.php'
  447. );
  448. $this->assertIdentical($result, $expected);
  449. $Folder->cd(TEST_CAKE_CORE_INCLUDE_PATH . 'config');
  450. $Folder->cd(TMP);
  451. $Folder->delete($Folder->pwd() . DS . 'testme');
  452. $File->delete();
  453. }
  454. /**
  455. * testConstructWithNonExistantPath method
  456. *
  457. * @access public
  458. * @return void
  459. */
  460. function testConstructWithNonExistantPath() {
  461. $Folder = new Folder(TMP . 'config_non_existant', true);
  462. $this->assertTrue(is_dir(TMP . 'config_non_existant'));
  463. $Folder->cd(TMP);
  464. $Folder->delete($Folder->pwd() . 'config_non_existant');
  465. }
  466. /**
  467. * testDirSize method
  468. *
  469. * @access public
  470. * @return void
  471. */
  472. function testDirSize() {
  473. $Folder = new Folder(TMP . 'config_non_existant', true);
  474. $this->assertEqual($Folder->dirSize(), 0);
  475. $File = new File($Folder->pwd() . DS . 'my.php', true, 0777);
  476. $File->create();
  477. $File->write('something here');
  478. $File->close();
  479. $this->assertEqual($Folder->dirSize(), 14);
  480. $Folder->cd(TMP);
  481. $Folder->delete($Folder->pwd() . 'config_non_existant');
  482. }
  483. /**
  484. * testDelete method
  485. *
  486. * @access public
  487. * @return void
  488. */
  489. function testDelete() {
  490. $path = TMP . 'folder_delete_test';
  491. $Folder = new Folder($path, true);
  492. touch(TMP . 'folder_delete_test' . DS . 'file1');
  493. touch(TMP . 'folder_delete_test' . DS . 'file2');
  494. $return = $Folder->delete();
  495. $this->assertTrue($return);
  496. $messages = $Folder->messages();
  497. $errors = $Folder->errors();
  498. $this->assertEqual($errors, array());
  499. $expected = array(
  500. $path . ' created',
  501. $path . DS . 'file1 removed',
  502. $path . DS . 'file2 removed',
  503. $path . ' removed'
  504. );
  505. $this->assertEqual($expected, $messages);
  506. }
  507. /**
  508. * testCopy method
  509. *
  510. * Verify that directories and files are copied recursively
  511. * even if the destination directory already exists.
  512. * Subdirectories existing in both destination and source directory
  513. * are skipped and not merged or overwritten.
  514. *
  515. * @return void
  516. * @access public
  517. * @link https://trac.cakephp.org/ticket/6259
  518. */
  519. function testCopy() {
  520. $path = TMP . 'folder_test';
  521. $folder1 = $path . DS . 'folder1';
  522. $folder2 = $folder1 . DS . 'folder2';
  523. $folder3 = $path . DS . 'folder3';
  524. $file1 = $folder1 . DS . 'file1.php';
  525. $file2 = $folder2 . DS . 'file2.php';
  526. new Folder($path, true);
  527. new Folder($folder1, true);
  528. new Folder($folder2, true);
  529. new Folder($folder3, true);
  530. touch($file1);
  531. touch($file2);
  532. $Folder = new Folder($folder1);
  533. $result = $Folder->copy($folder3);
  534. $this->assertTrue($result);
  535. $this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
  536. $this->assertTrue(file_exists($folder3 . DS . 'folder2' . DS . 'file2.php'));
  537. $Folder = new Folder($folder3);
  538. $Folder->delete();
  539. $Folder = new Folder($folder1);
  540. $result = $Folder->copy($folder3);
  541. $this->assertTrue($result);
  542. $this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
  543. $this->assertTrue(file_exists($folder3 . DS . 'folder2' . DS . 'file2.php'));
  544. $Folder = new Folder($folder3);
  545. $Folder->delete();
  546. new Folder($folder3, true);
  547. new Folder($folder3 . DS . 'folder2', true);
  548. file_put_contents($folder3 . DS . 'folder2' . DS . 'file2.php', 'untouched');
  549. $Folder = new Folder($folder1);
  550. $result = $Folder->copy($folder3);
  551. $this->assertTrue($result);
  552. $this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
  553. $this->assertEqual(file_get_contents($folder3 . DS . 'folder2' . DS . 'file2.php'), 'untouched');
  554. $Folder = new Folder($path);
  555. $Folder->delete();
  556. }
  557. /**
  558. * testMove method
  559. *
  560. * Verify that directories and files are moved recursively
  561. * even if the destination directory already exists.
  562. * Subdirectories existing in both destination and source directory
  563. * are skipped and not merged or overwritten.
  564. *
  565. * @return void
  566. * @access public
  567. * @link https://trac.cakephp.org/ticket/6259
  568. */
  569. function testMove() {
  570. $path = TMP . 'folder_test';
  571. $folder1 = $path . DS . 'folder1';
  572. $folder2 = $folder1 . DS . 'folder2';
  573. $folder3 = $path . DS . 'folder3';
  574. $file1 = $folder1 . DS . 'file1.php';
  575. $file2 = $folder2 . DS . 'file2.php';
  576. new Folder($path, true);
  577. new Folder($folder1, true);
  578. new Folder($folder2, true);
  579. new Folder($folder3, true);
  580. touch($file1);
  581. touch($file2);
  582. $Folder = new Folder($folder1);
  583. $result = $Folder->move($folder3);
  584. $this->assertTrue($result);
  585. $this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
  586. $this->assertTrue(is_dir($folder3 . DS . 'folder2'));
  587. $this->assertTrue(file_exists($folder3 . DS . 'folder2' . DS . 'file2.php'));
  588. $this->assertFalse(file_exists($file1));
  589. $this->assertFalse(file_exists($folder2));
  590. $this->assertFalse(file_exists($file2));
  591. $Folder = new Folder($folder3);
  592. $Folder->delete();
  593. new Folder($folder1, true);
  594. new Folder($folder2, true);
  595. touch($file1);
  596. touch($file2);
  597. $Folder = new Folder($folder1);
  598. $result = $Folder->move($folder3);
  599. $this->assertTrue($result);
  600. $this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
  601. $this->assertTrue(is_dir($folder3 . DS . 'folder2'));
  602. $this->assertTrue(file_exists($folder3 . DS . 'folder2' . DS . 'file2.php'));
  603. $this->assertFalse(file_exists($file1));
  604. $this->assertFalse(file_exists($folder2));
  605. $this->assertFalse(file_exists($file2));
  606. $Folder = new Folder($folder3);
  607. $Folder->delete();
  608. new Folder($folder1, true);
  609. new Folder($folder2, true);
  610. new Folder($folder3, true);
  611. new Folder($folder3 . DS . 'folder2', true);
  612. touch($file1);
  613. touch($file2);
  614. file_put_contents($folder3 . DS . 'folder2' . DS . 'file2.php', 'untouched');
  615. $Folder = new Folder($folder1);
  616. $result = $Folder->move($folder3);
  617. $this->assertTrue($result);
  618. $this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
  619. $this->assertEqual(file_get_contents($folder3 . DS . 'folder2' . DS . 'file2.php'), 'untouched');
  620. $this->assertFalse(file_exists($file1));
  621. $this->assertFalse(file_exists($folder2));
  622. $this->assertFalse(file_exists($file2));
  623. $Folder = new Folder($path);
  624. $Folder->delete();
  625. }
  626. }
  627. ?>