diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/karma.config.js | 3 | ||||
-rw-r--r-- | tests/lib/connector/sabre/aborteduploaddetectionplugin.php | 12 | ||||
-rw-r--r-- | tests/lib/connector/sabre/directory.php | 6 | ||||
-rw-r--r-- | tests/lib/connector/sabre/file.php | 8 | ||||
-rw-r--r-- | tests/lib/connector/sabre/objecttree.php | 5 | ||||
-rw-r--r-- | tests/lib/connector/sabre/quotaplugin.php | 12 | ||||
-rw-r--r-- | tests/lib/files/cache/changepropagator.php | 72 | ||||
-rw-r--r-- | tests/lib/files/cache/scanner.php | 8 | ||||
-rw-r--r-- | tests/lib/files/utils/scanner.php | 64 | ||||
-rw-r--r-- | tests/lib/files/view.php | 30 |
10 files changed, 176 insertions, 44 deletions
diff --git a/tests/karma.config.js b/tests/karma.config.js index 846e8f7be91..1f903f58210 100644 --- a/tests/karma.config.js +++ b/tests/karma.config.js @@ -52,7 +52,8 @@ module.exports = function(config) { // only test these files, others are not ready and mess // up with the global namespace/classes/state 'apps/files_sharing/js/app.js', - 'apps/files_sharing/js/sharedfilelist.js' + 'apps/files_sharing/js/sharedfilelist.js', + 'apps/files_sharing/js/share.js' ], testFiles: ['apps/files_sharing/tests/js/*.js'] }]; diff --git a/tests/lib/connector/sabre/aborteduploaddetectionplugin.php b/tests/lib/connector/sabre/aborteduploaddetectionplugin.php index 60d141e72bc..7e9f70ddcd3 100644 --- a/tests/lib/connector/sabre/aborteduploaddetectionplugin.php +++ b/tests/lib/connector/sabre/aborteduploaddetectionplugin.php @@ -9,7 +9,7 @@ class Test_OC_Connector_Sabre_AbortedUploadDetectionPlugin extends PHPUnit_Framework_TestCase { /** - * @var Sabre_DAV_Server + * @var \Sabre\DAV\Server */ private $server; @@ -19,7 +19,7 @@ class Test_OC_Connector_Sabre_AbortedUploadDetectionPlugin extends PHPUnit_Frame private $plugin; private function init($view) { - $this->server = new Sabre_DAV_Server(); + $this->server = new \Sabre\DAV\Server(); $this->plugin = new OC_Connector_Sabre_AbortedUploadDetectionPlugin($view); $this->plugin->initialize($this->server); } @@ -30,7 +30,7 @@ class Test_OC_Connector_Sabre_AbortedUploadDetectionPlugin extends PHPUnit_Frame public function testLength($expected, $headers) { $this->init(null); - $this->server->httpRequest = new Sabre_HTTP_Request($headers); + $this->server->httpRequest = new \Sabre\HTTP\Request($headers); $length = $this->plugin->getLength(); $this->assertEquals($expected, $length); } @@ -42,14 +42,14 @@ class Test_OC_Connector_Sabre_AbortedUploadDetectionPlugin extends PHPUnit_Frame $this->init($this->buildFileViewMock($fileSize)); $headers['REQUEST_METHOD'] = $method; - $this->server->httpRequest = new Sabre_HTTP_Request($headers); + $this->server->httpRequest = new Sabre\HTTP\Request($headers); $this->plugin->verifyContentLength('foo.txt'); $this->assertTrue(true); } /** * @dataProvider verifyContentLengthFailedProvider - * @expectedException Sabre_DAV_Exception_BadRequest + * @expectedException \Sabre\DAV\Exception\BadRequest */ public function testVerifyContentLengthFailed($method, $fileSize, $headers) { $view = $this->buildFileViewMock($fileSize); @@ -58,7 +58,7 @@ class Test_OC_Connector_Sabre_AbortedUploadDetectionPlugin extends PHPUnit_Frame $view->expects($this->once())->method('unlink'); $headers['REQUEST_METHOD'] = $method; - $this->server->httpRequest = new Sabre_HTTP_Request($headers); + $this->server->httpRequest = new Sabre\HTTP\Request($headers); $this->plugin->verifyContentLength('foo.txt'); } diff --git a/tests/lib/connector/sabre/directory.php b/tests/lib/connector/sabre/directory.php index b2bf0d4a6d2..8a1550ffa95 100644 --- a/tests/lib/connector/sabre/directory.php +++ b/tests/lib/connector/sabre/directory.php @@ -23,7 +23,7 @@ class Test_OC_Connector_Sabre_Directory extends PHPUnit_Framework_TestCase { } /** - * @expectedException Sabre_DAV_Exception_Forbidden + * @expectedException \Sabre\DAV\Exception\Forbidden */ public function testCreateSharedFileFails() { $dir = $this->getRootDir(); @@ -31,7 +31,7 @@ class Test_OC_Connector_Sabre_Directory extends PHPUnit_Framework_TestCase { } /** - * @expectedException Sabre_DAV_Exception_Forbidden + * @expectedException \Sabre\DAV\Exception\Forbidden */ public function testCreateSharedFolderFails() { $dir = $this->getRootDir(); @@ -39,7 +39,7 @@ class Test_OC_Connector_Sabre_Directory extends PHPUnit_Framework_TestCase { } /** - * @expectedException Sabre_DAV_Exception_Forbidden + * @expectedException \Sabre\DAV\Exception\Forbidden */ public function testDeleteSharedFolderFails() { $dir = $this->getRootDir(); diff --git a/tests/lib/connector/sabre/file.php b/tests/lib/connector/sabre/file.php index a9056460a5c..3dd5b328f46 100644 --- a/tests/lib/connector/sabre/file.php +++ b/tests/lib/connector/sabre/file.php @@ -9,7 +9,7 @@ class Test_OC_Connector_Sabre_File extends PHPUnit_Framework_TestCase { /** - * @expectedException Sabre_DAV_Exception + * @expectedException \Sabre\DAV\Exception */ public function testSimplePutFails() { // setup @@ -33,7 +33,7 @@ class Test_OC_Connector_Sabre_File extends PHPUnit_Framework_TestCase { } /** - * @expectedException Sabre_DAV_Exception + * @expectedException \Sabre\DAV\Exception */ public function testSimplePutFailsOnRename() { // setup @@ -62,7 +62,7 @@ class Test_OC_Connector_Sabre_File extends PHPUnit_Framework_TestCase { } /** - * @expectedException Sabre_DAV_Exception_BadRequest + * @expectedException \Sabre\DAV\Exception\BadRequest */ public function testSimplePutInvalidChars() { // setup @@ -86,7 +86,7 @@ class Test_OC_Connector_Sabre_File extends PHPUnit_Framework_TestCase { /** * Test setting name with setName() with invalid chars - * @expectedException Sabre_DAV_Exception_BadRequest + * @expectedException \Sabre\DAV\Exception\BadRequest */ public function testSetNameInvalidChars() { // setup diff --git a/tests/lib/connector/sabre/objecttree.php b/tests/lib/connector/sabre/objecttree.php index bc8ec98faee..0075b7832b8 100644 --- a/tests/lib/connector/sabre/objecttree.php +++ b/tests/lib/connector/sabre/objecttree.php @@ -12,7 +12,6 @@ namespace Test\OC\Connector\Sabre; use OC\Files\FileInfo; use OC_Connector_Sabre_Directory; use PHPUnit_Framework_TestCase; -use Sabre_DAV_Exception_Forbidden; class TestDoubleFileView extends \OC\Files\View{ @@ -43,7 +42,7 @@ class ObjectTree extends PHPUnit_Framework_TestCase { /** * @dataProvider moveFailedProvider - * @expectedException Sabre_DAV_Exception_Forbidden + * @expectedException \Sabre\DAV\Exception\Forbidden */ public function testMoveFailed($source, $dest, $updatables, $deletables) { $this->moveTest($source, $dest, $updatables, $deletables); @@ -59,7 +58,7 @@ class ObjectTree extends PHPUnit_Framework_TestCase { /** * @dataProvider moveFailedInvalidCharsProvider - * @expectedException Sabre_DAV_Exception_BadRequest + * @expectedException \Sabre\DAV\Exception\BadRequest */ public function testMoveFailedInvalidChars($source, $dest, $updatables, $deletables) { $this->moveTest($source, $dest, $updatables, $deletables); diff --git a/tests/lib/connector/sabre/quotaplugin.php b/tests/lib/connector/sabre/quotaplugin.php index 6781b970a4f..1024ae6af8f 100644 --- a/tests/lib/connector/sabre/quotaplugin.php +++ b/tests/lib/connector/sabre/quotaplugin.php @@ -9,7 +9,7 @@ class Test_OC_Connector_Sabre_QuotaPlugin extends PHPUnit_Framework_TestCase { /** - * @var Sabre_DAV_Server + * @var \Sabre\DAV\Server */ private $server; @@ -20,7 +20,7 @@ class Test_OC_Connector_Sabre_QuotaPlugin extends PHPUnit_Framework_TestCase { private function init($quota) { $view = $this->buildFileViewMock($quota); - $this->server = new Sabre_DAV_Server(); + $this->server = new \Sabre\DAV\Server(); $this->plugin = new OC_Connector_Sabre_QuotaPlugin($view); $this->plugin->initialize($this->server); } @@ -30,7 +30,7 @@ class Test_OC_Connector_Sabre_QuotaPlugin extends PHPUnit_Framework_TestCase { */ public function testLength($expected, $headers) { $this->init(0); - $this->server->httpRequest = new Sabre_HTTP_Request($headers); + $this->server->httpRequest = new \Sabre\HTTP\Request($headers); $length = $this->plugin->getLength(); $this->assertEquals($expected, $length); } @@ -41,19 +41,19 @@ class Test_OC_Connector_Sabre_QuotaPlugin extends PHPUnit_Framework_TestCase { public function testCheckQuota($quota, $headers) { $this->init($quota); - $this->server->httpRequest = new Sabre_HTTP_Request($headers); + $this->server->httpRequest = new Sabre\HTTP\Request($headers); $result = $this->plugin->checkQuota(''); $this->assertTrue($result); } /** - * @expectedException Sabre_DAV_Exception_InsufficientStorage + * @expectedException \Sabre\DAV\Exception\InsufficientStorage * @dataProvider quotaExceededProvider */ public function testCheckExceededQuota($quota, $headers) { $this->init($quota); - $this->server->httpRequest = new Sabre_HTTP_Request($headers); + $this->server->httpRequest = new Sabre\HTTP\Request($headers); $this->plugin->checkQuota(''); } diff --git a/tests/lib/files/cache/changepropagator.php b/tests/lib/files/cache/changepropagator.php new file mode 100644 index 00000000000..9beff27d50e --- /dev/null +++ b/tests/lib/files/cache/changepropagator.php @@ -0,0 +1,72 @@ +<?php +/** + * Copyright (c) 2014 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; +use OC\Files\Storage\Temporary; +use OC\Files\View; + +class ChangePropagator extends \PHPUnit_Framework_TestCase { + /** + * @var \OC\Files\Cache\ChangePropagator + */ + private $propagator; + + /** + * @var \OC\Files\View + */ + private $view; + + public function setUp() { + $storage = new Temporary(array()); + $root = '/' . uniqid(); + Filesystem::mount($storage, array(), $root); + $this->view = new View($root); + $this->propagator = new \OC\Files\Cache\ChangePropagator($this->view); + } + + public function testGetParentsSingle() { + $this->propagator->addChange('/foo/bar/asd'); + $this->assertEquals(array('/', '/foo', '/foo/bar'), $this->propagator->getAllParents()); + } + + public function testGetParentsMultiple() { + $this->propagator->addChange('/foo/bar/asd'); + $this->propagator->addChange('/foo/qwerty'); + $this->propagator->addChange('/foo/asd/bar'); + $this->assertEquals(array('/', '/foo', '/foo/bar', '/foo/asd'), $this->propagator->getAllParents()); + } + + public function testSinglePropagate() { + $this->view->mkdir('/foo'); + $this->view->mkdir('/foo/bar'); + $this->view->file_put_contents('/foo/bar/sad.txt', 'qwerty'); + + $oldInfo1 = $this->view->getFileInfo('/'); + $oldInfo2 = $this->view->getFileInfo('/foo'); + $oldInfo3 = $this->view->getFileInfo('/foo/bar'); + + $time = time() + 50; + + $this->propagator->addChange('/foo/bar/sad.txt'); + $this->propagator->propagateChanges($time); + + $newInfo1 = $this->view->getFileInfo('/'); + $newInfo2 = $this->view->getFileInfo('/foo'); + $newInfo3 = $this->view->getFileInfo('/foo/bar'); + + $this->assertEquals($newInfo1->getMTime(), $time); + $this->assertEquals($newInfo2->getMTime(), $time); + $this->assertEquals($newInfo3->getMTime(), $time); + + $this->assertNotEquals($oldInfo1->getEtag(), $newInfo1->getEtag()); + $this->assertNotEquals($oldInfo2->getEtag(), $newInfo2->getEtag()); + $this->assertNotEquals($oldInfo3->getEtag(), $newInfo3->getEtag()); + } +} diff --git a/tests/lib/files/cache/scanner.php b/tests/lib/files/cache/scanner.php index 1a42e656409..263e5b3445f 100644 --- a/tests/lib/files/cache/scanner.php +++ b/tests/lib/files/cache/scanner.php @@ -232,13 +232,5 @@ class Scanner extends \PHPUnit_Framework_TestCase { $newData0 = $this->cache->get('folder/bar.txt'); $this->assertInternalType('string', $newData0['etag']); $this->assertNotEmpty($newData0['etag']); - - $newData1 = $this->cache->get('folder'); - $this->assertInternalType('string', $newData1['etag']); - $this->assertNotSame($data1['etag'], $newData1['etag']); - - $newData2 = $this->cache->get(''); - $this->assertInternalType('string', $newData2['etag']); - $this->assertNotSame($data2['etag'], $newData2['etag']); } } diff --git a/tests/lib/files/utils/scanner.php b/tests/lib/files/utils/scanner.php index a021d215ae5..159a2a48677 100644 --- a/tests/lib/files/utils/scanner.php +++ b/tests/lib/files/utils/scanner.php @@ -8,6 +8,7 @@ namespace Test\Files\Utils; +use OC\Files\Filesystem; use OC\Files\Mount\Mount; use OC\Files\Storage\Temporary; @@ -27,12 +28,21 @@ class TestScanner extends \OC\Files\Utils\Scanner { protected function getMounts($dir) { return $this->mounts; } + + public function getPropagator() { + return $this->propagator; + } + + public function setPropagator($propagator) { + $this->propagator = $propagator; + } } class Scanner extends \PHPUnit_Framework_TestCase { public function testReuseExistingRoot() { $storage = new Temporary(array()); $mount = new Mount($storage, ''); + Filesystem::getMountManager()->addMount($mount); $cache = $storage->getCache(); $storage->mkdir('folder'); @@ -54,6 +64,7 @@ class Scanner extends \PHPUnit_Framework_TestCase { public function testReuseExistingFile() { $storage = new Temporary(array()); $mount = new Mount($storage, ''); + Filesystem::getMountManager()->addMount($mount); $cache = $storage->getCache(); $storage->mkdir('folder'); @@ -71,4 +82,57 @@ class Scanner extends \PHPUnit_Framework_TestCase { $new = $cache->get('folder/bar.txt'); $this->assertEquals($old, $new); } + + public function testChangePropagator() { + /** + * @var \OC\Files\Cache\ChangePropagator $propagator + */ + $propagator = $this->getMock('\OC\Files\Cache\ChangePropagator', array('propagateChanges'), array(), '', false); + + $storage = new Temporary(array()); + $mount = new Mount($storage, '/foo'); + Filesystem::getMountManager()->addMount($mount); + $cache = $storage->getCache(); + + $storage->mkdir('folder'); + $storage->file_put_contents('foo.txt', 'qwerty'); + $storage->file_put_contents('folder/bar.txt', 'qwerty'); + + $scanner = new TestScanner(''); + $originalPropagator = $scanner->getPropagator(); + $scanner->setPropagator($propagator); + $scanner->addMount($mount); + + $scanner->scan(''); + + $changes = $propagator->getChanges(); + $parents = $propagator->getAllParents(); + sort($changes); + sort($parents); + $this->assertEquals(array('/foo', '/foo/folder', '/foo/folder/bar.txt', '/foo/foo.txt'), $changes); + $this->assertEquals(array('/', '/foo', '/foo/folder'), $parents); + + $cache->put('foo.txt', array('mtime' => time() - 50)); + + $propagator = $this->getMock('\OC\Files\Cache\ChangePropagator', array('propagateChanges'), array(), '', false); + $scanner->setPropagator($propagator); + $storage->file_put_contents('foo.txt', 'asdasd'); + + $scanner->scan(''); + + $changes = $propagator->getChanges(); + $parents = $propagator->getAllParents(); + $this->assertEquals(array('/foo/foo.txt'), $changes); + $this->assertEquals(array('/', '/foo'), $parents); + + $scanner->setPropagator($originalPropagator); + + $oldInfo = $cache->get(''); + $cache->put('foo.txt', array('mtime' => time() - 70)); + $storage->file_put_contents('foo.txt', 'asdasd'); + + $scanner->scan(''); + $newInfo = $cache->get(''); + $this->assertNotEquals($oldInfo['etag'], $newInfo['etag']); + } } diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php index f86aa633e74..b2e0b59d8e6 100644 --- a/tests/lib/files/view.php +++ b/tests/lib/files/view.php @@ -50,14 +50,18 @@ class View extends \PHPUnit_Framework_TestCase { $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'); + $root = '/' . uniqid(); + \OC\Files\Filesystem::mount($storage1, array(), $root . '/'); + \OC\Files\Filesystem::mount($storage2, array(), $root . '/substorage'); + \OC\Files\Filesystem::mount($storage3, array(), $root . '/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(''); + $storageInfo = $storage3->getCache()->get(''); + $this->assertEquals($storageSize, $storageInfo['size']); + + $rootView = new \OC\Files\View($root); $cachedData = $rootView->getFileInfo('/foo.txt'); $this->assertEquals($textSize, $cachedData['size']); @@ -108,7 +112,7 @@ class View extends \PHPUnit_Framework_TestCase { $this->assertEquals('foo.png', $folderData[1]['name']); $this->assertEquals('foo.txt', $folderData[2]['name']); - $folderView = new \OC\Files\View('/folder'); + $folderView = new \OC\Files\View($root . '/folder'); $this->assertEquals($rootView->getFileInfo('/folder'), $folderView->getFileInfo('/')); $cachedData = $rootView->getFileInfo('/foo.txt'); @@ -578,9 +582,9 @@ class View extends \PHPUnit_Framework_TestCase { $longPath = ''; // 4000 is the maximum path length in file_cache.path $folderName = 'abcdefghijklmnopqrstuvwxyz012345678901234567890123456789'; - $depth = (4000/57); - foreach (range(0, $depth-1) as $i) { - $longPath .= '/'.$folderName; + $depth = (4000 / 57); + foreach (range(0, $depth - 1) as $i) { + $longPath .= '/' . $folderName; $result = $rootView->mkdir($longPath); $this->assertTrue($result, "mkdir failed on $i - path length: " . strlen($longPath)); @@ -596,7 +600,7 @@ class View extends \PHPUnit_Framework_TestCase { $scanner->scan(''); $longPath = $folderName; - foreach (range(0, $depth-1) as $i) { + foreach (range(0, $depth - 1) as $i) { $cachedFolder = $cache->get($longPath); $this->assertTrue(is_array($cachedFolder), "No cache entry for folder at $i"); $this->assertEquals($folderName, $cachedFolder['name'], "Wrong cache entry for folder at $i"); @@ -650,14 +654,14 @@ class View extends \PHPUnit_Framework_TestCase { * @dataProvider tooLongPathDataProvider * @expectedException \OCP\Files\InvalidPathException */ - public function testTooLongPath($operation, $param0 = NULL) { + public function testTooLongPath($operation, $param0 = null) { $longPath = ''; // 4000 is the maximum path length in file_cache.path $folderName = 'abcdefghijklmnopqrstuvwxyz012345678901234567890123456789'; - $depth = (4000/57); - foreach (range(0, $depth+1) as $i) { - $longPath .= '/'.$folderName; + $depth = (4000 / 57); + foreach (range(0, $depth + 1) as $i) { + $longPath .= '/' . $folderName; } $storage = new \OC\Files\Storage\Temporary(array()); |