summaryrefslogtreecommitdiffstats
path: root/tests/lib/testcase.php
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2014-11-19 14:40:15 +0100
committerJoas Schilling <nickvergessen@gmx.de>2014-11-20 15:26:26 +0100
commit84d358a7615f70944706d7e3095f372b8a4a29c8 (patch)
tree18b99e3069f4b4849b63a032ed2d05a14689fdbd /tests/lib/testcase.php
parentcbb9caf03083cc083491e292143ee53871920106 (diff)
downloadnextcloud-server-84d358a7615f70944706d7e3095f372b8a4a29c8.tar.gz
nextcloud-server-84d358a7615f70944706d7e3095f372b8a4a29c8.zip
Clean up the test data in tearDownAfterClass()
The result of the listener should then be empty and can be removed
Diffstat (limited to 'tests/lib/testcase.php')
-rw-r--r--tests/lib/testcase.php116
1 files changed, 111 insertions, 5 deletions
diff --git a/tests/lib/testcase.php b/tests/lib/testcase.php
index 315cd6858ed..e6f5ca71dac 100644
--- a/tests/lib/testcase.php
+++ b/tests/lib/testcase.php
@@ -23,21 +23,127 @@
namespace Test;
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) {
- // Do not use dots and slashes as we use the value for file names
return $prefix . \OC::$server->getSecureRandom()->getLowStrengthGenerator()->generate(
$length,
+ // Do not use dots and slashes as we use the value for file names
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
);
}
public static function tearDownAfterClass() {
+ $dataDir = \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data-autotest');
+
+ self::tearDownAfterClassCleanFileMapper($dataDir);
+ self::tearDownAfterClassCleanStorages();
+ self::tearDownAfterClassCleanFileCache();
+ self::tearDownAfterClassCleanStrayDataFiles($dataDir);
+ self::tearDownAfterClassCleanStrayHooks();
+ self::tearDownAfterClassCleanProxies();
+
+ parent::tearDownAfterClass();
+ }
+
+ /**
+ * Remove all entries from the files map table
+ * @param string $dataDir
+ */
+ static protected function tearDownAfterClassCleanFileMapper($dataDir) {
if (\OC_Util::runningOnWindows()) {
- $rootDirectory = \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data-autotest');
- $mapper = new \OC\Files\Mapper($rootDirectory);
- $mapper->removePath($rootDirectory, true, true);
+ $mapper = new \OC\Files\Mapper($dataDir);
+ $mapper->removePath($dataDir, true, true);
}
+ }
- parent::tearDownAfterClass();
+ /**
+ * 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();
}
}