add some more test cases for the scanner

This commit is contained in:
Robin Appelman 2012-10-03 11:40:09 +02:00
parent 3c8e5ea358
commit 85be00be65
2 changed files with 26 additions and 3 deletions

View File

@ -77,12 +77,14 @@ class Scanner {
* @param SCAN_RECURSIVE/SCAN_SHALLOW $recursive
* @return int the size of the scanned folder or -1 if the size is unknown at this stage
*/
public function scan($path, $recursive) {
public function scan($path, $recursive = self::SCAN_RECURSIVE) {
$this->scanFile($path);
$size = 0;
if ($dh = $this->storage->opendir($path)) {
while ($file = readdir($dh)) {
if ($file !== '.' and $file !== '..') {
$child = $path . '/' . $file;
$child = ($path !== '') ? $path . '/' . $file : $file;
$data = $this->scanFile($child);
if ($recursive === self::SCAN_RECURSIVE and $data['mimetype'] === 'httpd/unix-directory') {
$data['size'] = $this->scan($child, self::SCAN_RECURSIVE);

View File

@ -33,6 +33,27 @@ class Scanner extends \UnitTestCase {
$cachedData = $this->cache->get('foo.txt');
$this->assertEqual($cachedData['size'], strlen($data));
$this->assertEqual($cachedData['mimetype'], 'text/plain');
$this->assertNotEqual($cachedData['parent'], -1); //parent folders should be scanned automatically
$data = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png');
$this->storage->file_put_contents('foo.png', $data);
$this->scanner->scanFile('foo.png');
$this->assertEqual($this->cache->inCache('foo.png'), true);
$cachedData = $this->cache->get('foo.png');
$this->assertEqual($cachedData['size'], strlen($data));
$this->assertEqual($cachedData['mimetype'], 'image/png');
}
function testFolder() {
$textData = "dummy file data\n";
$imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png');
$this->storage->file_put_contents('foo.txt', $textData);
$this->storage->file_put_contents('foo.png', $imgData);
$this->scanner->scan('');
$this->assertEqual($this->cache->inCache('foo.txt'), true);
$this->assertEqual($this->cache->inCache('foo.png'), true);
}
function setUp() {
@ -42,6 +63,6 @@ class Scanner extends \UnitTestCase {
}
function tearDown() {
// $this->cache->clear();
$this->cache->clear();
}
}