Clean up the test data in tearDownAfterClass()
The result of the listener should then be empty and can be removed
This commit is contained in:
parent
cbb9caf030
commit
84d358a761
|
@ -23,21 +23,127 @@
|
||||||
namespace Test;
|
namespace Test;
|
||||||
|
|
||||||
abstract class TestCase extends \PHPUnit_Framework_TestCase {
|
abstract class TestCase extends \PHPUnit_Framework_TestCase {
|
||||||
|
/**
|
||||||
|
* Returns a unique identifier as uniqid() is not reliable sometimes
|
||||||
|
*
|
||||||
|
* @param string $prefix
|
||||||
|
* @param int $length
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
protected function getUniqueID($prefix = '', $length = 13) {
|
protected function getUniqueID($prefix = '', $length = 13) {
|
||||||
// Do not use dots and slashes as we use the value for file names
|
|
||||||
return $prefix . \OC::$server->getSecureRandom()->getLowStrengthGenerator()->generate(
|
return $prefix . \OC::$server->getSecureRandom()->getLowStrengthGenerator()->generate(
|
||||||
$length,
|
$length,
|
||||||
|
// Do not use dots and slashes as we use the value for file names
|
||||||
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function tearDownAfterClass() {
|
public static function tearDownAfterClass() {
|
||||||
if (\OC_Util::runningOnWindows()) {
|
$dataDir = \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data-autotest');
|
||||||
$rootDirectory = \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data-autotest');
|
|
||||||
$mapper = new \OC\Files\Mapper($rootDirectory);
|
self::tearDownAfterClassCleanFileMapper($dataDir);
|
||||||
$mapper->removePath($rootDirectory, true, true);
|
self::tearDownAfterClassCleanStorages();
|
||||||
}
|
self::tearDownAfterClassCleanFileCache();
|
||||||
|
self::tearDownAfterClassCleanStrayDataFiles($dataDir);
|
||||||
|
self::tearDownAfterClassCleanStrayHooks();
|
||||||
|
self::tearDownAfterClassCleanProxies();
|
||||||
|
|
||||||
parent::tearDownAfterClass();
|
parent::tearDownAfterClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove all entries from the files map table
|
||||||
|
* @param string $dataDir
|
||||||
|
*/
|
||||||
|
static protected function tearDownAfterClassCleanFileMapper($dataDir) {
|
||||||
|
if (\OC_Util::runningOnWindows()) {
|
||||||
|
$mapper = new \OC\Files\Mapper($dataDir);
|
||||||
|
$mapper->removePath($dataDir, true, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove all entries from the storages table
|
||||||
|
* @throws \DatabaseException
|
||||||
|
*/
|
||||||
|
static protected function tearDownAfterClassCleanStorages() {
|
||||||
|
$sql = 'DELETE FROM `*PREFIX*storages`';
|
||||||
|
$query = \OC_DB::prepare($sql);
|
||||||
|
$query->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove all entries from the filecache table
|
||||||
|
* @throws \DatabaseException
|
||||||
|
*/
|
||||||
|
static protected function tearDownAfterClassCleanFileCache() {
|
||||||
|
$sql = 'DELETE FROM `*PREFIX*filecache`';
|
||||||
|
$query = \OC_DB::prepare($sql);
|
||||||
|
$query->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove all unused files from the data dir
|
||||||
|
*
|
||||||
|
* @param string $dataDir
|
||||||
|
*/
|
||||||
|
static protected function tearDownAfterClassCleanStrayDataFiles($dataDir) {
|
||||||
|
$knownEntries = array(
|
||||||
|
'owncloud.log' => true,
|
||||||
|
'owncloud.db' => true,
|
||||||
|
'.ocdata' => true,
|
||||||
|
'..' => true,
|
||||||
|
'.' => true,
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($dh = opendir($dataDir)) {
|
||||||
|
while (($file = readdir($dh)) !== false) {
|
||||||
|
if (!isset($knownEntries[$file])) {
|
||||||
|
self::tearDownAfterClassCleanStrayDataUnlinkDir($dataDir . '/' . $file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir($dh);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recursive delete files and folders from a given directory
|
||||||
|
*
|
||||||
|
* @param string $dir
|
||||||
|
*/
|
||||||
|
static protected function tearDownAfterClassCleanStrayDataUnlinkDir($dir) {
|
||||||
|
if ($dh = @opendir($dir)) {
|
||||||
|
while (($file = readdir($dh)) !== false) {
|
||||||
|
if ($file === '..' || $file === '.') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$path = $dir . '/' . $file;
|
||||||
|
if (is_dir($path)) {
|
||||||
|
self::tearDownAfterClassCleanStrayDataUnlinkDir($path);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
@unlink($path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir($dh);
|
||||||
|
}
|
||||||
|
@rmdir($dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean up the list of hooks
|
||||||
|
*/
|
||||||
|
static protected function tearDownAfterClassCleanStrayHooks() {
|
||||||
|
\OC_Hook::clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean up the list of file proxies
|
||||||
|
*
|
||||||
|
* Also reenables file proxies, in case a test disabled them
|
||||||
|
*/
|
||||||
|
static protected function tearDownAfterClassCleanProxies() {
|
||||||
|
\OC_FileProxy::$enabled = true;
|
||||||
|
\OC_FileProxy::clearProxies();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue