silverstripe-framework/tests/core/CoreTest.php
Lukas a990c99d6e NEW: suffix subfolder in silverstripe-cache with php-version (#6810)
Note that this changes the default temp path value 

 * Was: /tmp/silverstripe-cache-Users-FOO-webroot-BAR-php7.1.5/USER
 * Now: /tmp/silverstripe-cache-Users-FOO-webroot-BAR/USER-php7.1.5
2017-06-16 11:25:02 +12:00

62 lines
2.1 KiB
PHP

<?php
/**
* Tests for the core of SilverStripe, such as how the temporary
* directory is determined throughout the framework.
*
* @package framework
* @subpackage tests
*/
class CoreTest extends SapphireTest {
protected $tempPath;
public function setUp() {
parent::setUp();
$this->tempPath = Director::baseFolder() . DIRECTORY_SEPARATOR . 'silverstripe-cache';
}
public function testGetTempPathInProject() {
$user = getTempFolderUsername();
$phpversion = '-php' . preg_replace('/[^\w-\.+]+/', '-', PHP_VERSION);
if(file_exists($this->tempPath)) {
$this->assertEquals(getTempFolder(BASE_PATH), $this->tempPath . DIRECTORY_SEPARATOR . $user . $phpversion);
} else {
$base = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'silverstripe-cache';
// A typical Windows location for where sites are stored on IIS
$this->assertEquals(
$base . 'C--inetpub-wwwroot-silverstripe-test-project' . DIRECTORY_SEPARATOR . $user . $phpversion,
getTempFolder('C:\\inetpub\\wwwroot\\silverstripe-test-project'));
// A typical Mac OS X location for where sites are stored
$this->assertEquals(
$base . '-Users-joebloggs-Sites-silverstripe-test-project' . DIRECTORY_SEPARATOR . $user . $phpversion,
getTempFolder('/Users/joebloggs/Sites/silverstripe-test-project'));
// A typical Linux location for where sites are stored
$this->assertEquals(
$base . '-var-www-silverstripe-test-project' . DIRECTORY_SEPARATOR . $user . $phpversion,
getTempFolder('/var/www/silverstripe-test-project'));
}
}
public function tearDown() {
parent::tearDown();
$user = getTempFolderUsername();
$phpversion = '-php' . preg_replace('/[^\w-\.+]+/', '-', PHP_VERSION);
$base = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'silverstripe-cache' . $phpversion;
foreach(array(
'C--inetpub-wwwroot-silverstripe-test-project',
'-Users-joebloggs-Sites-silverstripe-test-project',
'-cache-var-www-silverstripe-test-project'
) as $dir) {
$path = $base . $dir;
if(file_exists($path)) {
rmdir($path . DIRECTORY_SEPARATOR . $user . $phpversion);
rmdir($path);
}
}
}
}