diff options
author | David King <imkingdavid@gmail.com> | 2012-09-01 16:38:47 -0400 |
---|---|---|
committer | David King <imkingdavid@gmail.com> | 2012-09-01 16:38:47 -0400 |
commit | 7bf598954c452448c2807428f6517cd75d910f92 (patch) | |
tree | 1a8ba768a01b36e8fb1159b996383d935fb8b352 /tests/test_framework/phpbb_test_case_helpers.php | |
parent | 43190ebecaeadbc8738da9dcb33b9163652fb9f3 (diff) | |
parent | 81f7f28cc33d896973c2912097103ea84fa14114 (diff) | |
download | forums-7bf598954c452448c2807428f6517cd75d910f92.tar forums-7bf598954c452448c2807428f6517cd75d910f92.tar.gz forums-7bf598954c452448c2807428f6517cd75d910f92.tar.bz2 forums-7bf598954c452448c2807428f6517cd75d910f92.tar.xz forums-7bf598954c452448c2807428f6517cd75d910f92.zip |
Merge remote-tracking branch 'unknownbliss/ticket/10631' into develop
Diffstat (limited to 'tests/test_framework/phpbb_test_case_helpers.php')
-rw-r--r-- | tests/test_framework/phpbb_test_case_helpers.php | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 46feef550a..d10645a732 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -115,4 +115,112 @@ class phpbb_test_case_helpers return $config; } + + /** + * Recursive directory copying function + * + * @param string $source + * @param string $dest + * @return array list of files copied + */ + public function copy_dir($source, $dest) + { + $source = (substr($source, -1) == '/') ? $source : $source . '/'; + $dest = (substr($dest, -1) == '/') ? $dest : $dest . '/'; + + $copied_files = array(); + + if (!is_dir($dest)) + { + $this->makedirs($dest); + } + + $files = scandir($source); + foreach ($files as $file) + { + if ($file == '.' || $file == '..') + { + continue; + } + + if (is_dir($source . $file)) + { + $created_dir = false; + if (!is_dir($dest . $file)) + { + $created_dir = true; + $this->makedirs($dest . $file); + } + + $copied_files = array_merge($copied_files, self::copy_dir($source . $file, $dest . $file)); + + if ($created_dir) + { + $copied_files[] = $dest . $file; + } + } + else + { + if (!file_exists($dest . $file)) + { + copy($source . $file, $dest . $file); + + $copied_files[] = $dest . $file; + } + } + } + + return $copied_files; + } + + /** + * Remove files/directories that are listed in an array + * Designed for use with $this->copy_dir() + * + * @param array $file_list + */ + public function remove_files($file_list) + { + foreach ($file_list as $file) + { + if (is_dir($file)) + { + rmdir($file); + } + else + { + unlink($file); + } + } + } + + /** + * Empty directory (remove any subdirectories/files below) + * + * @param array $file_list + */ + public function empty_dir($path) + { + $path = (substr($path, -1) == '/') ? $path : $path . '/'; + + $files = scandir($path); + foreach ($files as $file) + { + if ($file == '.' || $file == '..') + { + continue; + } + + if (is_dir($path . $file)) + { + $this->empty_dir($path . $file); + + rmdir($path . $file); + } + else + { + unlink($path . $file); + } + } + } } |