diff options
author | Georg Ehrke <developer@georgehrke.com> | 2013-07-10 12:41:53 +0200 |
---|---|---|
committer | Georg Ehrke <developer@georgehrke.com> | 2013-07-10 12:41:53 +0200 |
commit | a357e5b284ed5b752864e4570cb179f3f2d88229 (patch) | |
tree | e811ea2288b5dfa069908f25f696f795a268cb53 /tests/lib | |
parent | 832779804d36d27c47325d1dcce09e566c8cee60 (diff) | |
parent | 5387e5c354440b264040816ea7fcaf6783a2ebdc (diff) | |
download | nextcloud-server-a357e5b284ed5b752864e4570cb179f3f2d88229.tar.gz nextcloud-server-a357e5b284ed5b752864e4570cb179f3f2d88229.zip |
merge conflicts ...
Diffstat (limited to 'tests/lib')
-rw-r--r-- | tests/lib/archive/tar.php | 6 | ||||
-rw-r--r-- | tests/lib/backgroundjob/timedjob.php | 3 | ||||
-rw-r--r-- | tests/lib/db.php | 28 | ||||
-rw-r--r-- | tests/lib/dbschema.php | 80 | ||||
-rw-r--r-- | tests/lib/files/cache/cache.php | 4 | ||||
-rw-r--r-- | tests/lib/files/cache/scanner.php | 52 | ||||
-rw-r--r-- | tests/lib/files/cache/updater.php | 131 | ||||
-rw-r--r-- | tests/lib/files/mount/mount.php | 46 | ||||
-rw-r--r-- | tests/lib/files/storage/storage.php | 14 | ||||
-rw-r--r-- | tests/lib/files/storage/wrapper.php | 26 | ||||
-rw-r--r-- | tests/lib/files/stream/staticstream.php | 68 | ||||
-rw-r--r-- | tests/lib/hooks/basicemitter.php | 18 | ||||
-rw-r--r-- | tests/lib/session/session.php | 2 | ||||
-rw-r--r-- | tests/lib/streamwrappers.php | 12 | ||||
-rw-r--r-- | tests/lib/util.php | 6 |
15 files changed, 416 insertions, 80 deletions
diff --git a/tests/lib/archive/tar.php b/tests/lib/archive/tar.php index e66a8740879..d831487b16f 100644 --- a/tests/lib/archive/tar.php +++ b/tests/lib/archive/tar.php @@ -10,6 +10,12 @@ require_once 'archive.php'; if (!OC_Util::runningOnWindows()) { class Test_Archive_TAR extends Test_Archive { + public function setUp() { + if (floatval(phpversion())>=5.5) { + $this->markTestSkipped('php 5.5 changed unpack function.'); + return; + } + } protected function getExisting() { $dir = OC::$SERVERROOT . '/tests/data'; return new OC_Archive_TAR($dir . '/data.tar.gz'); diff --git a/tests/lib/backgroundjob/timedjob.php b/tests/lib/backgroundjob/timedjob.php index 0af933afef8..f3c3eb4d0dd 100644 --- a/tests/lib/backgroundjob/timedjob.php +++ b/tests/lib/backgroundjob/timedjob.php @@ -41,6 +41,7 @@ class TimedJob extends \PHPUnit_Framework_TestCase { $this->fail("job should have run"); } catch (JobRun $e) { } + $this->assertTrue(true); } public function testShouldNotRunWithinInterval() { @@ -50,6 +51,7 @@ class TimedJob extends \PHPUnit_Framework_TestCase { } catch (JobRun $e) { $this->fail("job should not have run"); } + $this->assertTrue(true); } public function testShouldNotTwice() { @@ -64,5 +66,6 @@ class TimedJob extends \PHPUnit_Framework_TestCase { $this->fail("job should not have run the second time"); } } + $this->assertTrue(true); } } diff --git a/tests/lib/db.php b/tests/lib/db.php index afbdb413c3d..69e3542f926 100644 --- a/tests/lib/db.php +++ b/tests/lib/db.php @@ -40,7 +40,7 @@ class Test_DB extends PHPUnit_Framework_TestCase { $this->assertFalse((bool)$row); //PDO returns false, MDB2 returns null $query = OC_DB::prepare('INSERT INTO `*PREFIX*'.$this->table2.'` (`fullname`,`uri`) VALUES (?,?)'); $result = $query->execute(array('fullname test', 'uri_1')); - $this->assertTrue((bool)$result); + $this->assertEquals(1, $result); $query = OC_DB::prepare('SELECT `fullname`,`uri` FROM `*PREFIX*'.$this->table2.'` WHERE `uri` = ?'); $result = $query->execute(array('uri_1')); $this->assertTrue((bool)$result); @@ -57,7 +57,7 @@ class Test_DB extends PHPUnit_Framework_TestCase { public function testNOW() { $query = OC_DB::prepare('INSERT INTO `*PREFIX*'.$this->table2.'` (`fullname`,`uri`) VALUES (NOW(),?)'); $result = $query->execute(array('uri_2')); - $this->assertTrue((bool)$result); + $this->assertEquals(1, $result); $query = OC_DB::prepare('SELECT `fullname`,`uri` FROM `*PREFIX*'.$this->table2.'` WHERE `uri` = ?'); $result = $query->execute(array('uri_2')); $this->assertTrue((bool)$result); @@ -66,7 +66,7 @@ class Test_DB extends PHPUnit_Framework_TestCase { 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((bool)$result); + $this->assertEquals(1, $result); $query = OC_DB::prepare('SELECT `fullname`,`uri` FROM `*PREFIX*'.$this->table2.'` WHERE `uri` = ?'); $result = $query->execute(array('uri_3')); $this->assertTrue((bool)$result); @@ -74,11 +74,11 @@ class Test_DB extends PHPUnit_Framework_TestCase { public function testinsertIfNotExist() { $categoryentries = array( - array('user' => 'test', 'type' => 'contact', 'category' => 'Family'), - array('user' => 'test', 'type' => 'contact', 'category' => 'Friends'), - array('user' => 'test', 'type' => 'contact', 'category' => 'Coworkers'), - array('user' => 'test', 'type' => 'contact', 'category' => 'Coworkers'), - array('user' => 'test', 'type' => 'contact', 'category' => 'School'), + array('user' => 'test', 'type' => 'contact', 'category' => 'Family', 'expectedResult' => 1), + array('user' => 'test', 'type' => 'contact', 'category' => 'Friends', 'expectedResult' => 1), + array('user' => 'test', 'type' => 'contact', 'category' => 'Coworkers', 'expectedResult' => 1), + array('user' => 'test', 'type' => 'contact', 'category' => 'Coworkers', 'expectedResult' => 0), + array('user' => 'test', 'type' => 'contact', 'category' => 'School', 'expectedResult' => 1), ); foreach($categoryentries as $entry) { @@ -88,13 +88,13 @@ class Test_DB extends PHPUnit_Framework_TestCase { 'type' => $entry['type'], 'category' => $entry['category'], )); - $this->assertTrue((bool)$result); + $this->assertEquals($entry['expectedResult'], $result); } $query = OC_DB::prepare('SELECT * FROM `*PREFIX*'.$this->table3.'`'); $result = $query->execute(); $this->assertTrue((bool)$result); - $this->assertEquals('4', $result->numRows()); + $this->assertEquals(4, $result->numRows()); } public function testinsertIfNotExistDontOverwrite() { @@ -105,14 +105,14 @@ class Test_DB extends PHPUnit_Framework_TestCase { // 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((bool)$result); + $this->assertEquals(1, $result); $query = OC_DB::prepare('SELECT `fullname`, `uri`, `carddata` FROM `*PREFIX*'.$this->table2.'` WHERE `uri` = ?'); $result = $query->execute(array($uri)); $this->assertTrue((bool)$result); $row = $result->fetchRow(); $this->assertArrayHasKey('carddata', $row); $this->assertEquals($carddata, $row['carddata']); - $this->assertEquals('1', $result->numRows()); + $this->assertEquals(1, $result->numRows()); // Try to insert a new row $result = OC_DB::insertIfNotExist('*PREFIX*'.$this->table2, @@ -120,7 +120,7 @@ class Test_DB extends PHPUnit_Framework_TestCase { 'fullname' => $fullname, 'uri' => $uri, )); - $this->assertTrue((bool)$result); + $this->assertEquals(0, $result); $query = OC_DB::prepare('SELECT `fullname`, `uri`, `carddata` FROM `*PREFIX*'.$this->table2.'` WHERE `uri` = ?'); $result = $query->execute(array($uri)); @@ -130,7 +130,7 @@ class Test_DB extends PHPUnit_Framework_TestCase { // Test that previously inserted data isn't overwritten $this->assertEquals($carddata, $row['carddata']); // And that a new row hasn't been inserted. - $this->assertEquals('1', $result->numRows()); + $this->assertEquals(1, $result->numRows()); } } diff --git a/tests/lib/dbschema.php b/tests/lib/dbschema.php index 59f203993ef..c2e55eabf4b 100644 --- a/tests/lib/dbschema.php +++ b/tests/lib/dbschema.php @@ -7,9 +7,8 @@ */ 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; + protected $schema_file = 'static://test_db_scheme'; + protected $schema_file2 = 'static://test_db_scheme2'; protected $table1; protected $table2; @@ -20,19 +19,20 @@ class Test_DBSchema extends PHPUnit_Framework_TestCase { $r = '_'.OC_Util::generate_random_bytes('4').'_'; $content = file_get_contents( $dbfile ); $content = str_replace( '*dbprefix*', '*dbprefix*'.$r, $content ); - file_put_contents( self::$schema_file, $content ); + file_put_contents( $this->schema_file, $content ); $content = file_get_contents( $dbfile2 ); $content = str_replace( '*dbprefix*', '*dbprefix*'.$r, $content ); - file_put_contents( self::$schema_file2, $content ); + file_put_contents( $this->schema_file2, $content ); - $this->test_prefix = $r; - $this->table1 = $this->test_prefix.'cntcts_addrsbks'; - $this->table2 = $this->test_prefix.'cntcts_cards'; + $prefix = OC_Config::getValue( "dbtableprefix", "oc_" ); + + $this->table1 = $prefix.$r.'cntcts_addrsbks'; + $this->table2 = $prefix.$r.'cntcts_cards'; } public function tearDown() { - unlink(self::$schema_file); - unlink(self::$schema_file2); + unlink($this->schema_file); + unlink($this->schema_file2); } // everything in one test, they depend on each other @@ -47,13 +47,13 @@ class Test_DBSchema extends PHPUnit_Framework_TestCase { } public function doTestSchemaCreating() { - OC_DB::createDbFromStructure(self::$schema_file); + OC_DB::createDbFromStructure($this->schema_file); $this->assertTableExist($this->table1); $this->assertTableExist($this->table2); } public function doTestSchemaChanging() { - OC_DB::updateDbFromStructure(self::$schema_file2); + OC_DB::updateDbFromStructure($this->schema_file2); $this->assertTableExist($this->table2); } @@ -66,67 +66,61 @@ class Test_DBSchema extends PHPUnit_Framework_TestCase { } public function doTestSchemaRemoving() { - OC_DB::removeDBStructure(self::$schema_file); + OC_DB::removeDBStructure($this->schema_file); $this->assertTableNotExist($this->table1); $this->assertTableNotExist($this->table2); } public function tableExist($table) { - $table = '*PREFIX*' . $table; switch (OC_Config::getValue( 'dbtype', 'sqlite' )) { case 'sqlite': case 'sqlite3': $sql = "SELECT name FROM sqlite_master " - . "WHERE type = 'table' AND name != 'sqlite_sequence' " - . "AND name != 'geometry_columns' AND name != 'spatial_ref_sys' " - . "UNION ALL SELECT name FROM sqlite_temp_master " - . "WHERE type = 'table' AND name = '".$table."'"; - $query = OC_DB::prepare($sql); - $result = $query->execute(array()); - $exists = $result && $result->fetchOne(); + . "WHERE type = 'table' AND name = ? " + . "UNION ALL SELECT name FROM sqlite_temp_master " + . "WHERE type = 'table' AND name = ?"; + $result = \OC_DB::executeAudited($sql, array($table, $table)); break; case 'mysql': - $sql = 'SHOW TABLES LIKE "'.$table.'"'; - $query = OC_DB::prepare($sql); - $result = $query->execute(array()); - $exists = $result && $result->fetchOne(); + $sql = 'SHOW TABLES LIKE ?'; + $result = \OC_DB::executeAudited($sql, array($table)); break; case 'pgsql': - $sql = "SELECT tablename AS table_name, schemaname AS schema_name " - . "FROM pg_tables WHERE schemaname NOT LIKE 'pg_%' " - . "AND schemaname != 'information_schema' " - . "AND tablename = '".$table."'"; - $query = OC_DB::prepare($sql); - $result = $query->execute(array()); - $exists = $result && $result->fetchOne(); + $sql = 'SELECT tablename AS table_name, schemaname AS schema_name ' + . 'FROM pg_tables WHERE schemaname NOT LIKE \'pg_%\' ' + . 'AND schemaname != \'information_schema\' ' + . 'AND tablename = ?'; + $result = \OC_DB::executeAudited($sql, array($table)); break; case 'oci': - $sql = 'SELECT table_name FROM user_tables WHERE table_name = ?'; + $sql = 'SELECT TABLE_NAME FROM USER_TABLES WHERE TABLE_NAME = ?'; $result = \OC_DB::executeAudited($sql, array($table)); - $exists = (bool)$result->fetchOne(); //oracle uses MDB2 and returns null break; case 'mssql': - $sql = "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '{$table}'"; - $query = OC_DB::prepare($sql); - $result = $query->execute(array()); - $exists = $result && $result->fetchOne(); + $sql = 'SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = ?'; + $result = \OC_DB::executeAudited($sql, array($table)); break; } - return $exists; + + $name = $result->fetchOne(); //FIXME checking with '$result->numRows() === 1' does not seem to work? + if ($name === $table) { + return true; + } else { + return false; + } } public function assertTableExist($table) { - $this->assertTrue($this->tableExist($table)); + $this->assertTrue($this->tableExist($table), 'Table ' . $table . ' does not exist'); } public function assertTableNotExist($table) { $type=OC_Config::getValue( "dbtype", "sqlite" ); if( $type == 'sqlite' || $type == 'sqlite3' ) { // sqlite removes the tables after closing the DB - } - else { - $this->assertFalse($this->tableExist($table)); + } else { + $this->assertFalse($this->tableExist($table), 'Table ' . $table . ' exists.'); } } } diff --git a/tests/lib/files/cache/cache.php b/tests/lib/files/cache/cache.php index f272655925b..527c1d1b2a1 100644 --- a/tests/lib/files/cache/cache.php +++ b/tests/lib/files/cache/cache.php @@ -348,7 +348,9 @@ class Cache extends \PHPUnit_Framework_TestCase { } public function tearDown() { - $this->cache->clear(); + if ($this->cache) { + $this->cache->clear(); + } } public function setUp() { diff --git a/tests/lib/files/cache/scanner.php b/tests/lib/files/cache/scanner.php index 3885c99e6d3..263ceadccc7 100644 --- a/tests/lib/files/cache/scanner.php +++ b/tests/lib/files/cache/scanner.php @@ -104,7 +104,7 @@ class Scanner extends \PHPUnit_Framework_TestCase { $this->assertNotEquals($cachedDataFolder['size'], -1); } - function testBackgroundScan(){ + function testBackgroundScan() { $this->fillTestFolders(); $this->storage->mkdir('folder2'); $this->storage->file_put_contents('folder2/bar.txt', 'foobar'); @@ -126,6 +126,46 @@ class Scanner extends \PHPUnit_Framework_TestCase { $this->assertFalse($this->cache->getIncomplete()); } + public function testReuseExisting() { + $this->fillTestFolders(); + + $this->scanner->scan(''); + $oldData = $this->cache->get(''); + $this->storage->unlink('folder/bar.txt'); + $this->cache->put('folder', array('mtime' => $this->storage->filemtime('folder'))); + $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_SIZE); + $newData = $this->cache->get(''); + $this->assertNotEquals($oldData['etag'], $newData['etag']); + $this->assertEquals($oldData['size'], $newData['size']); + + $oldData = $newData; + $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_ETAG); + $newData = $this->cache->get(''); + $this->assertEquals($oldData['etag'], $newData['etag']); + $this->assertEquals(-1, $newData['size']); + } + + public function testRemovedFile() { + $this->fillTestFolders(); + + $this->scanner->scan(''); + $this->assertTrue($this->cache->inCache('foo.txt')); + $this->storage->unlink('foo.txt'); + $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW); + $this->assertFalse($this->cache->inCache('foo.txt')); + } + + public function testRemovedFolder() { + $this->fillTestFolders(); + + $this->scanner->scan(''); + $this->assertTrue($this->cache->inCache('folder/bar.txt')); + $this->storage->unlink('/folder'); + $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW); + $this->assertFalse($this->cache->inCache('folder')); + $this->assertFalse($this->cache->inCache('folder/bar.txt')); + } + function setUp() { $this->storage = new \OC\Files\Storage\Temporary(array()); $this->scanner = new \OC\Files\Cache\Scanner($this->storage); @@ -133,9 +173,11 @@ class Scanner extends \PHPUnit_Framework_TestCase { } function tearDown() { - $ids = $this->cache->getAll(); - $permissionsCache = $this->storage->getPermissionsCache(); - $permissionsCache->removeMultiple($ids, \OC_User::getUser()); - $this->cache->clear(); + if ($this->cache) { + $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 index dad3cd7e650..5d7997b0544 100644 --- a/tests/lib/files/cache/updater.php +++ b/tests/lib/files/cache/updater.php @@ -56,7 +56,7 @@ class Updater extends \PHPUnit_Framework_TestCase { \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'); - + \OC_Hook::connect('OC_Filesystem', 'post_touch', '\OC\Files\Cache\Updater', 'touchHook'); } public function tearDown() { @@ -69,6 +69,7 @@ class Updater extends \PHPUnit_Framework_TestCase { public function testWrite() { $textSize = strlen("dummy file data\n"); $imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo.png'); + $this->cache->put('foo.txt', array('mtime' => 100)); $rootCachedData = $this->cache->get(''); $this->assertEquals(3 * $textSize + $imageSize, $rootCachedData['size']); @@ -77,11 +78,9 @@ class Updater extends \PHPUnit_Framework_TestCase { $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')); @@ -96,6 +95,27 @@ class Updater extends \PHPUnit_Framework_TestCase { $this->assertGreaterThanOrEqual($rootCachedData['mtime'], $mtime); } + public function testWriteWithMountPoints() { + $storage2 = new \OC\Files\Storage\Temporary(array()); + $cache2 = $storage2->getCache(); + Filesystem::mount($storage2, array(), '/' . self::$user . '/files/folder/substorage'); + $folderCachedData = $this->cache->get('folder'); + $substorageCachedData = $cache2->get(''); + Filesystem::file_put_contents('folder/substorage/foo.txt', 'asd'); + $this->assertTrue($cache2->inCache('foo.txt')); + $cachedData = $cache2->get('foo.txt'); + $this->assertEquals(3, $cachedData['size']); + $mtime = $cachedData['mtime']; + + $cachedData = $cache2->get(''); + $this->assertNotEquals($substorageCachedData['etag'], $cachedData['etag']); + $this->assertEquals($mtime, $cachedData['mtime']); + + $cachedData = $this->cache->get('folder'); + $this->assertNotEquals($folderCachedData['etag'], $cachedData['etag']); + $this->assertEquals($mtime, $cachedData['mtime']); + } + public function testDelete() { $textSize = strlen("dummy file data\n"); $imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo.png'); @@ -103,7 +123,7 @@ class Updater extends \PHPUnit_Framework_TestCase { $this->assertEquals(3 * $textSize + $imageSize, $rootCachedData['size']); $this->assertTrue($this->cache->inCache('foo.txt')); - Filesystem::unlink('foo.txt', 'asd'); + Filesystem::unlink('foo.txt'); $this->assertFalse($this->cache->inCache('foo.txt')); $cachedData = $this->cache->get(''); $this->assertEquals(2 * $textSize + $imageSize, $cachedData['size']); @@ -123,6 +143,26 @@ class Updater extends \PHPUnit_Framework_TestCase { $this->assertGreaterThanOrEqual($rootCachedData['mtime'], $cachedData['mtime']); } + public function testDeleteWithMountPoints() { + $storage2 = new \OC\Files\Storage\Temporary(array()); + $cache2 = $storage2->getCache(); + Filesystem::mount($storage2, array(), '/' . self::$user . '/files/folder/substorage'); + Filesystem::file_put_contents('folder/substorage/foo.txt', 'asd'); + $this->assertTrue($cache2->inCache('foo.txt')); + $folderCachedData = $this->cache->get('folder'); + $substorageCachedData = $cache2->get(''); + Filesystem::unlink('folder/substorage/foo.txt'); + $this->assertFalse($cache2->inCache('foo.txt')); + + $cachedData = $cache2->get(''); + $this->assertNotEquals($substorageCachedData['etag'], $cachedData['etag']); + $this->assertGreaterThanOrEqual($substorageCachedData['mtime'], $cachedData['mtime']); + + $cachedData = $this->cache->get('folder'); + $this->assertNotEquals($folderCachedData['etag'], $cachedData['etag']); + $this->assertGreaterThanOrEqual($folderCachedData['mtime'], $cachedData['mtime']); + } + public function testRename() { $textSize = strlen("dummy file data\n"); $imageSize = filesize(\OC::$SERVERROOT . '/core/img/logo.png'); @@ -142,4 +182,87 @@ class Updater extends \PHPUnit_Framework_TestCase { $this->assertEquals(3 * $textSize + $imageSize, $cachedData['size']); $this->assertNotEquals($rootCachedData['etag'], $cachedData['etag']); } + + public function testRenameWithMountPoints() { + $storage2 = new \OC\Files\Storage\Temporary(array()); + $cache2 = $storage2->getCache(); + Filesystem::mount($storage2, array(), '/' . self::$user . '/files/folder/substorage'); + Filesystem::file_put_contents('folder/substorage/foo.txt', 'asd'); + $this->assertTrue($cache2->inCache('foo.txt')); + $folderCachedData = $this->cache->get('folder'); + $substorageCachedData = $cache2->get(''); + $fooCachedData = $cache2->get('foo.txt'); + Filesystem::rename('folder/substorage/foo.txt', 'folder/substorage/bar.txt'); + $this->assertFalse($cache2->inCache('foo.txt')); + $this->assertTrue($cache2->inCache('bar.txt')); + $cachedData = $cache2->get('bar.txt'); + $this->assertEquals($fooCachedData['fileid'], $cachedData['fileid']); + $mtime = $cachedData['mtime']; + + $cachedData = $cache2->get(''); + $this->assertNotEquals($substorageCachedData['etag'], $cachedData['etag']); + // rename can cause mtime change - invalid assert +// $this->assertEquals($mtime, $cachedData['mtime']); + + $cachedData = $this->cache->get('folder'); + $this->assertNotEquals($folderCachedData['etag'], $cachedData['etag']); + // rename can cause mtime change - invalid assert +// $this->assertEquals($mtime, $cachedData['mtime']); + } + + public function testTouch() { + $rootCachedData = $this->cache->get(''); + $fooCachedData = $this->cache->get('foo.txt'); + Filesystem::touch('foo.txt'); + $cachedData = $this->cache->get('foo.txt'); + $this->assertNotEquals($fooCachedData['etag'], $cachedData['etag']); + $this->assertGreaterThanOrEqual($fooCachedData['mtime'], $cachedData['mtime']); + + $cachedData = $this->cache->get(''); + $this->assertNotEquals($rootCachedData['etag'], $cachedData['etag']); + $this->assertGreaterThanOrEqual($rootCachedData['mtime'], $cachedData['mtime']); + $rootCachedData = $cachedData; + + $time = 1371006070; + $barCachedData = $this->cache->get('folder/bar.txt'); + $folderCachedData = $this->cache->get('folder'); + Filesystem::touch('folder/bar.txt', $time); + $cachedData = $this->cache->get('folder/bar.txt'); + $this->assertNotEquals($barCachedData['etag'], $cachedData['etag']); + $this->assertEquals($time, $cachedData['mtime']); + + $cachedData = $this->cache->get('folder'); + $this->assertNotEquals($folderCachedData['etag'], $cachedData['etag']); + $this->assertEquals($time, $cachedData['mtime']); + + $cachedData = $this->cache->get(''); + $this->assertNotEquals($rootCachedData['etag'], $cachedData['etag']); + $this->assertEquals($time, $cachedData['mtime']); + } + + public function testTouchWithMountPoints() { + $storage2 = new \OC\Files\Storage\Temporary(array()); + $cache2 = $storage2->getCache(); + Filesystem::mount($storage2, array(), '/' . self::$user . '/files/folder/substorage'); + Filesystem::file_put_contents('folder/substorage/foo.txt', 'asd'); + $this->assertTrue($cache2->inCache('foo.txt')); + $folderCachedData = $this->cache->get('folder'); + $substorageCachedData = $cache2->get(''); + $fooCachedData = $cache2->get('foo.txt'); + $cachedData = $cache2->get('foo.txt'); + $time = 1371006070; + Filesystem::touch('folder/substorage/foo.txt', $time); + $cachedData = $cache2->get('foo.txt'); + $this->assertNotEquals($fooCachedData['etag'], $cachedData['etag']); + $this->assertEquals($time, $cachedData['mtime']); + + $cachedData = $cache2->get(''); + $this->assertNotEquals($substorageCachedData['etag'], $cachedData['etag']); + $this->assertEquals($time, $cachedData['mtime']); + + $cachedData = $this->cache->get('folder'); + $this->assertNotEquals($folderCachedData['etag'], $cachedData['etag']); + $this->assertEquals($time, $cachedData['mtime']); + } + } diff --git a/tests/lib/files/mount/mount.php b/tests/lib/files/mount/mount.php new file mode 100644 index 00000000000..b057204ad35 --- /dev/null +++ b/tests/lib/files/mount/mount.php @@ -0,0 +1,46 @@ +<?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\Mount; + + +use OC\Files\Storage\Loader; +use OC\Files\Storage\Wrapper\Wrapper; + +class Mount extends \PHPUnit_Framework_TestCase { + public function testFromStorageObject() { + $storage = $this->getMockBuilder('\OC\Files\Storage\Temporary') + ->disableOriginalConstructor() + ->getMock(); + $mount = new \OC\Files\Mount\Mount($storage, '/foo'); + $this->assertInstanceOf('\OC\Files\Storage\Temporary', $mount->getStorage()); + } + + public function testFromStorageClassname() { + $mount = new \OC\Files\Mount\Mount('\OC\Files\Storage\Temporary', '/foo'); + $this->assertInstanceOf('\OC\Files\Storage\Temporary', $mount->getStorage()); + } + + public function testWrapper() { + $test = $this; + $wrapper = function ($mountPoint, $storage) use (&$test) { + $test->assertEquals('/foo/', $mountPoint); + $test->assertInstanceOf('\OC\Files\Storage\Storage', $storage); + return new Wrapper(array('storage' => $storage)); + }; + + $loader = new Loader(); + $loader->addStorageWrapper($wrapper); + + $storage = $this->getMockBuilder('\OC\Files\Storage\Temporary') + ->disableOriginalConstructor() + ->getMock(); + $mount = new \OC\Files\Mount\Mount($storage, '/foo', array(), $loader); + $this->assertInstanceOf('\OC\Files\Storage\Wrapper\Wrapper', $mount->getStorage()); + } +} diff --git a/tests/lib/files/storage/storage.php b/tests/lib/files/storage/storage.php index 0e22f26ae83..fb3e05e66b3 100644 --- a/tests/lib/files/storage/storage.php +++ b/tests/lib/files/storage/storage.php @@ -258,9 +258,21 @@ abstract class Storage extends \PHPUnit_Framework_TestCase { $this->assertEquals(file_get_contents($textFile), $content); } - public function testTouchCreateFile(){ + public function testTouchCreateFile() { $this->assertFalse($this->instance->file_exists('foo')); $this->instance->touch('foo'); $this->assertTrue($this->instance->file_exists('foo')); } + + public function testRecursiveRmdir() { + $this->instance->mkdir('folder'); + $this->instance->mkdir('folder/bar'); + $this->instance->file_put_contents('folder/asd.txt', 'foobar'); + $this->instance->file_put_contents('folder/bar/foo.txt', 'asd'); + $this->instance->rmdir('folder'); + $this->assertFalse($this->instance->file_exists('folder/asd.txt')); + $this->assertFalse($this->instance->file_exists('folder/bar/foo.txt')); + $this->assertFalse($this->instance->file_exists('folder/bar')); + $this->assertFalse($this->instance->file_exists('folder')); + } } diff --git a/tests/lib/files/storage/wrapper.php b/tests/lib/files/storage/wrapper.php new file mode 100644 index 00000000000..2794a0a6263 --- /dev/null +++ b/tests/lib/files/storage/wrapper.php @@ -0,0 +1,26 @@ +<?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\Storage; + +class Wrapper extends Storage { + /** + * @var string tmpDir + */ + private $tmpDir; + + public function setUp() { + $this->tmpDir = \OC_Helper::tmpFolder(); + $storage = new \OC\Files\Storage\Local(array('datadir' => $this->tmpDir)); + $this->instance = new \OC\Files\Storage\Wrapper\Wrapper(array('storage' => $storage)); + } + + public function tearDown() { + \OC_Helper::rmdirr($this->tmpDir); + } +} diff --git a/tests/lib/files/stream/staticstream.php b/tests/lib/files/stream/staticstream.php new file mode 100644 index 00000000000..d55086196a0 --- /dev/null +++ b/tests/lib/files/stream/staticstream.php @@ -0,0 +1,68 @@ +<?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\Stream; + +class StaticStream extends \PHPUnit_Framework_TestCase { + + private $sourceFile; + private $sourceText; + + public function __construct() { + $this->sourceFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; + $this->sourceText = file_get_contents($this->sourceFile); + } + + public function tearDown() { + \OC\Files\Stream\StaticStream::clear(); + } + + public function testContent() { + file_put_contents('static://foo', $this->sourceText); + $this->assertEquals($this->sourceText, file_get_contents('static://foo')); + } + + public function testMultipleFiles() { + file_put_contents('static://foo', $this->sourceText); + file_put_contents('static://bar', strrev($this->sourceText)); + $this->assertEquals($this->sourceText, file_get_contents('static://foo')); + $this->assertEquals(strrev($this->sourceText), file_get_contents('static://bar')); + } + + public function testOverwrite() { + file_put_contents('static://foo', $this->sourceText); + file_put_contents('static://foo', 'qwerty'); + $this->assertEquals('qwerty', file_get_contents('static://foo')); + } + + public function testIsFile() { + $this->assertFalse(is_file('static://foo')); + file_put_contents('static://foo', $this->sourceText); + $this->assertTrue(is_file('static://foo')); + } + + public function testIsDir() { + $this->assertFalse(is_dir('static://foo')); + file_put_contents('static://foo', $this->sourceText); + $this->assertFalse(is_dir('static://foo')); + } + + public function testFileType() { + file_put_contents('static://foo', $this->sourceText); + $this->assertEquals('file', filetype('static://foo')); + } + + public function testUnlink() { + $this->assertFalse(file_exists('static://foo')); + file_put_contents('static://foo', $this->sourceText); + $this->assertTrue(file_exists('static://foo')); + unlink('static://foo'); + clearstatcache(); + $this->assertFalse(file_exists('static://foo')); + } +} diff --git a/tests/lib/hooks/basicemitter.php b/tests/lib/hooks/basicemitter.php index f48dc53c563..0eae730d030 100644 --- a/tests/lib/hooks/basicemitter.php +++ b/tests/lib/hooks/basicemitter.php @@ -155,6 +155,8 @@ class BasicEmitter extends \PHPUnit_Framework_TestCase { $this->emitter->listen('Test', 'test', $listener); $this->emitter->removeListener('Test', 'test', $listener); $this->emitter->emitEvent('Test', 'test'); + + $this->assertTrue(true); } public function testRemoveWildcardListener() { @@ -168,6 +170,8 @@ class BasicEmitter extends \PHPUnit_Framework_TestCase { $this->emitter->listen('Test', 'test', $listener2); $this->emitter->removeListener('Test', 'test'); $this->emitter->emitEvent('Test', 'test'); + + $this->assertTrue(true); } public function testRemoveWildcardMethod() { @@ -179,6 +183,8 @@ class BasicEmitter extends \PHPUnit_Framework_TestCase { $this->emitter->removeListener('Test', null, $listener); $this->emitter->emitEvent('Test', 'test'); $this->emitter->emitEvent('Test', 'foo'); + + $this->assertTrue(true); } public function testRemoveWildcardScope() { @@ -190,6 +196,8 @@ class BasicEmitter extends \PHPUnit_Framework_TestCase { $this->emitter->removeListener(null, 'test', $listener); $this->emitter->emitEvent('Test', 'test'); $this->emitter->emitEvent('Bar', 'test'); + + $this->assertTrue(true); } public function testRemoveWildcardScopeAndMethod() { @@ -203,6 +211,8 @@ class BasicEmitter extends \PHPUnit_Framework_TestCase { $this->emitter->emitEvent('Test', 'test'); $this->emitter->emitEvent('Test', 'foo'); $this->emitter->emitEvent('Bar', 'foo'); + + $this->assertTrue(true); } /** @@ -219,6 +229,8 @@ class BasicEmitter extends \PHPUnit_Framework_TestCase { $this->emitter->listen('Test', 'test', $listener2); $this->emitter->removeListener('Test', 'test', $listener1); $this->emitter->emitEvent('Test', 'test'); + + $this->assertTrue(true); } /** @@ -232,6 +244,8 @@ class BasicEmitter extends \PHPUnit_Framework_TestCase { $this->emitter->listen('Test', 'foo', $listener); $this->emitter->removeListener('Test', 'foo', $listener); $this->emitter->emitEvent('Test', 'test'); + + $this->assertTrue(true); } /** @@ -245,6 +259,8 @@ class BasicEmitter extends \PHPUnit_Framework_TestCase { $this->emitter->listen('Bar', 'test', $listener); $this->emitter->removeListener('Bar', 'test', $listener); $this->emitter->emitEvent('Test', 'test'); + + $this->assertTrue(true); } /** @@ -257,5 +273,7 @@ class BasicEmitter extends \PHPUnit_Framework_TestCase { $this->emitter->listen('Test', 'test', $listener); $this->emitter->removeListener('Bar', 'test', $listener); $this->emitter->emitEvent('Test', 'test'); + + $this->assertTrue(true); } } diff --git a/tests/lib/session/session.php b/tests/lib/session/session.php index 72dee44e7cb..9ce11274c84 100644 --- a/tests/lib/session/session.php +++ b/tests/lib/session/session.php @@ -44,7 +44,9 @@ abstract class Session extends \PHPUnit_Framework_TestCase { } public function testRemoveNonExisting() { + $this->assertFalse($this->instance->exists('foo')); $this->instance->remove('foo'); + $this->assertFalse($this->instance->exists('foo')); } public function testNotExistsAfterClear() { diff --git a/tests/lib/streamwrappers.php b/tests/lib/streamwrappers.php index c7e51ccfa48..d15b712139d 100644 --- a/tests/lib/streamwrappers.php +++ b/tests/lib/streamwrappers.php @@ -33,18 +33,6 @@ class Test_StreamWrappers extends PHPUnit_Framework_TestCase { $this->assertEquals(count($items), count($result)); } - public function testStaticStream() { - $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->assertEquals(file_get_contents($sourceFile), file_get_contents($staticFile)); - unlink($staticFile); - clearstatcache(); - $this->assertFalse(file_exists($staticFile)); - } - public function testCloseStream() { //ensure all basic stream stuff works $sourceFile = OC::$SERVERROOT . '/tests/data/lorem.txt'; diff --git a/tests/lib/util.php b/tests/lib/util.php index 1f253825920..9742d57ac7a 100644 --- a/tests/lib/util.php +++ b/tests/lib/util.php @@ -37,6 +37,12 @@ class Test_Util extends PHPUnit_Framework_TestCase { $result = OC_Util::sanitizeHTML($goodString); $this->assertEquals("This is an harmless string.", $result); } + + function testEncodePath(){ + $component = '/§#@test%&^ä/-child'; + $result = OC_Util::encodePath($component); + $this->assertEquals("/%C2%A7%23%40test%25%26%5E%C3%A4/-child", $result); + } function testGenerate_random_bytes() { $result = strlen(OC_Util::generate_random_bytes(59)); |