]> source.dussan.org Git - nextcloud-server.git/commitdiff
test case for hooks send from a non-default view
authorRobin Appelman <icewind@owncloud.com>
Thu, 29 Aug 2013 13:25:38 +0000 (15:25 +0200)
committerRobin Appelman <icewind@owncloud.com>
Thu, 29 Aug 2013 13:25:38 +0000 (15:25 +0200)
tests/lib/files/view.php

index 3bac9e770aa1b73fa81bd0b162a3c83618bdc8ce..0de436f570a5ddbc35b0ecf37293a50ef98fd408 100644 (file)
@@ -25,7 +25,7 @@ class View extends \PHPUnit_Framework_TestCase {
 
                //login
                \OC_User::createUser('test', 'test');
-               $this->user=\OC_User::getUser();
+               $this->user = \OC_User::getUser();
                \OC_User::setUserId('test');
 
                \OC\Files\Filesystem::clearMounts();
@@ -325,6 +325,35 @@ class View extends \PHPUnit_Framework_TestCase {
                $this->assertEquals($cachedData['storage_mtime'], $cachedData['mtime']);
        }
 
+       /**
+        * @medium
+        */
+       function testViewHooks() {
+               $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');
+
+               $rootView = new \OC\Files\View('');
+               $subView = new \OC\Files\View($defaultRoot . '/substorage');
+               $this->hookPath = null;
+
+               $rootView->file_put_contents('/foo.txt', 'asd');
+               $this->assertNull($this->hookPath);
+
+               $subView->file_put_contents('/foo.txt', 'asd');
+               $this->assertNotNull($this->hookPath);
+               $this->assertEquals('/substorage/foo.txt', $this->hookPath);
+       }
+
+       private $hookPath;
+
+       function dummyHook($params) {
+               $this->hookPath = $params['path'];
+       }
+
        /**
         * @param bool $scan
         * @return \OC\Files\Storage\Storage