From 29a997e5b309ec320648c1f836238814ba4f4912 Mon Sep 17 00:00:00 2001 From: Matthias Held Date: Fri, 14 Sep 2018 20:37:58 +0200 Subject: Add tests Signed-off-by: Matthias Held --- lib/Controller/ScanController.php | 94 ++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 42 deletions(-) (limited to 'lib') 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 @@ -265,13 +265,60 @@ 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); @@ -318,39 +365,15 @@ class ScanController extends OCSController return $fileOperation; } - /** - * 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); - } } -- cgit v1.2.3