MDL-36963 Add unit tests for directory operations in mdeploy.php

This commit is contained in:
David Mudrák 2012-12-06 02:42:48 +01:00 committed by Dan Poltawski
parent 75879a9e74
commit dabe5acc42

View File

@ -85,6 +85,30 @@ class testable_input_manager extends input_manager {
}
/**
* Testable subclass
*
* @copyright 2012 David Mudrak <david@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class testable_worker extends worker {
/**
* Provides access to the protected method.
*/
public function move_directory($source, $target, $keepsourceroot = false) {
return parent::move_directory($source, $target, $keepsourceroot);
}
/**
* Provides access to the protected method.
*/
public function remove_directory($path, $keeppathroot = false) {
return parent::remove_directory($path, $keeppathroot);
}
}
/**
* Test cases for the mdeploy utility
*
@ -212,4 +236,26 @@ class mdeploytest extends PHPUnit_Framework_TestCase {
$this->assertTrue(true);
}
}
public function test_moving_and_removing_directories() {
$worker = testable_worker::instance();
$root = sys_get_temp_dir().'/'.uniqid('mdeploytest', true);
mkdir($root.'/a', 0777, true);
touch($root.'/a/a.txt');
$this->assertTrue(file_exists($root.'/a/a.txt'));
$this->assertFalse(file_exists($root.'/b/a.txt'));
$this->assertTrue($worker->move_directory($root.'/a', $root.'/b'));
$this->assertFalse(is_dir($root.'/a'));
$this->assertTrue(file_exists($root.'/b/a.txt'));
$this->assertTrue($worker->move_directory($root.'/b', $root.'/c', true));
$this->assertTrue(file_exists($root.'/c/a.txt'));
$this->assertFalse(file_exists($root.'/b/a.txt'));
$this->assertTrue(is_dir($root.'/b'));
$this->assertTrue($worker->remove_directory($root.'/c', true));
$this->assertFalse(file_exists($root.'/c/a.txt'));
$this->assertTrue($worker->remove_directory($root.'/c'));
$this->assertFalse(is_dir($root.'/c'));
}
}