mirror of
https://github.com/silverstripe/silverstripe-dms
synced 2024-10-22 14:05:56 +02:00
43 lines
1.2 KiB
PHP
43 lines
1.2 KiB
PHP
<?php
|
|
|
|
class DMSFilesystemTestHelper
|
|
{
|
|
/**
|
|
* Files that are added to the DMS asset directory by the DMS instance. They will be removed after running tests.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected static $dmsFiles = array('.htaccess', 'web.config');
|
|
|
|
/**
|
|
* Deletes a directory and all files within it, or a file. Will automatically prepend the base path.
|
|
*
|
|
* This only work while a unit test is running for safety reasons.
|
|
*
|
|
* @param string $path
|
|
*/
|
|
public static function delete($path)
|
|
{
|
|
if (!SapphireTest::is_running_test() || !file_exists($path)) {
|
|
return false;
|
|
}
|
|
|
|
$path = BASE_PATH . DIRECTORY_SEPARATOR . $path;
|
|
if (is_dir($path)) {
|
|
$files = new RecursiveIteratorIterator(
|
|
new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS),
|
|
RecursiveIteratorIterator::CHILD_FIRST
|
|
);
|
|
|
|
foreach ($files as $fileinfo) {
|
|
$action = $fileinfo->isDir() ? 'rmdir' : 'unlink';
|
|
$action($fileinfo->getRealPath());
|
|
}
|
|
|
|
rmdir($path);
|
|
} else {
|
|
unlink($path);
|
|
}
|
|
}
|
|
}
|