16
16
/**
17
17
* KWUtils tests
18
18
*/
19
+
20
+
19
21
class KWUtilsTest extends ControllerTestCase
20
22
{
21
23
24
+ /**
25
+ * helper function to return Midas configured temp directory
26
+ * @return midas temp dir
27
+ */
28
+ protected function getTempDirectory ()
29
+ {
30
+ include_once BASE_PATH .'/core/GlobalController.php ' ;
31
+ $ controller = new MIDAS_GlobalController ($ this ->request , $ this ->response );
32
+ return $ controller ->getTempDirectory ();
33
+ }
22
34
23
35
/** tests mkDir function */
24
36
public function testMkDir ()
25
37
{
26
- $ tmpDir = ' /tmp ' ;
38
+ $ tmpDir = $ this -> getTempDirectory () . ' / ' ;
27
39
// try creating one that exists
28
40
// we can ignore any errors
29
41
$ this ->assertFalse (KWUtils::mkDir ($ tmpDir ));
30
- $ tmpDir .= "/ KWUtilsTest " ;
42
+ $ tmpDir .= "KWUtilsTest " ;
31
43
$ this ->assertTrue (KWUtils::mkDir ($ tmpDir ));
32
44
// now clean up
33
45
rmdir ($ tmpDir );
@@ -39,7 +51,7 @@ public function testCreateSubDirectories()
39
51
// test creating directories, do this in the tmp dir
40
52
//
41
53
// create a nested set of directories
42
- $ tmpDir = BASE_PATH . 'tmp / ' ;
54
+ $ tmpDir = $ this -> getTempDirectory () . '/ ' ;
43
55
$ subDirs = array ("KWUtilsTest " , "1 " , "2 " , "3 " );
44
56
$ outDir = KWUtils::createSubDirectories ($ tmpDir , $ subDirs );
45
57
@@ -77,7 +89,7 @@ public function testExec()
77
89
// the value of pwd in it
78
90
79
91
// create a tmp dir for this test
80
- $ execDir = BASE_PATH . 'tmp /KWUtilsTest ' ;
92
+ $ execDir = $ this -> getTempDirectory () . '/KWUtilsTest ' ;
81
93
mkdir ($ execDir );
82
94
$ cmd = 'pwd ' ;
83
95
$ chdir = $ execDir ;
@@ -86,9 +98,13 @@ public function testExec()
86
98
87
99
// yuck, need to do a bit of munging to get around tests/.. in BASE_PATH
88
100
$ execDir = str_replace ('tests/../ ' , '' , $ execDir );
101
+ // and now replace any // with /,
102
+ // the // doesn't affect functionality on the
103
+ // filesystem, but will cause string inequality
104
+ $ execDir = str_replace ('// ' , '/ ' , $ execDir );
89
105
90
106
$ this ->assertEquals ($ execDir , $ output [0 ]);
91
- // return_val should be 0
107
+ // returnVal should be 0
92
108
$ this ->assertEquals ($ returnVal , 0 );
93
109
// now clean up the tmp dir
94
110
rmdir ($ execDir );
0 commit comments