2009-12-16 06:36:35 +01:00
|
|
|
<?php
|
2016-08-19 00:51:35 +02:00
|
|
|
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\Control\Director;
|
|
|
|
|
2009-12-16 06:36:35 +01:00
|
|
|
/**
|
2012-03-24 04:38:57 +01:00
|
|
|
* Tests for the core of SilverStripe, such as how the temporary
|
2009-12-16 06:36:35 +01:00
|
|
|
* directory is determined throughout the framework.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2009-12-16 06:36:35 +01:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
class CoreTest extends SapphireTest {
|
|
|
|
|
2009-12-16 06:36:48 +01:00
|
|
|
protected $tempPath;
|
2009-12-16 06:36:35 +01:00
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
2013-10-03 03:49:18 +02:00
|
|
|
$this->tempPath = Director::baseFolder() . DIRECTORY_SEPARATOR . 'silverstripe-cache';
|
2009-12-16 06:36:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetTempPathInProject() {
|
2013-10-03 03:49:18 +02:00
|
|
|
$user = getTempFolderUsername();
|
|
|
|
|
2009-12-16 06:36:48 +01:00
|
|
|
if(file_exists($this->tempPath)) {
|
2013-10-03 03:49:18 +02:00
|
|
|
$this->assertEquals(getTempFolder(BASE_PATH), $this->tempPath . DIRECTORY_SEPARATOR . $user);
|
2009-12-16 06:36:48 +01:00
|
|
|
} else {
|
2013-03-18 03:30:09 +01:00
|
|
|
$user = getTempFolderUsername();
|
2016-01-06 00:34:58 +01:00
|
|
|
$base = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'silverstripe-cache-php' .
|
2015-02-12 02:20:54 +01:00
|
|
|
preg_replace('/[^\w-\.+]+/', '-', PHP_VERSION);
|
2013-03-18 03:30:09 +01:00
|
|
|
|
2009-12-16 06:36:48 +01:00
|
|
|
// A typical Windows location for where sites are stored on IIS
|
2015-02-12 02:20:54 +01:00
|
|
|
$this->assertEquals(
|
|
|
|
$base . 'C--inetpub-wwwroot-silverstripe-test-project' . DIRECTORY_SEPARATOR . $user,
|
2013-03-18 03:30:09 +01:00
|
|
|
getTempFolder('C:\\inetpub\\wwwroot\\silverstripe-test-project'));
|
2010-10-19 06:52:46 +02:00
|
|
|
|
2009-12-16 06:36:48 +01:00
|
|
|
// A typical Mac OS X location for where sites are stored
|
2015-02-12 02:20:54 +01:00
|
|
|
$this->assertEquals(
|
|
|
|
$base . '-Users-joebloggs-Sites-silverstripe-test-project' . DIRECTORY_SEPARATOR . $user,
|
2013-03-18 03:30:09 +01:00
|
|
|
getTempFolder('/Users/joebloggs/Sites/silverstripe-test-project'));
|
2011-01-26 23:51:08 +01:00
|
|
|
|
2009-12-16 06:36:48 +01:00
|
|
|
// A typical Linux location for where sites are stored
|
2015-02-12 02:20:54 +01:00
|
|
|
$this->assertEquals(
|
|
|
|
$base . '-var-www-silverstripe-test-project' . DIRECTORY_SEPARATOR . $user,
|
2013-03-18 03:30:09 +01:00
|
|
|
getTempFolder('/var/www/silverstripe-test-project'));
|
2009-12-16 06:36:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-19 06:52:46 +02:00
|
|
|
public function tearDown() {
|
|
|
|
parent::tearDown();
|
2013-03-18 03:30:09 +01:00
|
|
|
$user = getTempFolderUsername();
|
2016-01-06 00:34:58 +01:00
|
|
|
$base = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'silverstripe-cache-php' .
|
2015-02-12 02:20:54 +01:00
|
|
|
preg_replace('/[^\w-\.+]+/', '-', PHP_VERSION);
|
2013-10-03 03:49:18 +02:00
|
|
|
foreach(array(
|
2015-02-12 02:20:54 +01:00
|
|
|
'C--inetpub-wwwroot-silverstripe-test-project',
|
|
|
|
'-Users-joebloggs-Sites-silverstripe-test-project',
|
|
|
|
'-cache-var-www-silverstripe-test-project'
|
2013-10-03 03:49:18 +02:00
|
|
|
) as $dir) {
|
2015-02-12 02:20:54 +01:00
|
|
|
$path = $base . $dir;
|
2013-10-03 03:49:18 +02:00
|
|
|
if(file_exists($path)) {
|
|
|
|
rmdir($path . DIRECTORY_SEPARATOR . $user);
|
|
|
|
rmdir($path);
|
2015-02-12 02:20:54 +01:00
|
|
|
}
|
2010-10-19 06:52:46 +02:00
|
|
|
}
|
2015-02-12 02:20:54 +01:00
|
|
|
}
|
2010-10-19 06:52:46 +02:00
|
|
|
|
2012-03-24 04:38:57 +01:00
|
|
|
}
|