From b46ee168ef227672268aede0a90e878d6d1b1ddd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Thu, 6 Dec 2012 02:42:48 +0100 Subject: [PATCH] MDL-36963 Add unit tests for directory operations in mdeploy.php --- mdeploytest.php | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/mdeploytest.php b/mdeploytest.php index 471a9d33eae..4724172e621 100644 --- a/mdeploytest.php +++ b/mdeploytest.php @@ -85,6 +85,30 @@ class testable_input_manager extends input_manager { } +/** + * Testable subclass + * + * @copyright 2012 David Mudrak + * @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')); + } }