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

Commit

Permalink
ENH: refs #0294. Centralized calls to getTempDirectory to KWUtils sta…
Browse files Browse the repository at this point in the history
…tic method
  • Loading branch information
Michael Grauer committed Nov 10, 2011
1 parent a13e277 commit cb8f63f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion core/GlobalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public function getEnvironment()
*/
public function getTempDirectory()
{
return BASE_PATH.'/tmp/misc';
return KWUtils::getTempDirectory();
}

/** return an array of form element */
Expand Down
11 changes: 11 additions & 0 deletions library/KWUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ public static function mkDir($dir, $mode = self::DEFAULT_MKDIR_MODE)
return true;
}

/**
* @method public getTempDirectory()
* get the midas temporary directory
* @return string
*/
public static function getTempDirectory()
{
return BASE_PATH.'/tmp/misc';
}


/**
* @method createSubDirectories recursively create subdirectories starting at
* baseDirectory, sequentially creating each of the directories in the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ public function setup()
*/
protected function getTempDirectory()
{
include_once BASE_PATH.'/core/GlobalController.php';
$controller = new MIDAS_GlobalController($this->request, $this->response);
return $controller->getTempDirectory();
return KWUtils::getTempDirectory();
}

/**
Expand Down
28 changes: 9 additions & 19 deletions tests/library/KWUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,14 @@
class KWUtilsTest extends ControllerTestCase
{

/**
* helper function to return Midas configured temp directory
* @return midas temp dir
*/
protected function getTempDirectory()
{
include_once BASE_PATH.'/core/GlobalController.php';
$controller = new MIDAS_GlobalController($this->request, $this->response);
return $controller->getTempDirectory();
}

/** tests mkDir function */
public function testMkDir()
{
$tmpDir = $this->getTempDirectory() . '/KWUtilsTest';
$this->assertTrue(KWUtils::mkDir($tmpDir));
$tmpDir = KWUtils::getTempDirectory();
$testDir = $tmpDir . '/' . 'KWUtilsTest';
$this->assertTrue(KWUtils::mkDir($testDir));
// now clean up
KWUtils::recursiveRemoveDirectory($tmpDir);
KWUtils::recursiveRemoveDirectory($testDir);
}

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

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

$topDir = $this->getTempDirectory() . '/KWUtilsTest';
$topDir = KWUtils::getTempDirectory() . '/KWUtilsTest';
KWUtils::recursiveRemoveDirectory($topDir);
}

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

// create a tmp dir for this test
$execDir = $this->getTempDirectory() . '/KWUtilsTest';
$execDir = KWUtils::getTempDirectory() . '/KWUtilsTest';
mkdir($execDir);
$cmd = 'pwd';
$chdir = $execDir;
Expand Down Expand Up @@ -162,9 +152,9 @@ public function testRecursiveRemoveDirectory()
$this->assertFalse(KWUtils::recursiveRemoveDirectory('thisstringisunlikelytobeadirectory'));

// create a two-level directory
$testParentDir = $this->getTempDirectory() . '/KWUtilsParentDir';
$testParentDir = KWUtils::getTempDirectory() . '/KWUtilsParentDir';
mkdir($testParentDir);
$testChildDir = $this->getTempDirectory() . '/KWUtilsParentDir/ChildDir';
$testChildDir = KWUtils::getTempDirectory() . '/KWUtilsParentDir/ChildDir';
mkdir($testChildDir);
copy(BASE_PATH.'/tests/testfiles/search.png', $testChildDir.'/testContent.png');
$this->assertTrue(file_exists($testChildDir.'/testContent.png'));
Expand Down

0 comments on commit cb8f63f

Please sign in to comment.