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