mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-09 02:06:32 +02:00
[ticket/10631] Functional acp_extensions test, cleanup
PHPBB3-10631
This commit is contained in:
committed by
Unknown Bliss
parent
500879520c
commit
36465c9a20
@@ -115,4 +115,112 @@ class phpbb_test_case_helpers
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursive directory copying function
|
||||
*
|
||||
* @param string $source
|
||||
* @param string $dest
|
||||
* @return array list of files copied
|
||||
*/
|
||||
public function copy_dir($source, $dest)
|
||||
{
|
||||
$source = (substr($source, -1) == '/') ? $source : $source . '/';
|
||||
$dest = (substr($dest, -1) == '/') ? $dest : $dest . '/';
|
||||
|
||||
$copied_files = array();
|
||||
|
||||
if (!is_dir($dest))
|
||||
{
|
||||
$this->makedirs($dest);
|
||||
}
|
||||
|
||||
$files = scandir($source);
|
||||
foreach ($files as $file)
|
||||
{
|
||||
if ($file == '.' || $file == '..')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_dir($source . $file))
|
||||
{
|
||||
$created_dir = false;
|
||||
if (!is_dir($dest . $file))
|
||||
{
|
||||
$created_dir = true;
|
||||
$this->makedirs($dest . $file);
|
||||
}
|
||||
|
||||
$copied_files = array_merge($copied_files, self::copy_dir($source . $file, $dest . $file));
|
||||
|
||||
if ($created_dir)
|
||||
{
|
||||
$copied_files[] = $dest . $file;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!file_exists($dest . $file))
|
||||
{
|
||||
copy($source . $file, $dest . $file);
|
||||
|
||||
$copied_files[] = $dest . $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $copied_files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove files/directories that are listed in an array
|
||||
* Designed for use with $this->copy_dir()
|
||||
*
|
||||
* @param array $file_list
|
||||
*/
|
||||
public function remove_files($file_list)
|
||||
{
|
||||
foreach ($file_list as $file)
|
||||
{
|
||||
if (is_dir($file))
|
||||
{
|
||||
rmdir($file);
|
||||
}
|
||||
else
|
||||
{
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty directory (remove any subdirectories/files below)
|
||||
*
|
||||
* @param array $file_list
|
||||
*/
|
||||
public function empty_dir($path)
|
||||
{
|
||||
$path = (substr($path, -1) == '/') ? $path : $path . '/';
|
||||
|
||||
$files = scandir($path);
|
||||
foreach ($files as $file)
|
||||
{
|
||||
if ($file == '.' || $file == '..')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_dir($path . $file))
|
||||
{
|
||||
$this->empty_dir($path . $file);
|
||||
|
||||
rmdir($path . $file);
|
||||
}
|
||||
else
|
||||
{
|
||||
unlink($path . $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user