coding style
[dokuwiki.git] / _test / core / TestUtils.php
blobe855cb00798bbded6a94b1cf123979d3b3a6c38b
1 <?php
3 /**
4 * Helper class with some filesystem utilities.
5 */
6 class TestUtils {
8 /**
9 * converts path to unix-like on windows OS
10 * @param string $path UNIX-like path to be converted
11 * @return string
13 public static function w2u($path) {
14 return isWindows() ? str_replace('\\', '/', $path) : $path;
17 /**
18 * helper for recursive copy()
20 * @static
21 * @param $destdir string
22 * @param $source string
24 public static function rcopy($destdir, $source) {
25 if (!is_dir($source)) {
26 copy($source, $destdir.'/'.basename($source));
27 } else {
28 $newdestdir = $destdir.'/'.basename($source);
29 if (!is_dir($newdestdir)) {
30 mkdir($newdestdir);
33 $dh = dir($source);
34 while (false !== ($entry = $dh->read())) {
35 if ($entry == '.' || $entry == '..') {
36 continue;
38 TestUtils::rcopy($newdestdir, $source.'/'.$entry);
40 $dh->close();
44 /**
45 * helper for recursive rmdir()/unlink()
47 * @static
48 * @param $target string
50 public static function rdelete($target) {
51 if (!is_dir($target)) {
52 unlink($target);
53 } else {
54 $dh = dir($target);
55 while (false !== ($entry = $dh->read())) {
56 if ($entry == '.' || $entry == '..') {
57 continue;
59 TestUtils::rdelete("$target/$entry");
61 $dh->close();
62 rmdir($target);
66 /**
67 * helper to append text to a file
69 * @static
70 * @param $file string
71 * @param $text string
73 public static function fappend($file, $text) {
74 $fh = fopen($file, 'a');
75 fwrite($fh, $text);
76 fclose($fh);