Skip to content

Commit

Permalink
Adding tests for Folder::copy and ::move showing that
Browse files Browse the repository at this point in the history
skipping existing subdirectories is the intended behavior.
Disproves #6529.  Refs #6529.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8133 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information
mariuswilms committed Apr 1, 2009
1 parent 6551e2a commit 392a6b1
Showing 1 changed file with 137 additions and 1 deletion.
138 changes: 137 additions & 1 deletion cake/tests/cases/libs/folder.test.php
Expand Up @@ -566,5 +566,141 @@ function testDelete() {
);
$this->assertEqual($expected, $messages);
}
/**
* testCopy method
*
* Verify that directories and files are copied recursively
* even if the destination directory already exists.
* Subdirectories existing in both destination and source directory
* are skipped and not merged or overwritten.
*
* @return void
* @access public
* @link https://trac.cakephp.org/ticket/6259
*/
function testCopy() {
$path = TMP . 'folder_test';
$folder1 = $path . DS . 'folder1';
$folder2 = $folder1 . DS . 'folder2';
$folder3 = $path . DS . 'folder3';
$file1 = $folder1 . DS . 'file1.php';
$file2 = $folder2 . DS . 'file2.php';

new Folder($path, true);
new Folder($folder1, true);
new Folder($folder2, true);
new Folder($folder3, true);
touch($file1);
touch($file2);

$Folder =& new Folder($folder1);
$result = $Folder->copy($folder3);
$this->assertTrue($result);
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
$this->assertTrue(file_exists($folder3 . DS . 'folder2' . DS . 'file2.php'));

$Folder =& new Folder($folder3);
$Folder->delete();

$Folder =& new Folder($folder1);
$result = $Folder->copy($folder3);
$this->assertTrue($result);
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
$this->assertTrue(file_exists($folder3 . DS . 'folder2' . DS . 'file2.php'));

$Folder =& new Folder($folder3);
$Folder->delete();

new Folder($folder3, true);
new Folder($folder3 . DS . 'folder2', true);
file_put_contents($folder3 . DS . 'folder2' . DS . 'file2.php', 'untouched');

$Folder =& new Folder($folder1);
$result = $Folder->copy($folder3);
$this->assertTrue($result);
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
$this->assertEqual(file_get_contents($folder3 . DS . 'folder2' . DS . 'file2.php'), 'untouched');

$Folder =& new Folder($path);
$Folder->delete();
}
/**
* testMove method
*
* Verify that directories and files are moved recursively
* even if the destination directory already exists.
* Subdirectories existing in both destination and source directory
* are skipped and not merged or overwritten.
*
* @return void
* @access public
* @link https://trac.cakephp.org/ticket/6259
*/
function testMove() {
$path = TMP . 'folder_test';
$folder1 = $path . DS . 'folder1';
$folder2 = $folder1 . DS . 'folder2';
$folder3 = $path . DS . 'folder3';
$file1 = $folder1 . DS . 'file1.php';
$file2 = $folder2 . DS . 'file2.php';

new Folder($path, true);
new Folder($folder1, true);
new Folder($folder2, true);
new Folder($folder3, true);
touch($file1);
touch($file2);

$Folder =& new Folder($folder1);
$result = $Folder->move($folder3);
$this->assertTrue($result);
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
$this->assertTrue(is_dir($folder3 . DS . 'folder2'));
$this->assertTrue(file_exists($folder3 . DS . 'folder2' . DS . 'file2.php'));
$this->assertFalse(file_exists($file1));
$this->assertFalse(file_exists($folder2));
$this->assertFalse(file_exists($file2));

$Folder =& new Folder($folder3);
$Folder->delete();

new Folder($folder1, true);
new Folder($folder2, true);
touch($file1);
touch($file2);

$Folder =& new Folder($folder1);
$result = $Folder->move($folder3);
$this->assertTrue($result);
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
$this->assertTrue(is_dir($folder3 . DS . 'folder2'));
$this->assertTrue(file_exists($folder3 . DS . 'folder2' . DS . 'file2.php'));
$this->assertFalse(file_exists($file1));
$this->assertFalse(file_exists($folder2));
$this->assertFalse(file_exists($file2));

$Folder =& new Folder($folder3);
$Folder->delete();

new Folder($folder1, true);
new Folder($folder2, true);
new Folder($folder3, true);
new Folder($folder3 . DS . 'folder2', true);
touch($file1);
touch($file2);
file_put_contents($folder3 . DS . 'folder2' . DS . 'file2.php', 'untouched');

$Folder =& new Folder($folder1);
$result = $Folder->move($folder3);
$this->assertTrue($result);
$this->assertTrue(file_exists($folder3 . DS . 'file1.php'));
$this->assertEqual(file_get_contents($folder3 . DS . 'folder2' . DS . 'file2.php'), 'untouched');
$this->assertFalse(file_exists($file1));
$this->assertFalse(file_exists($folder2));
$this->assertFalse(file_exists($file2));

$Folder =& new Folder($path);
$Folder->delete();
}
}
?>
?>

0 comments on commit 392a6b1

Please sign in to comment.