summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/bootstrap.php19
-rw-r--r--tests/enable_all.php3
-rw-r--r--tests/lib/archive.php36
-rw-r--r--tests/lib/cache.php10
-rw-r--r--tests/lib/cache/file.php6
-rw-r--r--tests/lib/db.php40
-rw-r--r--tests/lib/dbschema.php2
-rw-r--r--tests/lib/files/cache/cache.php215
-rw-r--r--tests/lib/files/cache/permissions.php56
-rw-r--r--tests/lib/files/cache/scanner.php141
-rw-r--r--tests/lib/files/cache/updater.php147
-rw-r--r--tests/lib/files/cache/watcher.php121
-rw-r--r--tests/lib/files/filesystem.php110
-rw-r--r--tests/lib/files/mount.php41
-rw-r--r--tests/lib/files/storage/commontest.php (renamed from tests/lib/filestorage/commontest.php)9
-rw-r--r--tests/lib/files/storage/local.php (renamed from tests/lib/filestorage/local.php)10
-rw-r--r--tests/lib/files/storage/storage.php (renamed from tests/lib/filestorage.php)78
-rw-r--r--tests/lib/files/view.php251
-rw-r--r--tests/lib/filesystem.php139
-rw-r--r--tests/lib/geo.php2
-rw-r--r--tests/lib/group.php56
-rw-r--r--tests/lib/group/backend.php20
-rw-r--r--tests/lib/helper.php2
-rw-r--r--tests/lib/share/share.php2
-rw-r--r--tests/lib/streamwrappers.php105
-rw-r--r--tests/lib/template.php14
-rw-r--r--tests/lib/user/backend.php8
-rw-r--r--tests/lib/util.php2
-rw-r--r--tests/lib/vcategories.php22
-rw-r--r--tests/phpunit.xml3
30 files changed, 1309 insertions, 361 deletions
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 115a15883a0..b97161ee6e4 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -8,24 +8,5 @@ if(!class_exists('PHPUnit_Framework_TestCase')) {
require_once('PHPUnit/Autoload.php');
}
-//SimpleTest compatibility
-abstract class UnitTestCase extends PHPUnit_Framework_TestCase{
- function assertEqual($expected, $actual, $string='') {
- $this->assertEquals($expected, $actual, $string);
- }
-
- function assertNotEqual($expected, $actual, $string='') {
- $this->assertNotEquals($expected, $actual, $string);
- }
-
- static function assertTrue($actual, $string='') {
- parent::assertTrue((bool)$actual, $string);
- }
-
- static function assertFalse($actual, $string='') {
- parent::assertFalse((bool)$actual, $string);
- }
-}
-
OC_Hook::clear();
OC_Log::$enabled = false;
diff --git a/tests/enable_all.php b/tests/enable_all.php
index 16838398f17..44af0115650 100644
--- a/tests/enable_all.php
+++ b/tests/enable_all.php
@@ -10,7 +10,8 @@ require_once __DIR__.'/../lib/base.php';
OC_App::enable('calendar');
OC_App::enable('contacts');
-OC_App::enable('apptemplate_advanced');
+OC_App::enable('apptemplateadvanced');
+OC_App::enable('appframework');
#OC_App::enable('files_archive');
#OC_App::enable('mozilla_sync');
#OC_App::enable('news');
diff --git a/tests/lib/archive.php b/tests/lib/archive.php
index cd2ca6630a5..be5cc897a67 100644
--- a/tests/lib/archive.php
+++ b/tests/lib/archive.php
@@ -6,7 +6,7 @@
* See the COPYING-README file.
*/
-abstract class Test_Archive extends UnitTestCase {
+abstract class Test_Archive extends PHPUnit_Framework_TestCase {
/**
* @var OC_Archive
*/
@@ -27,7 +27,7 @@ abstract class Test_Archive extends UnitTestCase {
$this->instance=$this->getExisting();
$allFiles=$this->instance->getFiles();
$expected=array('lorem.txt','logo-wide.png','dir/', 'dir/lorem.txt');
- $this->assertEqual(4, count($allFiles), 'only found '.count($allFiles).' out of 4 expected files');
+ $this->assertEquals(4, count($allFiles), 'only found '.count($allFiles).' out of 4 expected files');
foreach($expected as $file) {
$this->assertContains($file, $allFiles, 'cant find '. $file . ' in archive');
$this->assertTrue($this->instance->fileExists($file), 'file '.$file.' does not exist in archive');
@@ -36,14 +36,14 @@ abstract class Test_Archive extends UnitTestCase {
$rootContent=$this->instance->getFolder('');
$expected=array('lorem.txt','logo-wide.png', 'dir/');
- $this->assertEqual(3, count($rootContent));
+ $this->assertEquals(3, count($rootContent));
foreach($expected as $file) {
$this->assertContains($file, $rootContent, 'cant find '. $file . ' in archive');
}
$dirContent=$this->instance->getFolder('dir/');
$expected=array('lorem.txt');
- $this->assertEqual(1, count($dirContent));
+ $this->assertEquals(1, count($dirContent));
foreach($expected as $file) {
$this->assertContains($file, $dirContent, 'cant find '. $file . ' in archive');
}
@@ -53,36 +53,36 @@ abstract class Test_Archive extends UnitTestCase {
$this->instance=$this->getExisting();
$dir=OC::$SERVERROOT.'/tests/data';
$textFile=$dir.'/lorem.txt';
- $this->assertEqual(file_get_contents($textFile), $this->instance->getFile('lorem.txt'));
+ $this->assertEquals(file_get_contents($textFile), $this->instance->getFile('lorem.txt'));
$tmpFile=OCP\Files::tmpFile('.txt');
$this->instance->extractFile('lorem.txt', $tmpFile);
- $this->assertEqual(file_get_contents($textFile), file_get_contents($tmpFile));
+ $this->assertEquals(file_get_contents($textFile), file_get_contents($tmpFile));
}
public function testWrite() {
$dir=OC::$SERVERROOT.'/tests/data';
$textFile=$dir.'/lorem.txt';
$this->instance=$this->getNew();
- $this->assertEqual(0, count($this->instance->getFiles()));
+ $this->assertEquals(0, count($this->instance->getFiles()));
$this->instance->addFile('lorem.txt', $textFile);
- $this->assertEqual(1, count($this->instance->getFiles()));
+ $this->assertEquals(1, count($this->instance->getFiles()));
$this->assertTrue($this->instance->fileExists('lorem.txt'));
$this->assertFalse($this->instance->fileExists('lorem.txt/'));
- $this->assertEqual(file_get_contents($textFile), $this->instance->getFile('lorem.txt'));
+ $this->assertEquals(file_get_contents($textFile), $this->instance->getFile('lorem.txt'));
$this->instance->addFile('lorem.txt', 'foobar');
- $this->assertEqual('foobar', $this->instance->getFile('lorem.txt'));
+ $this->assertEquals('foobar', $this->instance->getFile('lorem.txt'));
}
public function testReadStream() {
$dir=OC::$SERVERROOT.'/tests/data';
$this->instance=$this->getExisting();
$fh=$this->instance->getStream('lorem.txt', 'r');
- $this->assertTrue($fh);
+ $this->assertTrue((bool)$fh);
$content=fread($fh, $this->instance->filesize('lorem.txt'));
fclose($fh);
- $this->assertEqual(file_get_contents($dir.'/lorem.txt'), $content);
+ $this->assertEquals(file_get_contents($dir.'/lorem.txt'), $content);
}
public function testWriteStream() {
$dir=OC::$SERVERROOT.'/tests/data';
@@ -93,7 +93,7 @@ abstract class Test_Archive extends UnitTestCase {
fclose($source);
fclose($fh);
$this->assertTrue($this->instance->fileExists('lorem.txt'));
- $this->assertEqual(file_get_contents($dir.'/lorem.txt'), $this->instance->getFile('lorem.txt'));
+ $this->assertEquals(file_get_contents($dir.'/lorem.txt'), $this->instance->getFile('lorem.txt'));
}
public function testFolder() {
$this->instance=$this->getNew();
@@ -111,10 +111,10 @@ abstract class Test_Archive extends UnitTestCase {
$this->instance=$this->getExisting();
$tmpDir=OCP\Files::tmpFolder();
$this->instance->extract($tmpDir);
- $this->assertEqual(true, file_exists($tmpDir.'lorem.txt'));
- $this->assertEqual(true, file_exists($tmpDir.'dir/lorem.txt'));
- $this->assertEqual(true, file_exists($tmpDir.'logo-wide.png'));
- $this->assertEqual(file_get_contents($dir.'/lorem.txt'), file_get_contents($tmpDir.'lorem.txt'));
+ $this->assertEquals(true, file_exists($tmpDir.'lorem.txt'));
+ $this->assertEquals(true, file_exists($tmpDir.'dir/lorem.txt'));
+ $this->assertEquals(true, file_exists($tmpDir.'logo-wide.png'));
+ $this->assertEquals(file_get_contents($dir.'/lorem.txt'), file_get_contents($tmpDir.'lorem.txt'));
OCP\Files::rmdirr($tmpDir);
}
public function testMoveRemove() {
@@ -126,7 +126,7 @@ abstract class Test_Archive extends UnitTestCase {
$this->instance->rename('lorem.txt', 'target.txt');
$this->assertTrue($this->instance->fileExists('target.txt'));
$this->assertFalse($this->instance->fileExists('lorem.txt'));
- $this->assertEqual(file_get_contents($textFile), $this->instance->getFile('target.txt'));
+ $this->assertEquals(file_get_contents($textFile), $this->instance->getFile('target.txt'));
$this->instance->remove('target.txt');
$this->assertFalse($this->instance->fileExists('target.txt'));
}
diff --git a/tests/lib/cache.php b/tests/lib/cache.php
index 1a1287ff135..3dcf39f7d60 100644
--- a/tests/lib/cache.php
+++ b/tests/lib/cache.php
@@ -6,7 +6,7 @@
* See the COPYING-README file.
*/
-abstract class Test_Cache extends UnitTestCase {
+abstract class Test_Cache extends PHPUnit_Framework_TestCase {
/**
* @var OC_Cache cache;
*/
@@ -26,19 +26,19 @@ abstract class Test_Cache extends UnitTestCase {
$this->instance->set('value1', $value);
$this->assertTrue($this->instance->hasKey('value1'));
$received=$this->instance->get('value1');
- $this->assertEqual($value, $received, 'Value recieved from cache not equal to the original');
+ $this->assertEquals($value, $received, 'Value recieved from cache not equal to the original');
$value='ipsum lorum';
$this->instance->set('value1', $value);
$received=$this->instance->get('value1');
- $this->assertEqual($value, $received, 'Value not overwritten by second set');
+ $this->assertEquals($value, $received, 'Value not overwritten by second set');
$value2='foobar';
$this->instance->set('value2', $value2);
$received2=$this->instance->get('value2');
$this->assertTrue($this->instance->hasKey('value1'));
$this->assertTrue($this->instance->hasKey('value2'));
- $this->assertEqual($value, $received, 'Value changed while setting other variable');
- $this->assertEqual($value2, $received2, 'Second value not equal to original');
+ $this->assertEquals($value, $received, 'Value changed while setting other variable');
+ $this->assertEquals($value2, $received2, 'Second value not equal to original');
$this->assertFalse($this->instance->hasKey('not_set'));
$this->assertNull($this->instance->get('not_set'), 'Unset value not equal to null');
diff --git a/tests/lib/cache/file.php b/tests/lib/cache/file.php
index d64627198e0..5dcd3268804 100644
--- a/tests/lib/cache/file.php
+++ b/tests/lib/cache/file.php
@@ -38,8 +38,8 @@ class Test_Cache_File extends Test_Cache {
}
//set up temporary storage
- OC_Filesystem::clearMounts();
- OC_Filesystem::mount('OC_Filestorage_Temporary', array(), '/');
+ \OC\Files\Filesystem::clearMounts();
+ \OC\Files\Filesystem::mount('\OC\Files\Storage\Temporary',array(),'/');
OC_User::clearBackends();
OC_User::useBackend(new OC_User_Dummy());
@@ -51,7 +51,7 @@ class Test_Cache_File extends Test_Cache {
OC_User::setUserId('test');
//set up the users dir
- $rootView=new OC_FilesystemView('');
+ $rootView=new \OC\Files\View('');
$rootView->mkdir('/test');
$this->instance=new OC_Cache_File();
diff --git a/tests/lib/db.php b/tests/lib/db.php
index c2eb38dae83..440f3fb6bfd 100644
--- a/tests/lib/db.php
+++ b/tests/lib/db.php
@@ -6,7 +6,7 @@
* See the COPYING-README file.
*/
-class Test_DB extends UnitTestCase {
+class Test_DB extends PHPUnit_Framework_TestCase {
protected $backupGlobals = FALSE;
protected static $schema_file = 'static://test_db_scheme';
@@ -35,18 +35,18 @@ class Test_DB extends UnitTestCase {
public function testQuotes() {
$query = OC_DB::prepare('SELECT `fullname` FROM *PREFIX*'.$this->table2.' WHERE `uri` = ?');
$result = $query->execute(array('uri_1'));
- $this->assertTrue($result);
+ $this->assertTrue((bool)$result);
$row = $result->fetchRow();
$this->assertFalse($row);
$query = OC_DB::prepare('INSERT INTO *PREFIX*'.$this->table2.' (`fullname`,`uri`) VALUES (?,?)');
$result = $query->execute(array('fullname test', 'uri_1'));
- $this->assertTrue($result);
+ $this->assertTrue((bool)$result);
$query = OC_DB::prepare('SELECT `fullname`,`uri` FROM *PREFIX*'.$this->table2.' WHERE `uri` = ?');
$result = $query->execute(array('uri_1'));
- $this->assertTrue($result);
+ $this->assertTrue((bool)$result);
$row = $result->fetchRow();
$this->assertArrayHasKey('fullname', $row);
- $this->assertEqual($row['fullname'], 'fullname test');
+ $this->assertEquals($row['fullname'], 'fullname test');
$row = $result->fetchRow();
$this->assertFalse($row);
}
@@ -54,19 +54,19 @@ class Test_DB extends UnitTestCase {
public function testNOW() {
$query = OC_DB::prepare('INSERT INTO *PREFIX*'.$this->table2.' (`fullname`,`uri`) VALUES (NOW(),?)');
$result = $query->execute(array('uri_2'));
- $this->assertTrue($result);
+ $this->assertTrue((bool)$result);
$query = OC_DB::prepare('SELECT `fullname`,`uri` FROM *PREFIX*'.$this->table2.' WHERE `uri` = ?');
$result = $query->execute(array('uri_2'));
- $this->assertTrue($result);
+ $this->assertTrue((bool)$result);
}
public function testUNIX_TIMESTAMP() {
$query = OC_DB::prepare('INSERT INTO *PREFIX*'.$this->table2.' (`fullname`,`uri`) VALUES (UNIX_TIMESTAMP(),?)');
$result = $query->execute(array('uri_3'));
- $this->assertTrue($result);
+ $this->assertTrue((bool)$result);
$query = OC_DB::prepare('SELECT `fullname`,`uri` FROM *PREFIX*'.$this->table2.' WHERE `uri` = ?');
$result = $query->execute(array('uri_3'));
- $this->assertTrue($result);
+ $this->assertTrue((bool)$result);
}
public function testinsertIfNotExist() {
@@ -85,13 +85,13 @@ class Test_DB extends UnitTestCase {
'type' => $entry['type'],
'category' => $entry['category'],
));
- $this->assertTrue($result);
+ $this->assertTrue((bool)$result);
}
$query = OC_DB::prepare('SELECT * FROM *PREFIX*'.$this->table3);
$result = $query->execute();
- $this->assertTrue($result);
- $this->assertEqual('4', $result->numRows());
+ $this->assertTrue((bool)$result);
+ $this->assertEquals('4', $result->numRows());
}
public function testinsertIfNotExistDontOverwrite() {
@@ -102,14 +102,14 @@ class Test_DB extends UnitTestCase {
// Normal test to have same known data inserted.
$query = OC_DB::prepare('INSERT INTO *PREFIX*'.$this->table2.' (`fullname`, `uri`, `carddata`) VALUES (?, ?, ?)');
$result = $query->execute(array($fullname, $uri, $carddata));
- $this->assertTrue($result);
+ $this->assertTrue((bool)$result);
$query = OC_DB::prepare('SELECT `fullname`, `uri`, `carddata` FROM *PREFIX*'.$this->table2.' WHERE `uri` = ?');
$result = $query->execute(array($uri));
- $this->assertTrue($result);
+ $this->assertTrue((bool)$result);
$row = $result->fetchRow();
$this->assertArrayHasKey('carddata', $row);
- $this->assertEqual($carddata, $row['carddata']);
- $this->assertEqual('1', $result->numRows());
+ $this->assertEquals($carddata, $row['carddata']);
+ $this->assertEquals('1', $result->numRows());
// Try to insert a new row
$result = OC_DB::insertIfNotExist('*PREFIX*'.$this->table2,
@@ -117,17 +117,17 @@ class Test_DB extends UnitTestCase {
'fullname' => $fullname,
'uri' => $uri,
));
- $this->assertTrue($result);
+ $this->assertTrue((bool)$result);
$query = OC_DB::prepare('SELECT `fullname`, `uri`, `carddata` FROM *PREFIX*'.$this->table2.' WHERE `uri` = ?');
$result = $query->execute(array($uri));
- $this->assertTrue($result);
+ $this->assertTrue((bool)$result);
$row = $result->fetchRow();
$this->assertArrayHasKey('carddata', $row);
// Test that previously inserted data isn't overwritten
- $this->assertEqual($carddata, $row['carddata']);
+ $this->assertEquals($carddata, $row['carddata']);
// And that a new row hasn't been inserted.
- $this->assertEqual('1', $result->numRows());
+ $this->assertEquals('1', $result->numRows());
}
}
diff --git a/tests/lib/dbschema.php b/tests/lib/dbschema.php
index cd408160afb..fb60ce7dbb7 100644
--- a/tests/lib/dbschema.php
+++ b/tests/lib/dbschema.php
@@ -6,7 +6,7 @@
* See the COPYING-README file.
*/
-class Test_DBSchema extends UnitTestCase {
+class Test_DBSchema extends PHPUnit_Framework_TestCase {
protected static $schema_file = 'static://test_db_scheme';
protected static $schema_file2 = 'static://test_db_scheme2';
protected $test_prefix;
diff --git a/tests/lib/files/cache/cache.php b/tests/lib/files/cache/cache.php
new file mode 100644
index 00000000000..c466fbb63e7
--- /dev/null
+++ b/tests/lib/files/cache/cache.php
@@ -0,0 +1,215 @@
+<?php
+/**
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\Files\Cache;
+
+class Cache extends \PHPUnit_Framework_TestCase {
+ /**
+ * @var \OC\Files\Storage\Temporary $storage;
+ */
+ private $storage;
+
+ /**
+ * @var \OC\Files\Cache\Cache $cache
+ */
+ private $cache;
+
+ public function testSimple() {
+ $file1 = 'foo';
+ $file2 = 'foo/bar';
+ $data1 = array('size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder');
+ $data2 = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'foo/file');
+
+ $this->assertFalse($this->cache->inCache($file1));
+ $this->assertEquals($this->cache->get($file1), null);
+
+ $id1 = $this->cache->put($file1, $data1);
+ $this->assertTrue($this->cache->inCache($file1));
+ $cacheData1 = $this->cache->get($file1);
+ foreach ($data1 as $key => $value) {
+ $this->assertEquals($value, $cacheData1[$key]);
+ }
+ $this->assertEquals($cacheData1['mimepart'], 'foo');
+ $this->assertEquals($cacheData1['fileid'], $id1);
+ $this->assertEquals($id1, $this->cache->getId($file1));
+
+ $this->assertFalse($this->cache->inCache($file2));
+ $id2 = $this->cache->put($file2, $data2);
+ $this->assertTrue($this->cache->inCache($file2));
+ $cacheData2 = $this->cache->get($file2);
+ foreach ($data2 as $key => $value) {
+ $this->assertEquals($value, $cacheData2[$key]);
+ }
+ $this->assertEquals($cacheData1['fileid'], $cacheData2['parent']);
+ $this->assertEquals($cacheData2['fileid'], $id2);
+ $this->assertEquals($id2, $this->cache->getId($file2));
+ $this->assertEquals($id1, $this->cache->getParentId($file2));
+
+ $newSize = 1050;
+ $newId2 = $this->cache->put($file2, array('size' => $newSize));
+ $cacheData2 = $this->cache->get($file2);
+ $this->assertEquals($newId2, $id2);
+ $this->assertEquals($cacheData2['size'], $newSize);
+ $this->assertEquals($cacheData1, $this->cache->get($file1));
+
+ $this->cache->remove($file2);
+ $this->assertFalse($this->cache->inCache($file2));
+ $this->assertEquals($this->cache->get($file2), null);
+ $this->assertTrue($this->cache->inCache($file1));
+
+ $this->assertEquals($cacheData1, $this->cache->get($id1));
+ }
+
+ public function testPartial() {
+ $file1 = 'foo';
+
+ $this->cache->put($file1, array('size' => 10));
+ $this->assertEquals(array('size' => 10), $this->cache->get($file1));
+
+ $this->cache->put($file1, array('mtime' => 15));
+ $this->assertEquals(array('size' => 10, 'mtime' => 15), $this->cache->get($file1));
+
+ $this->cache->put($file1, array('size' => 12));
+ $this->assertEquals(array('size' => 12, 'mtime' => 15), $this->cache->get($file1));
+ }
+
+ public function testFolder() {
+ $file1 = 'folder';
+ $file2 = 'folder/bar';
+ $file3 = 'folder/foo';
+ $data1 = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory');
+ $fileData = array();
+ $fileData['bar'] = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'foo/file');
+ $fileData['foo'] = array('size' => 20, 'mtime' => 25, 'mimetype' => 'foo/file');
+
+ $this->cache->put($file1, $data1);
+ $this->cache->put($file2, $fileData['bar']);
+ $this->cache->put($file3, $fileData['foo']);
+
+ $content = $this->cache->getFolderContents($file1);
+ $this->assertEquals(count($content), 2);
+ foreach ($content as $cachedData) {
+ $data = $fileData[$cachedData['name']];
+ foreach ($data as $name => $value) {
+ $this->assertEquals($value, $cachedData[$name]);
+ }
+ }
+
+ $file4 = 'folder/unkownSize';
+ $fileData['unkownSize'] = array('size' => -1, 'mtime' => 25, 'mimetype' => 'foo/file');
+ $this->cache->put($file4, $fileData['unkownSize']);
+
+ $this->assertEquals(-1, $this->cache->calculateFolderSize($file1));
+
+ $fileData['unkownSize'] = array('size' => 5, 'mtime' => 25, 'mimetype' => 'foo/file');
+ $this->cache->put($file4, $fileData['unkownSize']);
+
+ $this->assertEquals(1025, $this->cache->calculateFolderSize($file1));
+
+ $this->cache->remove('folder');
+ $this->assertFalse($this->cache->inCache('folder/foo'));
+ $this->assertFalse($this->cache->inCache('folder/bar'));
+ }
+
+ function testStatus() {
+ $this->assertEquals(\OC\Files\Cache\Cache::NOT_FOUND, $this->cache->getStatus('foo'));
+ $this->cache->put('foo', array('size' => -1));
+ $this->assertEquals(\OC\Files\Cache\Cache::PARTIAL, $this->cache->getStatus('foo'));
+ $this->cache->put('foo', array('size' => -1, 'mtime' => 20, 'mimetype' => 'foo/file'));
+ $this->assertEquals(\OC\Files\Cache\Cache::SHALLOW, $this->cache->getStatus('foo'));
+ $this->cache->put('foo', array('size' => 10));
+ $this->assertEquals(\OC\Files\Cache\Cache::COMPLETE, $this->cache->getStatus('foo'));
+ }
+
+ function testSearch() {
+ $file1 = 'folder';
+ $file2 = 'folder/foobar';
+ $file3 = 'folder/foo';
+ $data1 = array('size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder');
+ $fileData = array();
+ $fileData['foobar'] = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'foo/file');
+ $fileData['foo'] = array('size' => 20, 'mtime' => 25, 'mimetype' => 'foo/file');
+
+ $this->cache->put($file1, $data1);
+ $this->cache->put($file2, $fileData['foobar']);
+ $this->cache->put($file3, $fileData['foo']);
+
+ $this->assertEquals(2, count($this->cache->search('%foo%')));
+ $this->assertEquals(1, count($this->cache->search('foo')));
+ $this->assertEquals(1, count($this->cache->search('%folder%')));
+ $this->assertEquals(1, count($this->cache->search('folder%')));
+ $this->assertEquals(3, count($this->cache->search('%')));
+
+ $this->assertEquals(3, count($this->cache->searchByMime('foo')));
+ $this->assertEquals(2, count($this->cache->searchByMime('foo/file')));
+ }
+
+ function testMove() {
+ $file1 = 'folder';
+ $file2 = 'folder/bar';
+ $file3 = 'folder/foo';
+ $file4 = 'folder/foo/1';
+ $file5 = 'folder/foo/2';
+ $data = array('size' => 100, 'mtime' => 50, 'mimetype' => 'foo/bar');
+
+ $this->cache->put($file1, $data);
+ $this->cache->put($file2, $data);
+ $this->cache->put($file3, $data);
+ $this->cache->put($file4, $data);
+ $this->cache->put($file5, $data);
+
+ $this->cache->move('folder/foo', 'folder/foobar');
+
+ $this->assertFalse($this->cache->inCache('folder/foo'));
+ $this->assertFalse($this->cache->inCache('folder/foo/1'));
+ $this->assertFalse($this->cache->inCache('folder/foo/2'));
+
+ $this->assertTrue($this->cache->inCache('folder/bar'));
+ $this->assertTrue($this->cache->inCache('folder/foobar'));
+ $this->assertTrue($this->cache->inCache('folder/foobar/1'));
+ $this->assertTrue($this->cache->inCache('folder/foobar/2'));
+ }
+
+ function testGetIncomplete() {
+ $file1 = 'folder1';
+ $file2 = 'folder2';
+ $file3 = 'folder3';
+ $file4 = 'folder4';
+ $data = array('size' => 10, 'mtime' => 50, 'mimetype' => 'foo/bar');
+
+ $this->cache->put($file1, $data);
+ $data['size'] = -1;
+ $this->cache->put($file2, $data);
+ $this->cache->put($file3, $data);
+ $data['size'] = 12;
+ $this->cache->put($file4, $data);
+
+ $this->assertEquals($file3, $this->cache->getIncomplete());
+ }
+
+ function testNonExisting() {
+ $this->assertFalse($this->cache->get('foo.txt'));
+ $this->assertEquals(array(), $this->cache->getFolderContents('foo'));
+ }
+
+ function testGetById() {
+ $storageId = $this->storage->getId();
+ $data = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'foo/file');
+ $id = $this->cache->put('foo', $data);
+ $this->assertEquals(array($storageId, 'foo'), \OC\Files\Cache\Cache::getById($id));
+ }
+
+ public function tearDown() {
+ $this->cache->clear();
+ }
+
+ public function setUp() {
+ $this->storage = new \OC\Files\Storage\Temporary(array());
+ $this->cache = new \OC\Files\Cache\Cache($this->storage);
+ }
+}
diff --git a/tests/lib/files/cache/permissions.php b/tests/lib/files/cache/permissions.php
new file mode 100644
index 00000000000..56dbbc4518e
--- /dev/null
+++ b/tests/lib/files/cache/permissions.php
@@ -0,0 +1,56 @@
+<?php
+/**
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\Files\Cache;
+
+class Permissions extends \PHPUnit_Framework_TestCase {
+ /***
+ * @var \OC\Files\Cache\Permissions $permissionsCache
+ */
+ private $permissionsCache;
+
+ function setUp(){
+ $this->permissionsCache=new \OC\Files\Cache\Permissions('dummy');
+ }
+
+ function testSimple() {
+ $ids = range(1, 10);
+ $user = uniqid();
+
+ $this->assertEquals(-1, $this->permissionsCache->get(1, $user));
+ $this->permissionsCache->set(1, $user, 1);
+ $this->assertEquals(1, $this->permissionsCache->get(1, $user));
+ $this->assertEquals(-1, $this->permissionsCache->get(2, $user));
+ $this->assertEquals(-1, $this->permissionsCache->get(1, $user . '2'));
+
+ $this->permissionsCache->set(1, $user, 2);
+ $this->assertEquals(2, $this->permissionsCache->get(1, $user));
+
+ $this->permissionsCache->set(2, $user, 1);
+ $this->assertEquals(1, $this->permissionsCache->get(2, $user));
+
+ $this->permissionsCache->remove(1, $user);
+ $this->assertEquals(-1, $this->permissionsCache->get(1, $user));
+ $this->permissionsCache->remove(1, $user . '2');
+ $this->assertEquals(1, $this->permissionsCache->get(2, $user));
+
+ $expected = array();
+ foreach ($ids as $id) {
+ $this->permissionsCache->set($id, $user, 10 + $id);
+ $expected[$id] = 10 + $id;
+ }
+ $this->assertEquals($expected, $this->permissionsCache->getMultiple($ids, $user));
+
+ $this->permissionsCache->removeMultiple(array(10, 9), $user);
+ unset($expected[9]);
+ unset($expected[10]);
+ $this->assertEquals($expected, $this->permissionsCache->getMultiple($ids, $user));
+
+ $this->permissionsCache->removeMultiple($ids, $user);
+ }
+}
diff --git a/tests/lib/files/cache/scanner.php b/tests/lib/files/cache/scanner.php
new file mode 100644
index 00000000000..3885c99e6d3
--- /dev/null
+++ b/tests/lib/files/cache/scanner.php
@@ -0,0 +1,141 @@
+<?php
+/**
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\Files\Cache;
+
+class Scanner extends \PHPUnit_Framework_TestCase {
+ /**
+ * @var \OC\Files\Storage\Storage $storage
+ */
+ private $storage;
+
+ /**
+ * @var \OC\Files\Cache\Scanner $scanner
+ */
+ private $scanner;
+
+ /**
+ * @var \OC\Files\Cache\Cache $cache
+ */
+ private $cache;
+
+ function testFile() {
+ $data = "dummy file data\n";
+ $this->storage->file_put_contents('foo.txt', $data);
+ $this->scanner->scanFile('foo.txt');
+
+ $this->assertEquals($this->cache->inCache('foo.txt'), true);
+ $cachedData = $this->cache->get('foo.txt');
+ $this->assertEquals($cachedData['size'], strlen($data));
+ $this->assertEquals($cachedData['mimetype'], 'text/plain');
+ $this->assertNotEquals($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->assertEquals($this->cache->inCache('foo.png'), true);
+ $cachedData = $this->cache->get('foo.png');
+ $this->assertEquals($cachedData['size'], strlen($data));
+ $this->assertEquals($cachedData['mimetype'], 'image/png');
+ }
+
+ private function fillTestFolders() {
+ $textData = "dummy file data\n";
+ $imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png');
+ $this->storage->mkdir('folder');
+ $this->storage->file_put_contents('foo.txt', $textData);
+ $this->storage->file_put_contents('foo.png', $imgData);
+ $this->storage->file_put_contents('folder/bar.txt', $textData);
+ }
+
+ function testFolder() {
+ $this->fillTestFolders();
+
+ $this->scanner->scan('');
+ $this->assertEquals($this->cache->inCache(''), true);
+ $this->assertEquals($this->cache->inCache('foo.txt'), true);
+ $this->assertEquals($this->cache->inCache('foo.png'), true);
+ $this->assertEquals($this->cache->inCache('folder'), true);
+ $this->assertEquals($this->cache->inCache('folder/bar.txt'), true);
+
+ $cachedDataText = $this->cache->get('foo.txt');
+ $cachedDataText2 = $this->cache->get('foo.txt');
+ $cachedDataImage = $this->cache->get('foo.png');
+ $cachedDataFolder = $this->cache->get('');
+ $cachedDataFolder2 = $this->cache->get('folder');
+
+ $this->assertEquals($cachedDataImage['parent'], $cachedDataText['parent']);
+ $this->assertEquals($cachedDataFolder['fileid'], $cachedDataImage['parent']);
+ $this->assertEquals($cachedDataFolder['size'], $cachedDataImage['size'] + $cachedDataText['size'] + $cachedDataText2['size']);
+ $this->assertEquals($cachedDataFolder2['size'], $cachedDataText2['size']);
+ }
+
+ function testShallow() {
+ $this->fillTestFolders();
+
+ $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW);
+ $this->assertEquals($this->cache->inCache(''), true);
+ $this->assertEquals($this->cache->inCache('foo.txt'), true);
+ $this->assertEquals($this->cache->inCache('foo.png'), true);
+ $this->assertEquals($this->cache->inCache('folder'), true);
+ $this->assertEquals($this->cache->inCache('folder/bar.txt'), false);
+
+ $cachedDataFolder = $this->cache->get('');
+ $cachedDataFolder2 = $this->cache->get('folder');
+
+ $this->assertEquals(-1, $cachedDataFolder['size']);
+ $this->assertEquals(-1, $cachedDataFolder2['size']);
+
+ $this->scanner->scan('folder', \OC\Files\Cache\Scanner::SCAN_SHALLOW);
+
+ $cachedDataFolder2 = $this->cache->get('folder');
+
+ $this->assertNotEquals($cachedDataFolder2['size'], -1);
+
+ $this->cache->correctFolderSize('folder');
+
+ $cachedDataFolder = $this->cache->get('');
+ $this->assertNotEquals($cachedDataFolder['size'], -1);
+ }
+
+ function testBackgroundScan(){
+ $this->fillTestFolders();
+ $this->storage->mkdir('folder2');
+ $this->storage->file_put_contents('folder2/bar.txt', 'foobar');
+
+ $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW);
+ $this->assertFalse($this->cache->inCache('folder/bar.txt'));
+ $this->assertFalse($this->cache->inCache('folder/2bar.txt'));
+ $cachedData = $this->cache->get('');
+ $this->assertEquals(-1, $cachedData['size']);
+
+ $this->scanner->backgroundScan();
+
+ $this->assertTrue($this->cache->inCache('folder/bar.txt'));
+ $this->assertTrue($this->cache->inCache('folder/bar.txt'));
+
+ $cachedData = $this->cache->get('');
+ $this->assertnotEquals(-1, $cachedData['size']);
+
+ $this->assertFalse($this->cache->getIncomplete());
+ }
+
+ function setUp() {
+ $this->storage = new \OC\Files\Storage\Temporary(array());
+ $this->scanner = new \OC\Files\Cache\Scanner($this->storage);
+ $this->cache = new \OC\Files\Cache\Cache($this->storage);
+ }
+
+ function tearDown() {
+ $ids = $this->cache->getAll();
+ $permissionsCache = $this->storage->getPermissionsCache();
+ $permissionsCache->removeMultiple($ids, \OC_User::getUser());
+ $this->cache->clear();
+ }
+}
diff --git a/tests/lib/files/cache/updater.php b/tests/lib/files/cache/updater.php
new file mode 100644
index 00000000000..b83dd0c26e5
--- /dev/null
+++ b/tests/lib/files/cache/updater.php
@@ -0,0 +1,147 @@
+<?php
+/**
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\Files\Cache;
+
+use \OC\Files\Filesystem as Filesystem;
+
+class Updater extends \PHPUnit_Framework_TestCase {
+ /**
+ * @var \OC\Files\Storage\Storage $storage
+ */
+ private $storage;
+
+ /**
+ * @var \OC\Files\Cache\Scanner $scanner
+ */
+ private $scanner;
+
+ /**
+ * @var \OC\Files\Cache\Cache $cache
+ */
+ private $cache;
+
+ private static $user;
+
+ public function setUp() {
+ $this->storage = new \OC\Files\Storage\Temporary(array());
+ $textData = "dummy file data\n";
+ $imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png');
+ $this->storage->mkdir('folder');
+ $this->storage->file_put_contents('foo.txt', $textData);
+ $this->storage->file_put_contents('foo.png', $imgData);
+ $this->storage->file_put_contents('folder/bar.txt', $textData);
+ $this->storage->file_put_contents('folder/bar2.txt', $textData);
+
+ $this->scanner = $this->storage->getScanner();
+ $this->scanner->scan('');
+ $this->cache = $this->storage->getCache();
+
+ if (!self::$user) {
+ if (!\OC\Files\Filesystem::getView()) {
+ self::$user = uniqid();
+ \OC\Files\Filesystem::init('/' . self::$user . '/files');
+ } else {
+ self::$user = \OC_User::getUser();
+ }
+ }
+
+ Filesystem::clearMounts();
+ Filesystem::mount($this->storage, array(), '/' . self::$user . '/files');
+
+ \OC_Hook::connect('OC_Filesystem', 'post_write', '\OC\Files\Cache\Updater', 'writeHook');
+ \OC_Hook::connect('OC_Filesystem', 'post_delete', '\OC\Files\Cache\Updater', 'deleteHook');
+ \OC_Hook::connect('OC_Filesystem', 'post_rename', '\OC\Files\Cache\Updater', 'renameHook');
+
+ }
+
+ public function tearDown() {
+ if ($this->cache) {
+ $this->cache->clear();
+ }
+ Filesystem::tearDown();
+ }
+
+ public function testWrite() {
+ $textSize = strlen("dummy file data\n");
+ $imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo.png');
+ $rootCachedData = $this->cache->get('');
+ $this->assertEquals(3 * $textSize + $imageSize, $rootCachedData['size']);
+
+ $fooCachedData = $this->cache->get('foo.txt');
+ Filesystem::file_put_contents('foo.txt', 'asd');
+ $cachedData = $this->cache->get('foo.txt');
+ $this->assertEquals(3, $cachedData['size']);
+ $this->assertNotEquals($fooCachedData['etag'], $cachedData['etag']);
+ $mtime = $cachedData['mtime'];
+ $cachedData = $this->cache->get('');
+ $this->assertEquals(2 * $textSize + $imageSize + 3, $cachedData['size']);
+ $this->assertNotEquals($rootCachedData['etag'], $cachedData['etag']);
+ $this->assertGreaterThanOrEqual($rootCachedData['mtime'], $mtime);
+ $rootCachedData = $cachedData;
+
+ $this->assertFalse($this->cache->inCache('bar.txt'));
+ Filesystem::file_put_contents('bar.txt', 'asd');
+ $this->assertTrue($this->cache->inCache('bar.txt'));
+ $cachedData = $this->cache->get('bar.txt');
+ $this->assertEquals(3, $cachedData['size']);
+ $mtime = $cachedData['mtime'];
+ $cachedData = $this->cache->get('');
+ $this->assertEquals(2 * $textSize + $imageSize + 2 * 3, $cachedData['size']);
+ $this->assertNotEquals($rootCachedData['etag'], $cachedData['etag']);
+ $this->assertGreaterThanOrEqual($rootCachedData['mtime'], $mtime);
+ }
+
+ public function testDelete() {
+ $textSize = strlen("dummy file data\n");
+ $imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo.png');
+ $rootCachedData = $this->cache->get('');
+ $this->assertEquals(3 * $textSize + $imageSize, $rootCachedData['size']);
+
+ $this->assertTrue($this->cache->inCache('foo.txt'));
+ Filesystem::unlink('foo.txt', 'asd');
+ $this->assertFalse($this->cache->inCache('foo.txt'));
+ $cachedData = $this->cache->get('');
+ $this->assertEquals(2 * $textSize + $imageSize, $cachedData['size']);
+ $this->assertNotEquals($rootCachedData['etag'], $cachedData['etag']);
+ $this->assertGreaterThanOrEqual($rootCachedData['mtime'], $cachedData['mtime']);
+ $rootCachedData = $cachedData;
+
+ Filesystem::mkdir('bar_folder');
+ $this->assertTrue($this->cache->inCache('bar_folder'));
+ $cachedData = $this->cache->get('');
+ $this->assertNotEquals($rootCachedData['etag'], $cachedData['etag']);
+ $rootCachedData = $cachedData;
+ Filesystem::rmdir('bar_folder');
+ $this->assertFalse($this->cache->inCache('bar_folder'));
+ $cachedData = $this->cache->get('');
+ $this->assertNotEquals($rootCachedData['etag'], $cachedData['etag']);
+ $this->assertGreaterThanOrEqual($rootCachedData['mtime'], $cachedData['mtime']);
+ }
+
+ public function testRename() {
+ $textSize = strlen("dummy file data\n");
+ $imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo.png');
+ $rootCachedData = $this->cache->get('');
+ $this->assertEquals(3 * $textSize + $imageSize, $rootCachedData['size']);
+
+ $this->assertTrue($this->cache->inCache('foo.txt'));
+ $fooCachedData = $this->cache->get('foo.txt');
+ $this->assertFalse($this->cache->inCache('bar.txt'));
+ Filesystem::rename('foo.txt', 'bar.txt');
+ $this->assertFalse($this->cache->inCache('foo.txt'));
+ $this->assertTrue($this->cache->inCache('bar.txt'));
+ $cachedData = $this->cache->get('bar.txt');
+ $this->assertNotEquals($fooCachedData['etag'], $cachedData['etag']);
+ $mtime = $cachedData['mtime'];
+ $cachedData = $this->cache->get('');
+ $this->assertEquals(3 * $textSize + $imageSize, $cachedData['size']);
+ $this->assertNotEquals($rootCachedData['etag'], $cachedData['etag']);
+ $this->assertEquals($mtime, $cachedData['mtime']);
+ }
+}
diff --git a/tests/lib/files/cache/watcher.php b/tests/lib/files/cache/watcher.php
new file mode 100644
index 00000000000..e8a1689cab0
--- /dev/null
+++ b/tests/lib/files/cache/watcher.php
@@ -0,0 +1,121 @@
+<?php
+/**
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\Files\Cache;
+
+class Watcher extends \PHPUnit_Framework_TestCase {
+
+ /**
+ * @var \OC\Files\Storage\Storage[] $storages;
+ */
+ private $storages = array();
+
+ public function setUp() {
+ \OC\Files\Filesystem::clearMounts();
+ }
+
+ public function tearDown() {
+ foreach ($this->storages as $storage) {
+ $cache = $storage->getCache();
+ $ids = $cache->getAll();
+ $permissionsCache = $storage->getPermissionsCache();
+ $permissionsCache->removeMultiple($ids, \OC_User::getUser());
+ $cache->clear();
+ }
+ }
+
+ function testWatcher() {
+ $storage = $this->getTestStorage();
+ $cache = $storage->getCache();
+ $updater = $storage->getWatcher();
+
+ //set the mtime to the past so it can detect an mtime change
+ $cache->put('', array('mtime' => 10));
+
+ $this->assertTrue($cache->inCache('folder/bar.txt'));
+ $this->assertTrue($cache->inCache('folder/bar2.txt'));
+
+ $this->assertFalse($cache->inCache('bar.test'));
+ $storage->file_put_contents('bar.test', 'foo');
+ $updater->checkUpdate('');
+ $this->assertTrue($cache->inCache('bar.test'));
+ $cachedData = $cache->get('bar.test');
+ $this->assertEquals(3, $cachedData['size']);
+
+ $cache->put('bar.test', array('mtime' => 10));
+ $storage->file_put_contents('bar.test', 'test data');
+
+ $updater->checkUpdate('bar.test');
+ $cachedData = $cache->get('bar.test');
+ $this->assertEquals(9, $cachedData['size']);
+
+ $cache->put('folder', array('mtime' => 10));
+
+ $storage->unlink('folder/bar2.txt');
+ $updater->checkUpdate('folder');
+
+ $this->assertTrue($cache->inCache('folder/bar.txt'));
+ $this->assertFalse($cache->inCache('folder/bar2.txt'));
+ }
+
+ public function testFileToFolder() {
+ $storage = $this->getTestStorage();
+ $cache = $storage->getCache();
+ $updater = $storage->getWatcher();
+
+ //set the mtime to the past so it can detect an mtime change
+ $cache->put('', array('mtime' => 10));
+
+ $storage->unlink('foo.txt');
+ $storage->rename('folder', 'foo.txt');
+ $updater->checkUpdate('');
+
+ $entry = $cache->get('foo.txt');
+ $this->assertEquals(-1, $entry['size']);
+ $this->assertEquals('httpd/unix-directory', $entry['mimetype']);
+ $this->assertFalse($cache->inCache('folder'));
+ $this->assertFalse($cache->inCache('folder/bar.txt'));
+
+ $storage = $this->getTestStorage();
+ $cache = $storage->getCache();
+ $updater = $storage->getWatcher();
+
+ //set the mtime to the past so it can detect an mtime change
+ $cache->put('foo.txt', array('mtime' => 10));
+
+ $storage->unlink('foo.txt');
+ $storage->rename('folder', 'foo.txt');
+ $updater->checkUpdate('foo.txt');
+
+ $entry = $cache->get('foo.txt');
+ $this->assertEquals('httpd/unix-directory', $entry['mimetype']);
+ $this->assertTrue($cache->inCache('foo.txt/bar.txt'));
+ }
+
+ /**
+ * @param bool $scan
+ * @return \OC\Files\Storage\Storage
+ */
+ private function getTestStorage($scan = true) {
+ $storage = new \OC\Files\Storage\Temporary(array());
+ $textData = "dummy file data\n";
+ $imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png');
+ $storage->mkdir('folder');
+ $storage->file_put_contents('foo.txt', $textData);
+ $storage->file_put_contents('foo.png', $imgData);
+ $storage->file_put_contents('folder/bar.txt', $textData);
+ $storage->file_put_contents('folder/bar2.txt', $textData);
+
+ if ($scan) {
+ $scanner = $storage->getScanner();
+ $scanner->scan('');
+ }
+ $this->storages[] = $storage;
+ return $storage;
+ }
+}
diff --git a/tests/lib/files/filesystem.php b/tests/lib/files/filesystem.php
new file mode 100644
index 00000000000..5837093fdd6
--- /dev/null
+++ b/tests/lib/files/filesystem.php
@@ -0,0 +1,110 @@
+<?php
+/**
+ * ownCloud
+ *
+ * @author Robin Appelman
+ * @copyright 2012 Robin Appelman icewind@owncloud.com
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Test\Files;
+
+class Filesystem extends \PHPUnit_Framework_TestCase {
+ /**
+ * @var array tmpDirs
+ */
+ private $tmpDirs=array();
+
+ /**
+ * @return array
+ */
+ private function getStorageData() {
+ $dir = \OC_Helper::tmpFolder();
+ $this->tmpDirs[] = $dir;
+ return array('datadir' => $dir);
+ }
+
+ public function tearDown() {
+ foreach ($this->tmpDirs as $dir) {
+ \OC_Helper::rmdirr($dir);
+ }
+ }
+
+ public function setUp() {
+ \OC\Files\Filesystem::clearMounts();
+ }
+
+ public function testMount() {
+ \OC\Files\Filesystem::mount('\OC\Files\Storage\Local',self::getStorageData(),'/');
+ $this->assertEquals('/',\OC\Files\Filesystem::getMountPoint('/'));
+ $this->assertEquals('/',\OC\Files\Filesystem::getMountPoint('/some/folder'));
+ list( , $internalPath)=\OC\Files\Filesystem::resolvePath('/');
+ $this->assertEquals('',$internalPath);
+ list( , $internalPath)=\OC\Files\Filesystem::resolvePath('/some/folder');
+ $this->assertEquals('some/folder',$internalPath);
+
+ \OC\Files\Filesystem::mount('\OC\Files\Storage\Local',self::getStorageData(),'/some');
+ $this->assertEquals('/',\OC\Files\Filesystem::getMountPoint('/'));
+ $this->assertEquals('/some/',\OC\Files\Filesystem::getMountPoint('/some/folder'));
+ $this->assertEquals('/some/',\OC\Files\Filesystem::getMountPoint('/some/'));
+ $this->assertEquals('/some/',\OC\Files\Filesystem::getMountPoint('/some'));
+ list( , $internalPath)=\OC\Files\Filesystem::resolvePath('/some/folder');
+ $this->assertEquals('folder',$internalPath);
+ }
+
+ public function testNormalize() {
+ $this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('/path/'));
+ $this->assertEquals('/path/', \OC\Files\Filesystem::normalizePath('/path/', false));
+ $this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('path'));
+ $this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('\path'));
+ $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo//bar/'));
+ $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo////bar'));
+ if (class_exists('Normalizer')) {
+ $this->assertEquals("/foo/bar\xC3\xBC", \OC\Files\Filesystem::normalizePath("/foo/baru\xCC\x88"));
+ }
+ }
+
+ public function testHooks() {
+ if(\OC\Files\Filesystem::getView()){
+ $user = \OC_User::getUser();
+ }else{
+ $user=uniqid();
+ \OC\Files\Filesystem::init('/'.$user.'/files');
+ }
+ \OC_Hook::clear('OC_Filesystem');
+ \OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook');
+
+ \OC\Files\Filesystem::mount('OC\Files\Storage\Temporary', array(), '/');
+
+ $rootView=new \OC\Files\View('');
+ $rootView->mkdir('/'.$user);
+ $rootView->mkdir('/'.$user.'/files');
+
+ \OC\Files\Filesystem::file_put_contents('/foo', 'foo');
+ \OC\Files\Filesystem::mkdir('/bar');
+ \OC\Files\Filesystem::file_put_contents('/bar//foo', 'foo');
+
+ $tmpFile = \OC_Helper::tmpFile();
+ file_put_contents($tmpFile, 'foo');
+ $fh = fopen($tmpFile, 'r');
+ \OC\Files\Filesystem::file_put_contents('/bar//foo', $fh);
+ }
+
+ public function dummyHook($arguments) {
+ $path = $arguments['path'];
+ $this->assertEquals($path, \OC\Files\Filesystem::normalizePath($path)); //the path passed to the hook should already be normalized
+ }
+}
diff --git a/tests/lib/files/mount.php b/tests/lib/files/mount.php
new file mode 100644
index 00000000000..f223f0f6c53
--- /dev/null
+++ b/tests/lib/files/mount.php
@@ -0,0 +1,41 @@
+<?php
+/**
+ * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\Files;
+
+use \OC\Files\Storage\Temporary;
+
+class Mount extends \PHPUnit_Framework_TestCase {
+ public function setup() {
+ \OC_Util::setupFS();
+ \OC\Files\Mount::clear();
+ }
+
+ public function testFind() {
+ $this->assertNull(\OC\Files\Mount::find('/'));
+
+ $rootMount = new \OC\Files\Mount(new Temporary(array()), '/');
+ $this->assertEquals($rootMount, \OC\Files\Mount::find('/'));
+ $this->assertEquals($rootMount, \OC\Files\Mount::find('/foo/bar'));
+
+ $storage = new Temporary(array());
+ $mount = new \OC\Files\Mount($storage, '/foo');
+ $this->assertEquals($rootMount, \OC\Files\Mount::find('/'));
+ $this->assertEquals($mount, \OC\Files\Mount::find('/foo/bar'));
+
+ $this->assertEquals(1, count(\OC\Files\Mount::findIn('/')));
+ new \OC\Files\Mount(new Temporary(array()), '/bar');
+ $this->assertEquals(2, count(\OC\Files\Mount::findIn('/')));
+
+ $id = $mount->getStorageId();
+ $this->assertEquals(array($mount), \OC\Files\Mount::findById($id));
+
+ $mount2 = new \OC\Files\Mount($storage, '/foo/bar');
+ $this->assertEquals(array($mount, $mount2), \OC\Files\Mount::findById($id));
+ }
+}
diff --git a/tests/lib/filestorage/commontest.php b/tests/lib/files/storage/commontest.php
index 6719fcff4e8..744d4608420 100644
--- a/tests/lib/filestorage/commontest.php
+++ b/tests/lib/files/storage/commontest.php
@@ -20,7 +20,9 @@
*
*/
-class Test_Filestorage_CommonTest extends Test_FileStorage {
+namespace Test\Files\Storage;
+
+class CommonTest extends Storage {
/**
* @var string tmpDir
*/
@@ -30,11 +32,10 @@ class Test_Filestorage_CommonTest extends Test_FileStorage {
if(!file_exists($this->tmpDir)) {
mkdir($this->tmpDir);
}
- $this->instance=new OC_Filestorage_CommonTest(array('datadir'=>$this->tmpDir));
+ $this->instance=new \OC\Files\Storage\CommonTest(array('datadir'=>$this->tmpDir));
}
public function tearDown() {
- OC_Helper::rmdirr($this->tmpDir);
+ \OC_Helper::rmdirr($this->tmpDir);
}
}
-
diff --git a/tests/lib/filestorage/local.php b/tests/lib/files/storage/local.php
index d7d71e8f372..1aad138aa33 100644
--- a/tests/lib/filestorage/local.php
+++ b/tests/lib/files/storage/local.php
@@ -20,18 +20,20 @@
*
*/
-class Test_Filestorage_Local extends Test_FileStorage {
+namespace Test\Files\Storage;
+
+class Local extends Storage {
/**
* @var string tmpDir
*/
private $tmpDir;
public function setUp() {
- $this->tmpDir=OC_Helper::tmpFolder();
- $this->instance=new OC_Filestorage_Local(array('datadir'=>$this->tmpDir));
+ $this->tmpDir=\OC_Helper::tmpFolder();
+ $this->instance=new \OC\Files\Storage\Local(array('datadir'=>$this->tmpDir));
}
public function tearDown() {
- OC_Helper::rmdirr($this->tmpDir);
+ \OC_Helper::rmdirr($this->tmpDir);
}
}
diff --git a/tests/lib/filestorage.php b/tests/lib/files/storage/storage.php
index e82a6f54e3d..781c0f92c92 100644
--- a/tests/lib/filestorage.php
+++ b/tests/lib/files/storage/storage.php
@@ -20,9 +20,11 @@
*
*/
-abstract class Test_FileStorage extends UnitTestCase {
+namespace Test\Files\Storage;
+
+abstract class Storage extends \PHPUnit_Framework_TestCase {
/**
- * @var OC_Filestorage instance
+ * @var \OC\Files\Storage\Storage instance
*/
protected $instance;
@@ -34,9 +36,9 @@ abstract class Test_FileStorage extends UnitTestCase {
$this->assertTrue($this->instance->isReadable('/'), 'Root folder is not readable');
$this->assertTrue($this->instance->is_dir('/'), 'Root folder is not a directory');
$this->assertFalse($this->instance->is_file('/'), 'Root folder is a file');
- $this->assertEqual('dir', $this->instance->filetype('/'));
+ $this->assertEquals('dir', $this->instance->filetype('/'));
- //without this, any further testing would be useless, not an acutal requirement for filestorage though
+ //without this, any further testing would be useless, not an actual requirement for filestorage though
$this->assertTrue($this->instance->isUpdatable('/'), 'Root folder is not writable');
}
@@ -48,8 +50,8 @@ abstract class Test_FileStorage extends UnitTestCase {
$this->assertTrue($this->instance->file_exists('/folder'));
$this->assertTrue($this->instance->is_dir('/folder'));
$this->assertFalse($this->instance->is_file('/folder'));
- $this->assertEqual('dir', $this->instance->filetype('/folder'));
- $this->assertEqual(0, $this->instance->filesize('/folder'));
+ $this->assertEquals('dir', $this->instance->filetype('/folder'));
+ $this->assertEquals(0, $this->instance->filesize('/folder'));
$this->assertTrue($this->instance->isReadable('/folder'));
$this->assertTrue($this->instance->isUpdatable('/folder'));
@@ -60,7 +62,7 @@ abstract class Test_FileStorage extends UnitTestCase {
$content[] = $file;
}
}
- $this->assertEqual(array('folder'), $content);
+ $this->assertEquals(array('folder'), $content);
$this->assertFalse($this->instance->mkdir('/folder')); //cant create existing folders
$this->assertTrue($this->instance->rmdir('/folder'));
@@ -76,65 +78,65 @@ abstract class Test_FileStorage extends UnitTestCase {
$content[] = $file;
}
}
- $this->assertEqual(array(), $content);
+ $this->assertEquals(array(), $content);
}
/**
* test the various uses of file_get_contents and file_put_contents
*/
public function testGetPutContents() {
- $sourceFile = OC::$SERVERROOT . '/tests/data/lorem.txt';
+ $sourceFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
$sourceText = file_get_contents($sourceFile);
//fill a file with string data
$this->instance->file_put_contents('/lorem.txt', $sourceText);
$this->assertFalse($this->instance->is_dir('/lorem.txt'));
- $this->assertEqual($sourceText, $this->instance->file_get_contents('/lorem.txt'), 'data returned from file_get_contents is not equal to the source data');
+ $this->assertEquals($sourceText, $this->instance->file_get_contents('/lorem.txt'), 'data returned from file_get_contents is not equal to the source data');
//empty the file
$this->instance->file_put_contents('/lorem.txt', '');
- $this->assertEqual('', $this->instance->file_get_contents('/lorem.txt'), 'file not emptied');
+ $this->assertEquals('', $this->instance->file_get_contents('/lorem.txt'), 'file not emptied');
}
/**
* test various known mimetypes
*/
public function testMimeType() {
- $this->assertEqual('httpd/unix-directory', $this->instance->getMimeType('/'));
- $this->assertEqual(false, $this->instance->getMimeType('/non/existing/file'));
+ $this->assertEquals('httpd/unix-directory', $this->instance->getMimeType('/'));
+ $this->assertEquals(false, $this->instance->getMimeType('/non/existing/file'));
- $textFile = OC::$SERVERROOT . '/tests/data/lorem.txt';
+ $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
$this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile, 'r'));
- $this->assertEqual('text/plain', $this->instance->getMimeType('/lorem.txt'));
+ $this->assertEquals('text/plain', $this->instance->getMimeType('/lorem.txt'));
- $pngFile = OC::$SERVERROOT . '/tests/data/logo-wide.png';
+ $pngFile = \OC::$SERVERROOT . '/tests/data/logo-wide.png';
$this->instance->file_put_contents('/logo-wide.png', file_get_contents($pngFile, 'r'));
- $this->assertEqual('image/png', $this->instance->getMimeType('/logo-wide.png'));
+ $this->assertEquals('image/png', $this->instance->getMimeType('/logo-wide.png'));
- $svgFile = OC::$SERVERROOT . '/tests/data/logo-wide.svg';
+ $svgFile = \OC::$SERVERROOT . '/tests/data/logo-wide.svg';
$this->instance->file_put_contents('/logo-wide.svg', file_get_contents($svgFile, 'r'));
- $this->assertEqual('image/svg+xml', $this->instance->getMimeType('/logo-wide.svg'));
+ $this->assertEquals('image/svg+xml', $this->instance->getMimeType('/logo-wide.svg'));
}
public function testCopyAndMove() {
- $textFile = OC::$SERVERROOT . '/tests/data/lorem.txt';
+ $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
$this->instance->file_put_contents('/source.txt', file_get_contents($textFile));
$this->instance->copy('/source.txt', '/target.txt');
$this->assertTrue($this->instance->file_exists('/target.txt'));
- $this->assertEqual($this->instance->file_get_contents('/source.txt'), $this->instance->file_get_contents('/target.txt'));
+ $this->assertEquals($this->instance->file_get_contents('/source.txt'), $this->instance->file_get_contents('/target.txt'));
$this->instance->rename('/source.txt', '/target2.txt');
$this->assertTrue($this->instance->file_exists('/target2.txt'));
$this->assertFalse($this->instance->file_exists('/source.txt'));
- $this->assertEqual(file_get_contents($textFile), $this->instance->file_get_contents('/target.txt'));
+ $this->assertEquals(file_get_contents($textFile), $this->instance->file_get_contents('/target.txt'));
}
public function testLocal() {
- $textFile = OC::$SERVERROOT . '/tests/data/lorem.txt';
+ $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
$this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile));
$localFile = $this->instance->getLocalFile('/lorem.txt');
$this->assertTrue(file_exists($localFile));
- $this->assertEqual(file_get_contents($localFile), file_get_contents($textFile));
+ $this->assertEquals(file_get_contents($localFile), file_get_contents($textFile));
$this->instance->mkdir('/folder');
$this->instance->file_put_contents('/folder/lorem.txt', file_get_contents($textFile));
@@ -145,13 +147,13 @@ abstract class Test_FileStorage extends UnitTestCase {
$this->assertTrue(is_dir($localFolder));
$this->assertTrue(file_exists($localFolder . '/lorem.txt'));
- $this->assertEqual(file_get_contents($localFolder . '/lorem.txt'), file_get_contents($textFile));
- $this->assertEqual(file_get_contents($localFolder . '/bar.txt'), 'asd');
- $this->assertEqual(file_get_contents($localFolder . '/recursive/file.txt'), 'foo');
+ $this->assertEquals(file_get_contents($localFolder . '/lorem.txt'), file_get_contents($textFile));
+ $this->assertEquals(file_get_contents($localFolder . '/bar.txt'), 'asd');
+ $this->assertEquals(file_get_contents($localFolder . '/recursive/file.txt'), 'foo');
}
public function testStat() {
- $textFile = OC::$SERVERROOT . '/tests/data/lorem.txt';
+ $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
$ctimeStart = time();
$this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile));
$this->assertTrue($this->instance->isReadable('/lorem.txt'));
@@ -162,12 +164,12 @@ abstract class Test_FileStorage extends UnitTestCase {
$this->assertTrue(($ctimeStart - 1) <= $mTime);
$this->assertTrue($mTime <= ($ctimeEnd + 1));
- $this->assertEqual(filesize($textFile), $this->instance->filesize('/lorem.txt'));
+ $this->assertEquals(filesize($textFile), $this->instance->filesize('/lorem.txt'));
$stat = $this->instance->stat('/lorem.txt');
//only size and mtime are requered in the result
- $this->assertEqual($stat['size'], $this->instance->filesize('/lorem.txt'));
- $this->assertEqual($stat['mtime'], $mTime);
+ $this->assertEquals($stat['size'], $this->instance->filesize('/lorem.txt'));
+ $this->assertEquals($stat['mtime'], $mTime);
$mtimeStart = time();
$supportsTouch = $this->instance->touch('/lorem.txt');
@@ -181,7 +183,7 @@ abstract class Test_FileStorage extends UnitTestCase {
if ($this->instance->touch('/lorem.txt', 100) !== false) {
$mTime = $this->instance->filemtime('/lorem.txt');
- $this->assertEqual($mTime, 100);
+ $this->assertEquals($mTime, 100);
}
}
@@ -200,20 +202,20 @@ abstract class Test_FileStorage extends UnitTestCase {
}
public function testSearch() {
- $textFile = OC::$SERVERROOT . '/tests/data/lorem.txt';
+ $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
$this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile, 'r'));
- $pngFile = OC::$SERVERROOT . '/tests/data/logo-wide.png';
+ $pngFile = \OC::$SERVERROOT . '/tests/data/logo-wide.png';
$this->instance->file_put_contents('/logo-wide.png', file_get_contents($pngFile, 'r'));
- $svgFile = OC::$SERVERROOT . '/tests/data/logo-wide.svg';
+ $svgFile = \OC::$SERVERROOT . '/tests/data/logo-wide.svg';
$this->instance->file_put_contents('/logo-wide.svg', file_get_contents($svgFile, 'r'));
$result = $this->instance->search('logo');
- $this->assertEqual(2, count($result));
+ $this->assertEquals(2, count($result));
$this->assertContains('/logo-wide.svg', $result);
$this->assertContains('/logo-wide.png', $result);
}
public function testFOpen() {
- $textFile = OC::$SERVERROOT . '/tests/data/lorem.txt';
+ $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
$fh = @$this->instance->fopen('foo', 'r');
if ($fh) {
@@ -229,6 +231,6 @@ abstract class Test_FileStorage extends UnitTestCase {
$fh = $this->instance->fopen('foo', 'r');
$content = stream_get_contents($fh);
- $this->assertEqual(file_get_contents($textFile), $content);
+ $this->assertEquals(file_get_contents($textFile), $content);
}
}
diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php
new file mode 100644
index 00000000000..a064e44f3ef
--- /dev/null
+++ b/tests/lib/files/view.php
@@ -0,0 +1,251 @@
+<?php
+/**
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file. */
+
+namespace Test\Files;
+
+class View extends \PHPUnit_Framework_TestCase {
+ /**
+ * @var \OC\Files\Storage\Storage[] $storages;
+ */
+ private $storages = array();
+
+ public function setUp() {
+ \OC\Files\Filesystem::clearMounts();
+ }
+
+ public function tearDown() {
+ foreach ($this->storages as $storage) {
+ $cache = $storage->getCache();
+ $ids = $cache->getAll();
+ $permissionsCache = $storage->getPermissionsCache();
+ $permissionsCache->removeMultiple($ids, \OC_User::getUser());
+ $cache->clear();
+ }
+ }
+
+ public function testCacheAPI() {
+ $storage1 = $this->getTestStorage();
+ $storage2 = $this->getTestStorage();
+ $storage3 = $this->getTestStorage();
+ \OC\Files\Filesystem::mount($storage1, array(), '/');
+ \OC\Files\Filesystem::mount($storage2, array(), '/substorage');
+ \OC\Files\Filesystem::mount($storage3, array(), '/folder/anotherstorage');
+ $textSize = strlen("dummy file data\n");
+ $imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo.png');
+ $storageSize = $textSize * 2 + $imageSize;
+
+ $rootView = new \OC\Files\View('');
+
+ $cachedData = $rootView->getFileInfo('/foo.txt');
+ $this->assertEquals($textSize, $cachedData['size']);
+ $this->assertEquals('text/plain', $cachedData['mimetype']);
+ $this->assertNotEquals(-1, $cachedData['permissions']);
+
+ $cachedData = $rootView->getFileInfo('/');
+ $this->assertEquals($storageSize * 3, $cachedData['size']);
+ $this->assertEquals('httpd/unix-directory', $cachedData['mimetype']);
+
+ $cachedData = $rootView->getFileInfo('/folder');
+ $this->assertEquals($storageSize + $textSize, $cachedData['size']);
+ $this->assertEquals('httpd/unix-directory', $cachedData['mimetype']);
+
+ $folderData = $rootView->getDirectoryContent('/');
+ /**
+ * expected entries:
+ * folder
+ * foo.png
+ * foo.txt
+ * substorage
+ */
+ $this->assertEquals(4, count($folderData));
+ $this->assertEquals('folder', $folderData[0]['name']);
+ $this->assertEquals('foo.png', $folderData[1]['name']);
+ $this->assertEquals('foo.txt', $folderData[2]['name']);
+ $this->assertEquals('substorage', $folderData[3]['name']);
+
+ $this->assertEquals($storageSize + $textSize, $folderData[0]['size']);
+ $this->assertEquals($imageSize, $folderData[1]['size']);
+ $this->assertEquals($textSize, $folderData[2]['size']);
+ $this->assertEquals($storageSize, $folderData[3]['size']);
+
+ $folderData = $rootView->getDirectoryContent('/substorage');
+ /**
+ * expected entries:
+ * folder
+ * foo.png
+ * foo.txt
+ */
+ $this->assertEquals(3, count($folderData));
+ $this->assertEquals('folder', $folderData[0]['name']);
+ $this->assertEquals('foo.png', $folderData[1]['name']);
+ $this->assertEquals('foo.txt', $folderData[2]['name']);
+
+ $folderView = new \OC\Files\View('/folder');
+ $this->assertEquals($rootView->getFileInfo('/folder'), $folderView->getFileInfo('/'));
+
+ $cachedData = $rootView->getFileInfo('/foo.txt');
+ $this->assertFalse($cachedData['encrypted']);
+ $id = $rootView->putFileInfo('/foo.txt', array('encrypted' => true));
+ $cachedData = $rootView->getFileInfo('/foo.txt');
+ $this->assertTrue($cachedData['encrypted']);
+ $this->assertEquals($cachedData['fileid'], $id);
+
+ $this->assertFalse($rootView->getFileInfo('/non/existing'));
+ $this->assertEquals(array(), $rootView->getDirectoryContent('/non/existing'));
+ }
+
+ function testGetPath() {
+ $storage1 = $this->getTestStorage();
+ $storage2 = $this->getTestStorage();
+ $storage3 = $this->getTestStorage();
+ \OC\Files\Filesystem::mount($storage1, array(), '/');
+ \OC\Files\Filesystem::mount($storage2, array(), '/substorage');
+ \OC\Files\Filesystem::mount($storage3, array(), '/folder/anotherstorage');
+
+ $rootView = new \OC\Files\View('');
+
+ $cachedData = $rootView->getFileInfo('/foo.txt');
+ $id1 = $cachedData['fileid'];
+ $this->assertEquals('/foo.txt', $rootView->getPath($id1));
+
+ $cachedData = $rootView->getFileInfo('/substorage/foo.txt');
+ $id2 = $cachedData['fileid'];
+ $this->assertEquals('/substorage/foo.txt', $rootView->getPath($id2));
+
+ $folderView = new \OC\Files\View('/substorage');
+ $this->assertEquals('/foo.txt', $folderView->getPath($id2));
+ $this->assertNull($folderView->getPath($id1));
+ }
+
+ function testMountPointOverwrite() {
+ $storage1 = $this->getTestStorage(false);
+ $storage2 = $this->getTestStorage();
+ $storage1->mkdir('substorage');
+ \OC\Files\Filesystem::mount($storage1, array(), '/');
+ \OC\Files\Filesystem::mount($storage2, array(), '/substorage');
+
+ $rootView = new \OC\Files\View('');
+ $folderContent = $rootView->getDirectoryContent('/');
+ $this->assertEquals(4, count($folderContent));
+ }
+
+ function testCacheIncompleteFolder() {
+ $storage1 = $this->getTestStorage(false);
+ \OC\Files\Filesystem::mount($storage1, array(), '/');
+ $rootView = new \OC\Files\View('');
+
+ $entries = $rootView->getDirectoryContent('/');
+ $this->assertEquals(3, count($entries));
+
+ // /folder will already be in the cache but not scanned
+ $entries = $rootView->getDirectoryContent('/folder');
+ $this->assertEquals(1, count($entries));
+ }
+
+ public function testAutoScan() {
+ $storage1 = $this->getTestStorage(false);
+ $storage2 = $this->getTestStorage(false);
+ \OC\Files\Filesystem::mount($storage1, array(), '/');
+ \OC\Files\Filesystem::mount($storage2, array(), '/substorage');
+ $textSize = strlen("dummy file data\n");
+
+ $rootView = new \OC\Files\View('');
+
+ $cachedData = $rootView->getFileInfo('/');
+ $this->assertEquals('httpd/unix-directory', $cachedData['mimetype']);
+ $this->assertEquals(-1, $cachedData['size']);
+
+ $folderData = $rootView->getDirectoryContent('/substorage/folder');
+ $this->assertEquals('text/plain', $folderData[0]['mimetype']);
+ $this->assertEquals($textSize, $folderData[0]['size']);
+ }
+
+ function testSearch() {
+ $storage1 = $this->getTestStorage();
+ $storage2 = $this->getTestStorage();
+ $storage3 = $this->getTestStorage();
+ \OC\Files\Filesystem::mount($storage1, array(), '/');
+ \OC\Files\Filesystem::mount($storage2, array(), '/substorage');
+ \OC\Files\Filesystem::mount($storage3, array(), '/folder/anotherstorage');
+
+ $rootView = new \OC\Files\View('');
+
+ $results = $rootView->search('foo');
+ $this->assertEquals(6, count($results));
+ $paths = array();
+ foreach ($results as $result) {
+ $this->assertEquals($result['path'], \OC\Files\Filesystem::normalizePath($result['path']));
+ $paths[] = $result['path'];
+ }
+ $this->assertContains('/foo.txt', $paths);
+ $this->assertContains('/foo.png', $paths);
+ $this->assertContains('/substorage/foo.txt', $paths);
+ $this->assertContains('/substorage/foo.png', $paths);
+ $this->assertContains('/folder/anotherstorage/foo.txt', $paths);
+ $this->assertContains('/folder/anotherstorage/foo.png', $paths);
+
+ $folderView = new \OC\Files\View('/folder');
+ $results = $folderView->search('bar');
+ $this->assertEquals(2, count($results));
+ $paths = array();
+ foreach ($results as $result) {
+ $paths[] = $result['path'];
+ }
+ $this->assertContains('/anotherstorage/folder/bar.txt', $paths);
+ $this->assertContains('/bar.txt', $paths);
+
+ $results = $folderView->search('foo');
+ $this->assertEquals(2, count($results));
+ $paths = array();
+ foreach ($results as $result) {
+ $paths[] = $result['path'];
+ }
+ $this->assertContains('/anotherstorage/foo.txt', $paths);
+ $this->assertContains('/anotherstorage/foo.png', $paths);
+
+ $this->assertEquals(6, count($rootView->searchByMime('text')));
+ $this->assertEquals(3, count($folderView->searchByMime('text')));
+ }
+
+ function testWatcher() {
+ $storage1 = $this->getTestStorage();
+ \OC\Files\Filesystem::mount($storage1, array(), '/');
+
+ $rootView = new \OC\Files\View('');
+
+ $cachedData = $rootView->getFileInfo('foo.txt');
+ $this->assertEquals(16, $cachedData['size']);
+
+ $rootView->putFileInfo('foo.txt', array('mtime' => 10));
+ $storage1->file_put_contents('foo.txt', 'foo');
+ clearstatcache();
+
+ $cachedData = $rootView->getFileInfo('foo.txt');
+ $this->assertEquals(3, $cachedData['size']);
+ }
+
+ /**
+ * @param bool $scan
+ * @return \OC\Files\Storage\Storage
+ */
+ private function getTestStorage($scan = true) {
+ $storage = new \OC\Files\Storage\Temporary(array());
+ $textData = "dummy file data\n";
+ $imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png');
+ $storage->mkdir('folder');
+ $storage->file_put_contents('foo.txt', $textData);
+ $storage->file_put_contents('foo.png', $imgData);
+ $storage->file_put_contents('folder/bar.txt', $textData);
+
+ if ($scan) {
+ $scanner = $storage->getScanner();
+ $scanner->scan('');
+ }
+ $this->storages[] = $storage;
+ return $storage;
+ }
+}
diff --git a/tests/lib/filesystem.php b/tests/lib/filesystem.php
deleted file mode 100644
index 5cced4946d9..00000000000
--- a/tests/lib/filesystem.php
+++ /dev/null
@@ -1,139 +0,0 @@
-<?php
-/**
- * ownCloud
- *
- * @author Robin Appelman
- * @copyright 2012 Robin Appelman icewind@owncloud.com
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
- *
- * You should have received a copy of the GNU Affero General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-class Test_Filesystem extends UnitTestCase {
- /**
- * @var array tmpDirs
- */
- private $tmpDirs = array();
-
- /**
- * @return array
- */
- private function getStorageData() {
- $dir = OC_Helper::tmpFolder();
- $this->tmpDirs[] = $dir;
- return array('datadir' => $dir);
- }
-
- public function tearDown() {
- foreach ($this->tmpDirs as $dir) {
- OC_Helper::rmdirr($dir);
- }
- }
-
- public function setUp() {
- OC_Filesystem::clearMounts();
- }
-
- public function testMount() {
- OC_Filesystem::mount('OC_Filestorage_Local', self::getStorageData(), '/');
- $this->assertEqual('/', OC_Filesystem::getMountPoint('/'));
- $this->assertEqual('/', OC_Filesystem::getMountPoint('/some/folder'));
- $this->assertEqual('', OC_Filesystem::getInternalPath('/'));
- $this->assertEqual('some/folder', OC_Filesystem::getInternalPath('/some/folder'));
-
- OC_Filesystem::mount('OC_Filestorage_Local', self::getStorageData(), '/some');
- $this->assertEqual('/', OC_Filesystem::getMountPoint('/'));
- $this->assertEqual('/some/', OC_Filesystem::getMountPoint('/some/folder'));
- $this->assertEqual('/some/', OC_Filesystem::getMountPoint('/some/'));
- $this->assertEqual('/', OC_Filesystem::getMountPoint('/some'));
- $this->assertEqual('folder', OC_Filesystem::getInternalPath('/some/folder'));
- }
-
- public function testNormalize() {
- $this->assertEqual('/path', OC_Filesystem::normalizePath('/path/'));
- $this->assertEqual('/path/', OC_Filesystem::normalizePath('/path/', false));
- $this->assertEqual('/path', OC_Filesystem::normalizePath('path'));
- $this->assertEqual('/path', OC_Filesystem::normalizePath('\path'));
- $this->assertEqual('/foo/bar', OC_Filesystem::normalizePath('/foo//bar/'));
- $this->assertEqual('/foo/bar', OC_Filesystem::normalizePath('/foo////bar'));
- if (class_exists('Normalizer')) {
- $this->assertEqual("/foo/bar\xC3\xBC", OC_Filesystem::normalizePath("/foo/baru\xCC\x88"));
- }
- }
-
- public function testBlacklist() {
- OC_Hook::clear('OC_Filesystem');
- OC::registerFilesystemHooks();
-
- $run = true;
- OC_Hook::emit(
- OC_Filesystem::CLASSNAME,
- OC_Filesystem::signal_write,
- array(
- OC_Filesystem::signal_param_path => '/test/.htaccess',
- OC_Filesystem::signal_param_run => &$run
- )
- );
- $this->assertFalse($run);
-
- if (OC_Filesystem::getView()) {
- $user = OC_User::getUser();
- } else {
- $user = uniqid();
- OC_Filesystem::init('/' . $user . '/files');
- }
-
- OC_Filesystem::mount('OC_Filestorage_Temporary', array(), '/');
-
- $rootView = new OC_FilesystemView('');
- $rootView->mkdir('/' . $user);
- $rootView->mkdir('/' . $user . '/files');
-
- $this->assertFalse($rootView->file_put_contents('/.htaccess', 'foo'));
- $this->assertFalse(OC_Filesystem::file_put_contents('/.htaccess', 'foo'));
- $fh = fopen(__FILE__, 'r');
- $this->assertFalse(OC_Filesystem::file_put_contents('/.htaccess', $fh));
- }
-
- public function testHooks() {
- if (OC_Filesystem::getView()) {
- $user = OC_User::getUser();
- } else {
- $user = uniqid();
- OC_Filesystem::init('/' . $user . '/files');
- }
- OC_Hook::clear('OC_Filesystem');
- OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook');
-
- OC_Filesystem::mount('OC_Filestorage_Temporary', array(), '/');
-
- $rootView = new OC_FilesystemView('');
- $rootView->mkdir('/' . $user);
- $rootView->mkdir('/' . $user . '/files');
-
- OC_Filesystem::file_put_contents('/foo', 'foo');
- OC_Filesystem::mkdir('/bar');
- OC_Filesystem::file_put_contents('/bar//foo', 'foo');
-
- $tmpFile = OC_Helper::tmpFile();
- file_put_contents($tmpFile, 'foo');
- $fh = fopen($tmpFile, 'r');
- OC_Filesystem::file_put_contents('/bar//foo', $fh);
- }
-
- public function dummyHook($arguments) {
- $path = $arguments['path'];
- $this->assertEqual($path, OC_Filesystem::normalizePath($path)); //the path passed to the hook should already be normalized
- }
-}
diff --git a/tests/lib/geo.php b/tests/lib/geo.php
index d4951ee79e7..82e61608687 100644
--- a/tests/lib/geo.php
+++ b/tests/lib/geo.php
@@ -6,7 +6,7 @@
* See the COPYING-README file.
*/
-class Test_Geo extends UnitTestCase {
+class Test_Geo extends PHPUnit_Framework_TestCase {
function testTimezone() {
$result = OC_Geo::timezone(3, 3);
$expected = 'Africa/Porto-Novo';
diff --git a/tests/lib/group.php b/tests/lib/group.php
index 28264b0f168..9128bd7ddce 100644
--- a/tests/lib/group.php
+++ b/tests/lib/group.php
@@ -22,7 +22,7 @@
*
*/
-class Test_Group extends UnitTestCase {
+class Test_Group extends PHPUnit_Framework_TestCase {
function setUp() {
OC_Group::clearBackends();
}
@@ -43,24 +43,24 @@ class Test_Group extends UnitTestCase {
$this->assertFalse(OC_Group::inGroup($user1, $group2));
$this->assertFalse(OC_Group::inGroup($user2, $group2));
- $this->assertTrue(OC_Group::addToGroup($user1, $group1));
+ $this->assertTrue((bool)OC_Group::addToGroup($user1, $group1));
$this->assertTrue(OC_Group::inGroup($user1, $group1));
$this->assertFalse(OC_Group::inGroup($user2, $group1));
$this->assertFalse(OC_Group::inGroup($user1, $group2));
$this->assertFalse(OC_Group::inGroup($user2, $group2));
- $this->assertFalse(OC_Group::addToGroup($user1, $group1));
+ $this->assertFalse((bool)OC_Group::addToGroup($user1, $group1));
- $this->assertEqual(array($user1), OC_Group::usersInGroup($group1));
- $this->assertEqual(array(), OC_Group::usersInGroup($group2));
+ $this->assertEquals(array($user1), OC_Group::usersInGroup($group1));
+ $this->assertEquals(array(), OC_Group::usersInGroup($group2));
- $this->assertEqual(array($group1), OC_Group::getUserGroups($user1));
- $this->assertEqual(array(), OC_Group::getUserGroups($user2));
+ $this->assertEquals(array($group1), OC_Group::getUserGroups($user1));
+ $this->assertEquals(array(), OC_Group::getUserGroups($user2));
OC_Group::deleteGroup($group1);
- $this->assertEqual(array(), OC_Group::getUserGroups($user1));
- $this->assertEqual(array(), OC_Group::usersInGroup($group1));
+ $this->assertEquals(array(), OC_Group::getUserGroups($user1));
+ $this->assertEquals(array(), OC_Group::usersInGroup($group1));
$this->assertFalse(OC_Group::inGroup($user1, $group1));
}
@@ -69,7 +69,7 @@ class Test_Group extends UnitTestCase {
OC_Group::useBackend(new OC_Group_Dummy());
$emptyGroup = null;
- $this->assertEqual(false, OC_Group::createGroup($emptyGroup));
+ $this->assertEquals(false, OC_Group::createGroup($emptyGroup));
}
@@ -80,8 +80,8 @@ class Test_Group extends UnitTestCase {
$groupCopy = $group;
- $this->assertEqual(false, OC_Group::createGroup($groupCopy));
- $this->assertEqual(array($group), OC_Group::getGroups());
+ $this->assertEquals(false, OC_Group::createGroup($groupCopy));
+ $this->assertEquals(array($group), OC_Group::getGroups());
}
@@ -90,8 +90,8 @@ class Test_Group extends UnitTestCase {
$adminGroup = 'admin';
OC_Group::createGroup($adminGroup);
- $this->assertEqual(false, OC_Group::deleteGroup($adminGroup));
- $this->assertEqual(array($adminGroup), OC_Group::getGroups());
+ $this->assertEquals(false, OC_Group::deleteGroup($adminGroup));
+ $this->assertEquals(array($adminGroup), OC_Group::getGroups());
}
@@ -100,8 +100,8 @@ class Test_Group extends UnitTestCase {
$groupNonExistent = 'notExistent';
$user = uniqid();
- $this->assertEqual(false, OC_Group::addToGroup($user, $groupNonExistent));
- $this->assertEqual(array(), OC_Group::getGroups());
+ $this->assertEquals(false, OC_Group::addToGroup($user, $groupNonExistent));
+ $this->assertEquals(array(), OC_Group::getGroups());
}
@@ -122,7 +122,7 @@ class Test_Group extends UnitTestCase {
OC_Group::addToGroup($user3, $group1);
OC_Group::addToGroup($user3, $group2);
- $this->assertEqual(array($user1, $user2, $user3),
+ $this->assertEquals(array($user1, $user2, $user3),
OC_Group::usersInGroups(array($group1, $group2, $group3)));
// FIXME: needs more parameter variation
@@ -141,16 +141,16 @@ class Test_Group extends UnitTestCase {
OC_Group::createGroup($group1);
//groups should be added to the first registered backend
- $this->assertEqual(array($group1), $backend1->getGroups());
- $this->assertEqual(array(), $backend2->getGroups());
+ $this->assertEquals(array($group1), $backend1->getGroups());
+ $this->assertEquals(array(), $backend2->getGroups());
- $this->assertEqual(array($group1), OC_Group::getGroups());
+ $this->assertEquals(array($group1), OC_Group::getGroups());
$this->assertTrue(OC_Group::groupExists($group1));
$this->assertFalse(OC_Group::groupExists($group2));
$backend1->createGroup($group2);
- $this->assertEqual(array($group1, $group2), OC_Group::getGroups());
+ $this->assertEquals(array($group1, $group2), OC_Group::getGroups());
$this->assertTrue(OC_Group::groupExists($group1));
$this->assertTrue(OC_Group::groupExists($group2));
@@ -161,22 +161,22 @@ class Test_Group extends UnitTestCase {
$this->assertFalse(OC_Group::inGroup($user2, $group1));
- $this->assertTrue(OC_Group::addToGroup($user1, $group1));
+ $this->assertTrue((bool)OC_Group::addToGroup($user1, $group1));
$this->assertTrue(OC_Group::inGroup($user1, $group1));
$this->assertFalse(OC_Group::inGroup($user2, $group1));
$this->assertFalse($backend2->inGroup($user1, $group1));
- $this->assertFalse(OC_Group::addToGroup($user1, $group1));
+ $this->assertFalse((bool)OC_Group::addToGroup($user1, $group1));
- $this->assertEqual(array($user1), OC_Group::usersInGroup($group1));
+ $this->assertEquals(array($user1), OC_Group::usersInGroup($group1));
- $this->assertEqual(array($group1), OC_Group::getUserGroups($user1));
- $this->assertEqual(array(), OC_Group::getUserGroups($user2));
+ $this->assertEquals(array($group1), OC_Group::getUserGroups($user1));
+ $this->assertEquals(array(), OC_Group::getUserGroups($user2));
OC_Group::deleteGroup($group1);
- $this->assertEqual(array(), OC_Group::getUserGroups($user1));
- $this->assertEqual(array(), OC_Group::usersInGroup($group1));
+ $this->assertEquals(array(), OC_Group::getUserGroups($user1));
+ $this->assertEquals(array(), OC_Group::usersInGroup($group1));
$this->assertFalse(OC_Group::inGroup($user1, $group1));
}
}
diff --git a/tests/lib/group/backend.php b/tests/lib/group/backend.php
index f61abed5f29..d308232a78b 100644
--- a/tests/lib/group/backend.php
+++ b/tests/lib/group/backend.php
@@ -20,7 +20,7 @@
*
*/
-abstract class Test_Group_Backend extends UnitTestCase {
+abstract class Test_Group_Backend extends PHPUnit_Framework_TestCase {
/**
* @var OC_Group_Backend $backend
*/
@@ -52,18 +52,18 @@ abstract class Test_Group_Backend extends UnitTestCase {
$name2=$this->getGroupName();
$this->backend->createGroup($name1);
$count=count($this->backend->getGroups())-$startCount;
- $this->assertEqual(1, $count);
+ $this->assertEquals(1, $count);
$this->assertTrue((array_search($name1, $this->backend->getGroups())!==false));
$this->assertFalse((array_search($name2, $this->backend->getGroups())!==false));
$this->backend->createGroup($name2);
$count=count($this->backend->getGroups())-$startCount;
- $this->assertEqual(2, $count);
+ $this->assertEquals(2, $count);
$this->assertTrue((array_search($name1, $this->backend->getGroups())!==false));
$this->assertTrue((array_search($name2, $this->backend->getGroups())!==false));
$this->backend->deleteGroup($name2);
$count=count($this->backend->getGroups())-$startCount;
- $this->assertEqual(1, $count);
+ $this->assertEquals(1, $count);
$this->assertTrue((array_search($name1, $this->backend->getGroups())!==false));
$this->assertFalse((array_search($name2, $this->backend->getGroups())!==false));
}
@@ -91,15 +91,15 @@ abstract class Test_Group_Backend extends UnitTestCase {
$this->assertFalse($this->backend->addToGroup($user1, $group1));
- $this->assertEqual(array($user1), $this->backend->usersInGroup($group1));
- $this->assertEqual(array(), $this->backend->usersInGroup($group2));
+ $this->assertEquals(array($user1), $this->backend->usersInGroup($group1));
+ $this->assertEquals(array(), $this->backend->usersInGroup($group2));
- $this->assertEqual(array($group1), $this->backend->getUserGroups($user1));
- $this->assertEqual(array(), $this->backend->getUserGroups($user2));
+ $this->assertEquals(array($group1), $this->backend->getUserGroups($user1));
+ $this->assertEquals(array(), $this->backend->getUserGroups($user2));
$this->backend->deleteGroup($group1);
- $this->assertEqual(array(), $this->backend->getUserGroups($user1));
- $this->assertEqual(array(), $this->backend->usersInGroup($group1));
+ $this->assertEquals(array(), $this->backend->getUserGroups($user1));
+ $this->assertEquals(array(), $this->backend->usersInGroup($group1));
$this->assertFalse($this->backend->inGroup($user1, $group1));
}
}
diff --git a/tests/lib/helper.php b/tests/lib/helper.php
index cfb9a799579..336e8f8b3c5 100644
--- a/tests/lib/helper.php
+++ b/tests/lib/helper.php
@@ -6,7 +6,7 @@
* See the COPYING-README file.
*/
-class Test_Helper extends UnitTestCase {
+class Test_Helper extends PHPUnit_Framework_TestCase {
function testHumanFileSize() {
$result = OC_Helper::humanFileSize(0);
diff --git a/tests/lib/share/share.php b/tests/lib/share/share.php
index 92f5d065cf2..ab43e47726b 100644
--- a/tests/lib/share/share.php
+++ b/tests/lib/share/share.php
@@ -19,7 +19,7 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
-class Test_Share extends UnitTestCase {
+class Test_Share extends PHPUnit_Framework_TestCase {
protected $itemType;
protected $userBackend;
diff --git a/tests/lib/streamwrappers.php b/tests/lib/streamwrappers.php
index 89b2785fca6..2237ee7d378 100644
--- a/tests/lib/streamwrappers.php
+++ b/tests/lib/streamwrappers.php
@@ -1,45 +1,45 @@
<?php
/**
-* ownCloud
-*
-* @author Robin Appelman
-* @copyright 2012 Robin Appelman icewind@owncloud.com
-*
-* This library is free software; you can redistribute it and/or
-* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
-* License as published by the Free Software Foundation; either
-* version 3 of the License, or any later version.
-*
-* This library is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
-*
-* You should have received a copy of the GNU Affero General Public
-* License along with this library. If not, see <http://www.gnu.org/licenses/>.
-*
-*/
+ * ownCloud
+ *
+ * @author Robin Appelman
+ * @copyright 2012 Robin Appelman icewind@owncloud.com
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
-class Test_StreamWrappers extends UnitTestCase {
+class Test_StreamWrappers extends PHPUnit_Framework_TestCase {
public function testFakeDir() {
- $items=array('foo', 'bar');
- OC_FakeDirStream::$dirs['test']=$items;
- $dh=opendir('fakedir://test');
- $result=array();
- while($file=readdir($dh)) {
- $result[]=$file;
+ $items = array('foo', 'bar');
+ \OC\Files\Stream\Dir::register('test', $items);
+ $dh = opendir('fakedir://test');
+ $result = array();
+ while ($file = readdir($dh)) {
+ $result[] = $file;
$this->assertContains($file, $items);
}
- $this->assertEqual(count($items), count($result));
+ $this->assertEquals(count($items), count($result));
}
public function testStaticStream() {
- $sourceFile=OC::$SERVERROOT.'/tests/data/lorem.txt';
- $staticFile='static://test';
+ $sourceFile = OC::$SERVERROOT . '/tests/data/lorem.txt';
+ $staticFile = 'static://test';
$this->assertFalse(file_exists($staticFile));
file_put_contents($staticFile, file_get_contents($sourceFile));
$this->assertTrue(file_exists($staticFile));
- $this->assertEqual(file_get_contents($sourceFile), file_get_contents($staticFile));
+ $this->assertEquals(file_get_contents($sourceFile), file_get_contents($staticFile));
unlink($staticFile);
clearstatcache();
$this->assertFalse(file_exists($staticFile));
@@ -47,32 +47,51 @@ class Test_StreamWrappers extends UnitTestCase {
public function testCloseStream() {
//ensure all basic stream stuff works
- $sourceFile=OC::$SERVERROOT.'/tests/data/lorem.txt';
- $tmpFile=OC_Helper::TmpFile('.txt');
- $file='close://'.$tmpFile;
+ $sourceFile = OC::$SERVERROOT . '/tests/data/lorem.txt';
+ $tmpFile = OC_Helper::TmpFile('.txt');
+ $file = 'close://' . $tmpFile;
$this->assertTrue(file_exists($file));
file_put_contents($file, file_get_contents($sourceFile));
- $this->assertEqual(file_get_contents($sourceFile), file_get_contents($file));
+ $this->assertEquals(file_get_contents($sourceFile), file_get_contents($file));
unlink($file);
clearstatcache();
$this->assertFalse(file_exists($file));
-
+
//test callback
- $tmpFile=OC_Helper::TmpFile('.txt');
- $file='close://'.$tmpFile;
- OC_CloseStreamWrapper::$callBacks[$tmpFile]=array('Test_StreamWrappers', 'closeCallBack');
- $fh=fopen($file, 'w');
+ $tmpFile = OC_Helper::TmpFile('.txt');
+ $file = 'close://' . $tmpFile;
+ \OC\Files\Stream\Close::registerCallback($tmpFile, array('Test_StreamWrappers', 'closeCallBack'));
+ $fh = fopen($file, 'w');
fwrite($fh, 'asd');
- try{
+ try {
fclose($fh);
$this->fail('Expected exception');
- }catch(Exception $e) {
- $path=$e->getMessage();
- $this->assertEqual($path, $tmpFile);
+ } catch (Exception $e) {
+ $path = $e->getMessage();
+ $this->assertEquals($path, $tmpFile);
}
}
public static function closeCallBack($path) {
throw new Exception($path);
}
+
+ public function testOC() {
+ \OC\Files\Mount::clear();
+ $storage = new \OC\Files\Storage\Temporary(array());
+ $storage->file_put_contents('foo.txt', 'asd');
+ new \OC\Files\Mount($storage, '/');
+
+ $this->assertTrue(file_exists('oc:///foo.txt'));
+ $this->assertEquals('asd', file_get_contents('oc:///foo.txt'));
+ $this->assertEquals(array('.', '..', 'foo.txt'), scandir('oc:///'));
+
+ file_put_contents('oc:///bar.txt', 'qwerty');
+ $this->assertEquals('qwerty', $storage->file_get_contents('bar.txt'));
+ $this->assertEquals(array('.', '..', 'bar.txt', 'foo.txt'), scandir('oc:///'));
+ $this->assertEquals('qwerty', file_get_contents('oc:///bar.txt'));
+
+ unlink('oc:///foo.txt');
+ $this->assertEquals(array('.', '..', 'bar.txt'), scandir('oc:///'));
+ }
}
diff --git a/tests/lib/template.php b/tests/lib/template.php
index 736bc95255c..6e88d4c07fc 100644
--- a/tests/lib/template.php
+++ b/tests/lib/template.php
@@ -22,7 +22,7 @@
OC::autoload('OC_Template');
-class Test_TemplateFunctions extends UnitTestCase {
+class Test_TemplateFunctions extends PHPUnit_Framework_TestCase {
public function testP() {
// FIXME: do we need more testcases?
@@ -30,9 +30,8 @@ class Test_TemplateFunctions extends UnitTestCase {
ob_start();
p($htmlString);
$result = ob_get_clean();
- ob_end_clean();
- $this->assertEqual("&lt;script&gt;alert(&#039;xss&#039;);&lt;/script&gt;", $result);
+ $this->assertEquals("&lt;script&gt;alert(&#039;xss&#039;);&lt;/script&gt;", $result);
}
public function testPNormalString() {
@@ -40,9 +39,8 @@ class Test_TemplateFunctions extends UnitTestCase {
ob_start();
p($normalString);
$result = ob_get_clean();
- ob_end_clean();
- $this->assertEqual("This is a good string!", $result);
+ $this->assertEquals("This is a good string!", $result);
}
@@ -52,9 +50,8 @@ class Test_TemplateFunctions extends UnitTestCase {
ob_start();
print_unescaped($htmlString);
$result = ob_get_clean();
- ob_end_clean();
- $this->assertEqual($htmlString, $result);
+ $this->assertEquals($htmlString, $result);
}
public function testPrintUnescapedNormalString() {
@@ -62,9 +59,8 @@ class Test_TemplateFunctions extends UnitTestCase {
ob_start();
print_unescaped($normalString);
$result = ob_get_clean();
- ob_end_clean();
- $this->assertEqual("This is a good string!", $result);
+ $this->assertEquals("This is a good string!", $result);
}
diff --git a/tests/lib/user/backend.php b/tests/lib/user/backend.php
index 0b744770ea2..40674424c96 100644
--- a/tests/lib/user/backend.php
+++ b/tests/lib/user/backend.php
@@ -30,7 +30,7 @@
* For an example see /tests/lib/user/dummy.php
*/
-abstract class Test_User_Backend extends UnitTestCase {
+abstract class Test_User_Backend extends PHPUnit_Framework_TestCase {
/**
* @var OC_User_Backend $backend
*/
@@ -53,18 +53,18 @@ abstract class Test_User_Backend extends UnitTestCase {
$name2=$this->getUser();
$this->backend->createUser($name1, '');
$count=count($this->backend->getUsers())-$startCount;
- $this->assertEqual(1, $count);
+ $this->assertEquals(1, $count);
$this->assertTrue((array_search($name1, $this->backend->getUsers())!==false));
$this->assertFalse((array_search($name2, $this->backend->getUsers())!==false));
$this->backend->createUser($name2, '');
$count=count($this->backend->getUsers())-$startCount;
- $this->assertEqual(2, $count);
+ $this->assertEquals(2, $count);
$this->assertTrue((array_search($name1, $this->backend->getUsers())!==false));
$this->assertTrue((array_search($name2, $this->backend->getUsers())!==false));
$this->backend->deleteUser($name2);
$count=count($this->backend->getUsers())-$startCount;
- $this->assertEqual(1, $count);
+ $this->assertEquals(1, $count);
$this->assertTrue((array_search($name1, $this->backend->getUsers())!==false));
$this->assertFalse((array_search($name2, $this->backend->getUsers())!==false));
}
diff --git a/tests/lib/util.php b/tests/lib/util.php
index 27635cb8055..ebff3c7381a 100644
--- a/tests/lib/util.php
+++ b/tests/lib/util.php
@@ -6,7 +6,7 @@
* See the COPYING-README file.
*/
-class Test_Util extends UnitTestCase {
+class Test_Util extends PHPUnit_Framework_TestCase {
// Constructor
function Test_Util() {
diff --git a/tests/lib/vcategories.php b/tests/lib/vcategories.php
index 63516a063da..e79dd49870c 100644
--- a/tests/lib/vcategories.php
+++ b/tests/lib/vcategories.php
@@ -22,7 +22,7 @@
//require_once("../lib/template.php");
-class Test_VCategories extends UnitTestCase {
+class Test_VCategories extends PHPUnit_Framework_TestCase {
protected $objectType;
protected $user;
@@ -49,7 +49,7 @@ class Test_VCategories extends UnitTestCase {
$catmgr = new OC_VCategories($this->objectType, $this->user, $defcategories);
- $this->assertEqual(4, count($catmgr->categories()));
+ $this->assertEquals(4, count($catmgr->categories()));
}
public function testAddCategories() {
@@ -59,25 +59,25 @@ class Test_VCategories extends UnitTestCase {
foreach($categories as $category) {
$result = $catmgr->add($category);
- $this->assertTrue($result);
+ $this->assertTrue((bool)$result);
}
$this->assertFalse($catmgr->add('Family'));
$this->assertFalse($catmgr->add('fAMILY'));
- $this->assertEqual(4, count($catmgr->categories()));
+ $this->assertEquals(4, count($catmgr->categories()));
}
public function testdeleteCategories() {
$defcategories = array('Friends', 'Family', 'Work', 'Other');
$catmgr = new OC_VCategories($this->objectType, $this->user, $defcategories);
- $this->assertEqual(4, count($catmgr->categories()));
+ $this->assertEquals(4, count($catmgr->categories()));
$catmgr->delete('family');
- $this->assertEqual(3, count($catmgr->categories()));
+ $this->assertEquals(3, count($catmgr->categories()));
$catmgr->delete(array('Friends', 'Work', 'Other'));
- $this->assertEqual(0, count($catmgr->categories()));
+ $this->assertEquals(0, count($catmgr->categories()));
}
@@ -90,8 +90,8 @@ class Test_VCategories extends UnitTestCase {
$catmgr->addToCategory($id, 'Family');
}
- $this->assertEqual(1, count($catmgr->categories()));
- $this->assertEqual(9, count($catmgr->idsForCategory('Family')));
+ $this->assertEquals(1, count($catmgr->categories()));
+ $this->assertEquals(9, count($catmgr->idsForCategory('Family')));
}
/**
@@ -110,8 +110,8 @@ class Test_VCategories extends UnitTestCase {
$this->assertFalse(in_array($id, $catmgr->idsForCategory('Family')));
}
- $this->assertEqual(1, count($catmgr->categories()));
- $this->assertEqual(0, count($catmgr->idsForCategory('Family')));
+ $this->assertEquals(1, count($catmgr->categories()));
+ $this->assertEquals(0, count($catmgr->idsForCategory('Family')));
}
}
diff --git a/tests/phpunit.xml b/tests/phpunit.xml
index 23cd123edc6..f5a686c3020 100644
--- a/tests/phpunit.xml
+++ b/tests/phpunit.xml
@@ -11,4 +11,7 @@
<directory suffix=".php">../3rdparty</directory>
</exclude>
</whitelist>
+ <listeners>
+ <listener class="PHPUnit_Util_Log_JSON"></listener>
+ </listeners>
</phpunit>