mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Adding tests for Folder::copy and ::move showing that
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
This commit is contained in:
parent
6551e2a45d
commit
392a6b195d
1 changed files with 137 additions and 1 deletions
|
@ -566,5 +566,141 @@ class FolderTest extends CakeTestCase {
|
|||
);
|
||||
$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();
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
|
Loading…
Reference in a new issue