Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit cb8f63f

Browse files
author
Michael Grauer
committed
ENH: refs #0294. Centralized calls to getTempDirectory to KWUtils static method
1 parent a13e277 commit cb8f63f

File tree

4 files changed

+22
-23
lines changed

4 files changed

+22
-23
lines changed

core/GlobalController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public function getEnvironment()
279279
*/
280280
public function getTempDirectory()
281281
{
282-
return BASE_PATH.'/tmp/misc';
282+
return KWUtils::getTempDirectory();
283283
}
284284

285285
/** return an array of form element */

library/KWUtils.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ public static function mkDir($dir, $mode = self::DEFAULT_MKDIR_MODE)
4646
return true;
4747
}
4848

49+
/**
50+
* @method public getTempDirectory()
51+
* get the midas temporary directory
52+
* @return string
53+
*/
54+
public static function getTempDirectory()
55+
{
56+
return BASE_PATH.'/tmp/misc';
57+
}
58+
59+
4960
/**
5061
* @method createSubDirectories recursively create subdirectories starting at
5162
* baseDirectory, sequentially creating each of the directories in the

modules/batchmake/tests/controllers/BatchmakeControllerTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ public function setup()
3636
*/
3737
protected function getTempDirectory()
3838
{
39-
include_once BASE_PATH.'/core/GlobalController.php';
40-
$controller = new MIDAS_GlobalController($this->request, $this->response);
41-
return $controller->getTempDirectory();
39+
return KWUtils::getTempDirectory();
4240
}
4341

4442
/**

tests/library/KWUtilsTest.php

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,14 @@
2121
class KWUtilsTest extends ControllerTestCase
2222
{
2323

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-
}
34-
3524
/** tests mkDir function */
3625
public function testMkDir()
3726
{
38-
$tmpDir = $this->getTempDirectory() . '/KWUtilsTest';
39-
$this->assertTrue(KWUtils::mkDir($tmpDir));
27+
$tmpDir = KWUtils::getTempDirectory();
28+
$testDir = $tmpDir . '/' . 'KWUtilsTest';
29+
$this->assertTrue(KWUtils::mkDir($testDir));
4030
// now clean up
41-
KWUtils::recursiveRemoveDirectory($tmpDir);
31+
KWUtils::recursiveRemoveDirectory($testDir);
4232
}
4333

4434
/** tests createSubDirectories function */
@@ -47,7 +37,7 @@ public function testCreateSubDirectories()
4737
// test creating directories, do this in the tmp dir
4838
//
4939
// create a nested set of directories
50-
$tmpDir = $this->getTempDirectory() . '/';
40+
$tmpDir = KWUtils::getTempDirectory() . '/';
5141
$subDirs = array("KWUtilsTest", "1", "2", "3");
5242
$outDir = KWUtils::createSubDirectories($tmpDir, $subDirs);
5343

@@ -66,7 +56,7 @@ public function testCreateSubDirectories()
6656
$this->assertTrue(is_dir($currDir));
6757
}
6858

69-
$topDir = $this->getTempDirectory() . '/KWUtilsTest';
59+
$topDir = KWUtils::getTempDirectory() . '/KWUtilsTest';
7060
KWUtils::recursiveRemoveDirectory($topDir);
7161
}
7262

@@ -78,7 +68,7 @@ public function testExec()
7868
// the value of pwd in it
7969

8070
// create a tmp dir for this test
81-
$execDir = $this->getTempDirectory() . '/KWUtilsTest';
71+
$execDir = KWUtils::getTempDirectory() . '/KWUtilsTest';
8272
mkdir($execDir);
8373
$cmd = 'pwd';
8474
$chdir = $execDir;
@@ -162,9 +152,9 @@ public function testRecursiveRemoveDirectory()
162152
$this->assertFalse(KWUtils::recursiveRemoveDirectory('thisstringisunlikelytobeadirectory'));
163153

164154
// create a two-level directory
165-
$testParentDir = $this->getTempDirectory() . '/KWUtilsParentDir';
155+
$testParentDir = KWUtils::getTempDirectory() . '/KWUtilsParentDir';
166156
mkdir($testParentDir);
167-
$testChildDir = $this->getTempDirectory() . '/KWUtilsParentDir/ChildDir';
157+
$testChildDir = KWUtils::getTempDirectory() . '/KWUtilsParentDir/ChildDir';
168158
mkdir($testChildDir);
169159
copy(BASE_PATH.'/tests/testfiles/search.png', $testChildDir.'/testContent.png');
170160
$this->assertTrue(file_exists($testChildDir.'/testContent.png'));

0 commit comments

Comments
 (0)