diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2013-10-15 00:09:00 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2013-10-15 00:09:00 +0200 |
commit | 86f6f0ca92cb1ea3be45ca45e9f72ec556003f58 (patch) | |
tree | aa29ed92de93ae71f051ff5a541d1b999c7026e2 /tests | |
parent | b0980b62ac97bdc218edcafecfb5641911f87f2f (diff) | |
parent | 2bb452726997b8b4f4ea9b92587fd7d880d35c29 (diff) | |
download | nextcloud-server-86f6f0ca92cb1ea3be45ca45e9f72ec556003f58.tar.gz nextcloud-server-86f6f0ca92cb1ea3be45ca45e9f72ec556003f58.zip |
Merge branch 'master' into coverage-on-windows-master
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/files/view.php | 77 | ||||
-rw-r--r-- | tests/lib/helper.php | 34 |
2 files changed, 111 insertions, 0 deletions
diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php index 3043f132b73..0cc86d6651a 100644 --- a/tests/lib/files/view.php +++ b/tests/lib/files/view.php @@ -391,4 +391,81 @@ class View extends \PHPUnit_Framework_TestCase { $this->storages[] = $storage; return $storage; } + + private $createHookPath; + + function dummyCreateHook($params) { + $this->createHookPath = $params['path']; + } + + /** + * @medium + */ + function testViewHooksIfRootStartsTheSame() { + $storage1 = $this->getTestStorage(); + $storage2 = $this->getTestStorage(); + $defaultRoot = \OC\Files\Filesystem::getRoot(); + \OC\Files\Filesystem::mount($storage1, array(), '/'); + \OC\Files\Filesystem::mount($storage2, array(), $defaultRoot . '_substorage'); + \OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook'); + + $subView = new \OC\Files\View($defaultRoot . '_substorage'); + $this->hookPath = null; + + $subView->file_put_contents('/foo.txt', 'asd'); + $this->assertNull($this->hookPath); + } + + public function testEditNoCreateHook() { + $storage1 = $this->getTestStorage(); + $storage2 = $this->getTestStorage(); + $defaultRoot = \OC\Files\Filesystem::getRoot(); + \OC\Files\Filesystem::mount($storage1, array(), '/'); + \OC\Files\Filesystem::mount($storage2, array(), $defaultRoot); + \OC_Hook::connect('OC_Filesystem', 'post_create', $this, 'dummyCreateHook'); + + $view = new \OC\Files\View($defaultRoot); + $this->hookPath = null; + + $view->file_put_contents('/asd.txt', 'foo'); + $this->assertEquals('/asd.txt', $this->createHookPath); + $this->createHookPath = null; + + $view->file_put_contents('/asd.txt', 'foo'); + $this->assertNull($this->createHookPath); + } + + /** + * @dataProvider resolvePathTestProvider + */ + public function testResolvePath($expected, $pathToTest) { + $storage1 = $this->getTestStorage(); + \OC\Files\Filesystem::mount($storage1, array(), '/'); + + $view = new \OC\Files\View(''); + + $result = $view->resolvePath($pathToTest); + $this->assertEquals($expected, $result[1]); + + $exists = $view->file_exists($pathToTest); + $this->assertTrue($exists); + + $exists = $view->file_exists($result[1]); + $this->assertTrue($exists); + } + + function resolvePathTestProvider() { + return array( + array('foo.txt', 'foo.txt'), + array('foo.txt', '/foo.txt'), + array('folder', 'folder'), + array('folder', '/folder'), + array('folder', 'folder/'), + array('folder', '/folder/'), + array('folder/bar.txt', 'folder/bar.txt'), + array('folder/bar.txt', '/folder/bar.txt'), + array('', ''), + array('', '/'), + ); + } } diff --git a/tests/lib/helper.php b/tests/lib/helper.php index b4d896e5196..babafab52c0 100644 --- a/tests/lib/helper.php +++ b/tests/lib/helper.php @@ -208,4 +208,38 @@ class Test_Helper extends PHPUnit_Framework_TestCase { ->will($this->returnValue(true)); // filename(1) (2) (3).ext exists $this->assertEquals('dir/filename(1) (2) (4).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename(1) (2) (3).ext', $viewMock)); } + + /** + * @dataProvider streamCopyDataProvider + */ + public function testStreamCopy($expectedCount, $expectedResult, $source, $target) { + + if (is_string($source)) { + $source = fopen($source, 'r'); + } + if (is_string($target)) { + $target = fopen($target, 'w'); + } + + list($count, $result) = \OC_Helper::streamCopy($source, $target); + + if (is_resource($source)) { + fclose($source); + } + if (is_resource($target)) { + fclose($target); + } + + $this->assertSame($expectedCount, $count); + $this->assertSame($expectedResult, $result); + } + + + function streamCopyDataProvider() { + return array( + array(0, false, false, false), + array(0, false, \OC::$SERVERROOT . '/tests/data/lorem.txt', false), + array(446, true, \OC::$SERVERROOT . '/tests/data/lorem.txt', \OC::$SERVERROOT . '/tests/data/lorem-copy.txt'), + ); + } } |