diff options
author | Robin Appelman <robin@icewind.nl> | 2016-09-18 18:36:53 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2016-10-12 16:12:28 +0200 |
commit | 0d842e0550a15b7b6c501dae2ec24a61b72ef8c9 (patch) | |
tree | 06c880a305b73d603675b724ae73c944ad484225 /tests/lib/Files/Node/FileTest.php | |
parent | b2d68c00091f8bcba104cabfe0f7e2c78cc7a8d0 (diff) | |
download | nextcloud-server-0d842e0550a15b7b6c501dae2ec24a61b72ef8c9.tar.gz nextcloud-server-0d842e0550a15b7b6c501dae2ec24a61b72ef8c9.zip |
optimize Folder::getById to use less queries
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'tests/lib/Files/Node/FileTest.php')
-rw-r--r-- | tests/lib/Files/Node/FileTest.php | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/tests/lib/Files/Node/FileTest.php b/tests/lib/Files/Node/FileTest.php index 1b665bd4c72..b7a2fa2a1a3 100644 --- a/tests/lib/Files/Node/FileTest.php +++ b/tests/lib/Files/Node/FileTest.php @@ -21,6 +21,9 @@ class FileTest extends \Test\TestCase { /** @var \OC\Files\View|\PHPUnit_Framework_MockObject_MockObject */ private $view; + /** @var \OCP\Files\Config\IUserMountCache|\PHPUnit_Framework_MockObject_MockObject */ + private $userMountCache; + protected function setUp() { parent::setUp(); $config = $this->getMockBuilder('\OCP\IConfig') @@ -34,6 +37,9 @@ class FileTest extends \Test\TestCase { $this->view = $this->getMockBuilder('\OC\Files\View') ->disableOriginalConstructor() ->getMock(); + $this->userMountCache = $this->getMockBuilder('\OCP\Files\Config\IUserMountCache') + ->disableOriginalConstructor() + ->getMock(); } protected function getMockStorage() { @@ -52,7 +58,7 @@ class FileTest extends \Test\TestCase { public function testDelete() { /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */ $root = $this->getMockBuilder('\OC\Files\Node\Root') - ->setConstructorArgs([$this->manager, $this->view, $this->user]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache]) ->getMock(); $root->expects($this->exactly(2)) @@ -102,7 +108,7 @@ class FileTest extends \Test\TestCase { $hooksRun++; }; - $root = new \OC\Files\Node\Root($this->manager, $this->view, $this->user); + $root = new \OC\Files\Node\Root($this->manager, $this->view, $this->user, $this->userMountCache); $root->listen('\OC\Files', 'preDelete', $preListener); $root->listen('\OC\Files', 'postDelete', $postListener); @@ -132,7 +138,7 @@ class FileTest extends \Test\TestCase { public function testDeleteNotPermitted() { /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */ $root = $this->getMockBuilder('\OC\Files\Node\Root') - ->setConstructorArgs([$this->manager, $this->view, $this->user]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache]) ->getMock(); $root->expects($this->any()) @@ -151,7 +157,7 @@ class FileTest extends \Test\TestCase { public function testGetContent() { /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */ $root = $this->getMockBuilder('\OC\Files\Node\Root') - ->setConstructorArgs([$this->manager, $this->view, $this->user]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache]) ->getMock(); $hook = function ($file) { @@ -181,7 +187,7 @@ class FileTest extends \Test\TestCase { public function testGetContentNotPermitted() { /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */ $root = $this->getMockBuilder('\OC\Files\Node\Root') - ->setConstructorArgs([$this->manager, $this->view, $this->user]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache]) ->getMock(); $root->expects($this->any()) @@ -200,7 +206,7 @@ class FileTest extends \Test\TestCase { public function testPutContent() { /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */ $root = $this->getMockBuilder('\OC\Files\Node\Root') - ->setConstructorArgs([$this->manager, $this->view, $this->user]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache]) ->getMock(); $root->expects($this->any()) @@ -227,7 +233,7 @@ class FileTest extends \Test\TestCase { public function testPutContentNotPermitted() { /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */ $root = $this->getMockBuilder('\OC\Files\Node\Root') - ->setConstructorArgs([$this->manager, $this->view, $this->user]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache]) ->getMock(); $this->view->expects($this->once()) @@ -242,7 +248,7 @@ class FileTest extends \Test\TestCase { public function testGetMimeType() { /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */ $root = $this->getMockBuilder('\OC\Files\Node\Root') - ->setConstructorArgs([$this->manager, $this->view, $this->user]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache]) ->getMock(); $this->view->expects($this->once()) @@ -259,7 +265,7 @@ class FileTest extends \Test\TestCase { fwrite($stream, 'bar'); rewind($stream); - $root = new \OC\Files\Node\Root($this->manager, $this->view, $this->user); + $root = new \OC\Files\Node\Root($this->manager, $this->view, $this->user, $this->userMountCache); $hook = function ($file) { throw new \Exception('Hooks are not supposed to be called'); @@ -287,7 +293,7 @@ class FileTest extends \Test\TestCase { public function testFOpenWrite() { $stream = fopen('php://memory', 'w+'); - $root = new \OC\Files\Node\Root($this->manager, new $this->view, $this->user); + $root = new \OC\Files\Node\Root($this->manager, new $this->view, $this->user, $this->userMountCache); $hooksCalled = 0; $hook = function ($file) use (&$hooksCalled) { @@ -320,7 +326,7 @@ class FileTest extends \Test\TestCase { * @expectedException \OCP\Files\NotPermittedException */ public function testFOpenReadNotPermitted() { - $root = new \OC\Files\Node\Root($this->manager, $this->view, $this->user); + $root = new \OC\Files\Node\Root($this->manager, $this->view, $this->user, $this->userMountCache); $hook = function ($file) { throw new \Exception('Hooks are not supposed to be called'); @@ -339,7 +345,7 @@ class FileTest extends \Test\TestCase { * @expectedException \OCP\Files\NotPermittedException */ public function testFOpenReadWriteNoReadPermissions() { - $root = new \OC\Files\Node\Root($this->manager, $this->view, $this->user); + $root = new \OC\Files\Node\Root($this->manager, $this->view, $this->user, $this->userMountCache); $hook = function () { throw new \Exception('Hooks are not supposed to be called'); @@ -358,7 +364,7 @@ class FileTest extends \Test\TestCase { * @expectedException \OCP\Files\NotPermittedException */ public function testFOpenReadWriteNoWritePermissions() { - $root = new \OC\Files\Node\Root($this->manager, new $this->view, $this->user); + $root = new \OC\Files\Node\Root($this->manager, new $this->view, $this->user, $this->userMountCache); $hook = function () { throw new \Exception('Hooks are not supposed to be called'); @@ -376,7 +382,7 @@ class FileTest extends \Test\TestCase { public function testCopySameStorage() { /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */ $root = $this->getMockBuilder('\OC\Files\Node\Root') - ->setConstructorArgs([$this->manager, $this->view, $this->user]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache]) ->getMock(); $this->view->expects($this->any()) @@ -409,7 +415,7 @@ class FileTest extends \Test\TestCase { public function testCopyNotPermitted() { /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */ $root = $this->getMockBuilder('\OC\Files\Node\Root') - ->setConstructorArgs([$this->manager, $this->view, $this->user]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache]) ->getMock(); /** @@ -447,7 +453,7 @@ class FileTest extends \Test\TestCase { public function testCopyNoParent() { /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */ $root = $this->getMockBuilder('\OC\Files\Node\Root') - ->setConstructorArgs([$this->manager, $this->view, $this->user]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache]) ->getMock(); $this->view->expects($this->never()) @@ -469,7 +475,7 @@ class FileTest extends \Test\TestCase { public function testCopyParentIsFile() { /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */ $root = $this->getMockBuilder('\OC\Files\Node\Root') - ->setConstructorArgs([$this->manager, $this->view, $this->user]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache]) ->getMock(); $this->view->expects($this->never()) @@ -490,7 +496,7 @@ class FileTest extends \Test\TestCase { public function testMoveSameStorage() { /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */ $root = $this->getMockBuilder('\OC\Files\Node\Root') - ->setConstructorArgs([$this->manager, $this->view, $this->user]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache]) ->getMock(); $this->view->expects($this->any()) @@ -520,7 +526,7 @@ class FileTest extends \Test\TestCase { public function testMoveNotPermitted() { /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */ $root = $this->getMockBuilder('\OC\Files\Node\Root') - ->setConstructorArgs([$this->manager, $this->view, $this->user]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache]) ->getMock(); $this->view->expects($this->any()) @@ -547,7 +553,7 @@ class FileTest extends \Test\TestCase { public function testMoveNoParent() { /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */ $root = $this->getMockBuilder('\OC\Files\Node\Root') - ->setConstructorArgs([$this->manager, $this->view, $this->user]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache]) ->getMock(); /** @@ -577,7 +583,7 @@ class FileTest extends \Test\TestCase { public function testMoveParentIsFile() { /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject $root */ $root = $this->getMockBuilder('\OC\Files\Node\Root') - ->setConstructorArgs([$this->manager, $this->view, $this->user]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache]) ->getMock(); $this->view->expects($this->never()) |