MINOR Less obtrusive tests for testing the SS temp directory (from r94135)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@95589 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sean Harvey 2009-12-16 05:36:48 +00:00
parent b39b85fe58
commit a4e858aee7

View File

@ -9,49 +9,34 @@
*/ */
class CoreTest extends SapphireTest { class CoreTest extends SapphireTest {
protected $tempPath, $renamedTempPath; protected $tempPath;
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
$this->tempPath = $tempPath = Director::baseFolder() . '/silverstripe-cache'; $this->tempPath = $tempPath = Director::baseFolder() . '/silverstripe-cache';
$this->renamedTempPath = $renamedTempPath = Director::baseFolder() . '/silverstripe-cache-1';
// If the test failed (PHP error) this will need to be renamed
if(file_exists($renamedTempPath)) {
rename($renamedTempPath, $tempPath);
}
if(!file_exists($tempPath)) {
mkdir($tempPath);
}
} }
public function testGetTempPathInProject() { public function testGetTempPathInProject() {
$this->assertEquals(getTempFolder(), $this->tempPath); if(file_exists($this->tempPath)) {
rename($this->tempPath, $this->tempPath . '-1'); $this->assertEquals(getTempFolder(), $this->tempPath);
} else {
// Store the original variable so we know what to change it back to // Store the original variable so we know what to change it back to
$old = $_SERVER['SCRIPT_FILENAME']; $old = $_SERVER['SCRIPT_FILENAME'];
// A typical Windows location for where sites are stored on IIS // A typical Windows location for where sites are stored on IIS
$_SERVER['SCRIPT_FILENAME'] = 'C:\inetpub\wwwroot\silverstripe\sapphire\main.php'; $_SERVER['SCRIPT_FILENAME'] = 'C:\\inetpub\\wwwroot\\silverstripe\\sapphire\\main.php';
$this->assertEquals(getTempFolder(), getSysTempDir() . '/silverstripe-cacheC--inetpub-wwwroot-silverstripe'); $this->assertEquals(getTempFolder(), getSysTempDir() . '/silverstripe-cacheC--inetpub-wwwroot-silverstripe');
// A typical Mac OS X location for where sites are stored // A typical Mac OS X location for where sites are stored
$_SERVER['SCRIPT_FILENAME'] = '/Users/joebloggs/Sites/silverstripe/sapphire/main.php'; $_SERVER['SCRIPT_FILENAME'] = '/Users/joebloggs/Sites/silverstripe/sapphire/main.php';
$this->assertEquals(getTempFolder(), getSysTempDir() . '/silverstripe-cache-Users-joebloggs-Sites-silverstripe'); $this->assertEquals(getTempFolder(), getSysTempDir() . '/silverstripe-cache-Users-joebloggs-Sites-silverstripe');
// A typical Linux location for where sites are stored // A typical Linux location for where sites are stored
$_SERVER['SCRIPT_FILENAME'] = '/var/www/silverstripe/sapphire/main.php'; $_SERVER['SCRIPT_FILENAME'] = '/var/www/silverstripe/sapphire/main.php';
$this->assertEquals(getTempFolder(), getSysTempDir() . '/silverstripe-cache-var-www-silverstripe'); $this->assertEquals(getTempFolder(), getSysTempDir() . '/silverstripe-cache-var-www-silverstripe');
// Restore the SCRIPT_FILENAME variable back to the original // Restore the SCRIPT_FILENAME variable back to the original
$_SERVER['SCRIPT_FILENAME'] = $old; $_SERVER['SCRIPT_FILENAME'] = $old;
}
public function tearDown() {
parent::tearDown();
if(file_exists($this->renamedTempPath)) {
rename($this->renamedTempPath, Director::baseFolder() . '/silverstripe-cache');
} }
} }