Permalink
Browse files

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

  • Loading branch information...
mudrd8mz committed Dec 6, 2012
1 parent e399d32 commit b46ee168ef227672268aede0a90e878d6d1b1ddd
Showing with 46 additions and 0 deletions.
  1. +46 −0 mdeploytest.php
View
@@ -85,6 +85,30 @@ protected function initialize() {
}
+/**
+ * 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 @@ public function test_get_option() {
$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'));
+ }
}

0 comments on commit b46ee16

Please sign in to comment.