Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/undo-ransomware/ransomware_detection.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMatthias Held <ilovemilk@wusa.io>2018-09-14 21:37:58 +0300
committerMatthias Held <ilovemilk@wusa.io>2018-09-14 21:37:58 +0300
commit29a997e5b309ec320648c1f836238814ba4f4912 (patch)
treed5e56d80ac651fca723b81cae75af89cce78a5e1 /lib
parent0a3747e6f5a18dbfc60c2984df33be2991230b4e (diff)
Add tests
Signed-off-by: Matthias Held <matthias.held@uni-konstanz.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/Controller/ScanController.php94
1 files changed, 52 insertions, 42 deletions
diff --git a/lib/Controller/ScanController.php b/lib/Controller/ScanController.php
index da840b5..623631d 100644
--- a/lib/Controller/ScanController.php
+++ b/lib/Controller/ScanController.php
@@ -266,12 +266,59 @@ class ScanController extends OCSController
}
/**
+ * Just for testing purpose to mock the external static method.
+ *
+ * @return array
+ */
+ protected function getTrashFiles() {
+ return Helper::getTrashFiles("/", $this->userId, 'mtime', false);
+ }
+
+ /**
+ * Just for testing purpose to mock the external static method.
+ *
+ * @param string $trashPath
+ * @param array $pathInfo
+ * @param integer $timestamp
+ * @return boolean
+ */
+ protected function restoreFromTrashbin($trashPath, $name, $timestamp)
+ {
+ return Trashbin::restore($trashPath, $name, $timestamp);
+ }
+
+ /**
+ * Get last activity.
+ * Visibility 'protected' is that it's possible to mock the database access.
+ *
+ * @param $objectId
+ */
+ protected function getLastActivity($objectId)
+ {
+ $query = $this->connection->getQueryBuilder();
+ $query->select('*')->from('activity');
+ $query->where($query->expr()->eq('affecteduser', $query->createNamedParameter($this->userId)))
+ ->andWhere($query->expr()->eq('object_id', $query->createNamedParameter($objectId)));
+ $result = $query->execute();
+ while ($row = $result->fetch()) {
+ $rows[] = $row;
+ }
+ $result->closeCursor();
+ if (is_array($rows)) {
+ return array_pop($rows);
+ } else {
+ $this->logger->debug('getLastActivity: No activity found.', array('app' => Application::APP_ID));
+ return 0;
+ }
+ }
+
+ /**
* Builds a file operations from a file info array.
*
* @param array $file
* @return FileOperation
*/
- protected function buildFileOperation($file)
+ private function buildFileOperation($file)
{
$fileOperation = new FileOperation();
$fileOperation->setUserId($this->userId);
@@ -319,38 +366,14 @@ class ScanController extends OCSController
}
/**
- * Get last activity.
- *
- * @param $objectId
- */
- protected function getLastActivity($objectId)
- {
- $query = $this->connection->getQueryBuilder();
- $query->select('*')->from('activity');
- $query->where($query->expr()->eq('affecteduser', $query->createNamedParameter($this->userId)))
- ->andWhere($query->expr()->eq('object_id', $query->createNamedParameter($objectId)));
- $result = $query->execute();
- while ($row = $result->fetch()) {
- $rows[] = $row;
- }
- $result->closeCursor();
- if (is_array($rows)) {
- return array_pop($rows);
- } else {
- $this->logger->debug('getLastActivity: No activity found.', array('app' => Application::APP_ID));
- return 0;
- }
- }
-
- /**
* Get trash storage structure.
*
* @return StorageStructure
*/
- protected function getTrashStorageStructure()
+ private function getTrashStorageStructure()
{
$storageStructure = new StorageStructure(0, []);
- $nodes = Helper::getTrashFiles("/", $this->userId, 'mtime', false);
+ $nodes = $this->getTrashFiles();
foreach ($nodes as $node) {
$storageStructure->addFile($node);
$storageStructure->increaseNumberOfFiles();
@@ -365,7 +388,7 @@ class ScanController extends OCSController
*
* @return StorageStructure
*/
- protected function getStorageStructure($node)
+ private function getStorageStructure($node)
{
// set count for node to 0
$storageStructure = new StorageStructure(0, []);
@@ -404,7 +427,7 @@ class ScanController extends OCSController
*
* @return bool
*/
- protected function deleteFromStorage($path)
+ private function deleteFromStorage($path)
{
try {
$node = $this->userFolder->get($path);
@@ -422,17 +445,4 @@ class ScanController extends OCSController
return true;
}
}
-
- /**
- * Restores file from trash bin.
- *
- * @param string $trashPath
- * @param array $pathInfo
- * @param integer $timestamp
- * @return boolean
- */
- protected function restoreFromTrashbin($trashPath, $name, $timestamp)
- {
- return Trashbin::restore($trashPath, $name, $timestamp);
- }
}