diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2016-11-02 23:16:51 +0100 |
---|---|---|
committer | Lukas Reschke <lukas@statuscode.ch> | 2016-11-02 23:16:51 +0100 |
commit | 68cebef64ca38ea93bc1006d667726f42d7f9805 (patch) | |
tree | e0f060c68fb0d85d303eabb263cd8666407bb072 /tests | |
parent | 8653d1486243079426a855584111db519af6e544 (diff) | |
download | nextcloud-server-68cebef64ca38ea93bc1006d667726f42d7f9805.tar.gz nextcloud-server-68cebef64ca38ea93bc1006d667726f42d7f9805.zip |
DI for root.php
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Files/Node/FileTest.php | 100 | ||||
-rw-r--r-- | tests/lib/Files/Node/FolderTest.php | 125 | ||||
-rw-r--r-- | tests/lib/Files/Node/HookConnectorTest.php | 6 | ||||
-rw-r--r-- | tests/lib/Files/Node/IntegrationTest.php | 11 | ||||
-rw-r--r-- | tests/lib/Files/Node/NodeTest.php | 24 | ||||
-rw-r--r-- | tests/lib/Files/Node/RootTest.php | 172 |
6 files changed, 307 insertions, 131 deletions
diff --git a/tests/lib/Files/Node/FileTest.php b/tests/lib/Files/Node/FileTest.php index b7a2fa2a1a3..823e3b50249 100644 --- a/tests/lib/Files/Node/FileTest.php +++ b/tests/lib/Files/Node/FileTest.php @@ -10,19 +10,22 @@ namespace Test\Files\Node; use OC\Files\FileInfo; use OCP\Files\NotFoundException; +use OCP\ILogger; +use OCP\IUserManager; class FileTest extends \Test\TestCase { /** @var \OC\User\User */ private $user; - /** @var \OC\Files\Mount\Manager */ private $manager; - /** @var \OC\Files\View|\PHPUnit_Framework_MockObject_MockObject */ private $view; - /** @var \OCP\Files\Config\IUserMountCache|\PHPUnit_Framework_MockObject_MockObject */ private $userMountCache; + /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */ + private $logger; + /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */ + private $userManager; protected function setUp() { parent::setUp(); @@ -30,7 +33,6 @@ class FileTest extends \Test\TestCase { ->disableOriginalConstructor() ->getMock(); $this->user = new \OC\User\User('', new \Test\Util\User\Dummy, null, $config); - $this->manager = $this->getMockBuilder('\OC\Files\Mount\Manager') ->disableOriginalConstructor() ->getMock(); @@ -40,6 +42,8 @@ class FileTest extends \Test\TestCase { $this->userMountCache = $this->getMockBuilder('\OCP\Files\Config\IUserMountCache') ->disableOriginalConstructor() ->getMock(); + $this->logger = $this->createMock(ILogger::class); + $this->userManager = $this->createMock(IUserManager::class); } protected function getMockStorage() { @@ -58,7 +62,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, $this->userMountCache]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); $root->expects($this->exactly(2)) @@ -108,7 +112,14 @@ class FileTest extends \Test\TestCase { $hooksRun++; }; - $root = new \OC\Files\Node\Root($this->manager, $this->view, $this->user, $this->userMountCache); + $root = new \OC\Files\Node\Root( + $this->manager, + $this->view, + $this->user, + $this->userMountCache, + $this->logger, + $this->userManager + ); $root->listen('\OC\Files', 'preDelete', $preListener); $root->listen('\OC\Files', 'postDelete', $postListener); @@ -138,7 +149,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, $this->userMountCache]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); $root->expects($this->any()) @@ -157,7 +168,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, $this->userMountCache]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); $hook = function ($file) { @@ -187,7 +198,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, $this->userMountCache]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); $root->expects($this->any()) @@ -206,7 +217,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, $this->userMountCache]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); $root->expects($this->any()) @@ -233,7 +244,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, $this->userMountCache]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); $this->view->expects($this->once()) @@ -248,7 +259,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, $this->userMountCache]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); $this->view->expects($this->once()) @@ -265,7 +276,14 @@ class FileTest extends \Test\TestCase { fwrite($stream, 'bar'); rewind($stream); - $root = new \OC\Files\Node\Root($this->manager, $this->view, $this->user, $this->userMountCache); + $root = new \OC\Files\Node\Root( + $this->manager, + $this->view, + $this->user, + $this->userMountCache, + $this->logger, + $this->userManager + ); $hook = function ($file) { throw new \Exception('Hooks are not supposed to be called'); @@ -293,8 +311,14 @@ 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, $this->userMountCache); - + $root = new \OC\Files\Node\Root( + $this->manager, + new $this->view, + $this->user, + $this->userMountCache, + $this->logger, + $this->userManager + ); $hooksCalled = 0; $hook = function ($file) use (&$hooksCalled) { $hooksCalled++; @@ -326,8 +350,14 @@ class FileTest extends \Test\TestCase { * @expectedException \OCP\Files\NotPermittedException */ public function testFOpenReadNotPermitted() { - $root = new \OC\Files\Node\Root($this->manager, $this->view, $this->user, $this->userMountCache); - + $root = new \OC\Files\Node\Root( + $this->manager, + $this->view, + $this->user, + $this->userMountCache, + $this->logger, + $this->userManager + ); $hook = function ($file) { throw new \Exception('Hooks are not supposed to be called'); }; @@ -345,8 +375,14 @@ class FileTest extends \Test\TestCase { * @expectedException \OCP\Files\NotPermittedException */ public function testFOpenReadWriteNoReadPermissions() { - $root = new \OC\Files\Node\Root($this->manager, $this->view, $this->user, $this->userMountCache); - + $root = new \OC\Files\Node\Root( + $this->manager, + $this->view, + $this->user, + $this->userMountCache, + $this->logger, + $this->userManager + ); $hook = function () { throw new \Exception('Hooks are not supposed to be called'); }; @@ -364,8 +400,14 @@ 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, $this->userMountCache); - + $root = new \OC\Files\Node\Root( + $this->manager, + new $this->view, + $this->user, + $this->userMountCache, + $this->logger, + $this->userManager + ); $hook = function () { throw new \Exception('Hooks are not supposed to be called'); }; @@ -382,7 +424,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, $this->userMountCache]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); $this->view->expects($this->any()) @@ -415,7 +457,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, $this->userMountCache]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); /** @@ -453,7 +495,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, $this->userMountCache]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); $this->view->expects($this->never()) @@ -475,7 +517,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, $this->userMountCache]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); $this->view->expects($this->never()) @@ -496,7 +538,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, $this->userMountCache]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); $this->view->expects($this->any()) @@ -526,7 +568,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, $this->userMountCache]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); $this->view->expects($this->any()) @@ -553,7 +595,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, $this->userMountCache]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); /** @@ -583,7 +625,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, $this->userMountCache]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); $this->view->expects($this->never()) diff --git a/tests/lib/Files/Node/FolderTest.php b/tests/lib/Files/Node/FolderTest.php index e592013eb6a..dcfe6a1768c 100644 --- a/tests/lib/Files/Node/FolderTest.php +++ b/tests/lib/Files/Node/FolderTest.php @@ -18,11 +18,13 @@ use OC\Files\Node\Node; use OC\Files\Node\Root; use OC\Files\Storage\Temporary; use OC\Files\Storage\Wrapper\Jail; +use OC\User\User; use OCP\Files\Mount\IMountPoint; use OCP\Files\NotFoundException; -use OCP\Files\NotPermittedException; use OC\Files\View; use OCP\Files\Storage; +use OCP\ILogger; +use OCP\IUserManager; /** * Class FolderTest @@ -32,10 +34,14 @@ use OCP\Files\Storage; * @package Test\Files\Node */ class FolderTest extends \Test\TestCase { + /** @var User */ private $user; - /** @var \OCP\Files\Config\IUserMountCache|\PHPUnit_Framework_MockObject_MockObject */ private $userMountCache; + /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */ + private $logger; + /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */ + private $userManager; protected function setUp() { parent::setUp(); @@ -43,6 +49,8 @@ class FolderTest extends \Test\TestCase { $this->userMountCache = $this->getMockBuilder('\OCP\Files\Config\IUserMountCache') ->disableOriginalConstructor() ->getMock(); + $this->logger = $this->createMock(ILogger::class); + $this->userManager = $this->createMock(IUserManager::class); } protected function getMockStorage() { @@ -64,7 +72,7 @@ class FolderTest extends \Test\TestCase { */ $view = $this->createMock(View::class); $root = $this->getMockBuilder(Root::class) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); $root->expects($this->any()) ->method('getUser') @@ -118,7 +126,14 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = new \OC\Files\Node\Root($manager, $view, $this->user, $this->userMountCache); + $root = new \OC\Files\Node\Root( + $manager, + $view, + $this->user, + $this->userMountCache, + $this->logger, + $this->userManager + ); $root->listen('\OC\Files', 'preDelete', $preListener); $root->listen('\OC\Files', 'postDelete', $postListener); @@ -150,7 +165,9 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -171,7 +188,7 @@ class FolderTest extends \Test\TestCase { */ $view = $this->createMock(View::class); $root = $this->getMockBuilder(Root::class) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache]) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); $root->expects($this->any()) ->method('getUser') @@ -202,7 +219,9 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -221,7 +240,9 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -243,7 +264,9 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -263,7 +286,9 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -293,7 +318,9 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -313,7 +340,9 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -343,7 +372,9 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -363,7 +394,9 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -383,7 +416,9 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -431,8 +466,10 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setMethods(['getUser', 'getMountsIn', 'getMount']) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setMethods(['getUser', 'getMountsIn', 'getMount']) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -480,7 +517,9 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -528,7 +567,9 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -576,7 +617,9 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -656,8 +699,10 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setMethods(['getMountsIn', 'getMount']) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setMethods(['getMountsIn', 'getMount']) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $storage = $this->createMock(\OC\Files\Storage\Storage::class); $mount = new MountPoint($storage, '/bar'); $cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([''])->getMock(); @@ -707,8 +752,10 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setMethods(['getMountsIn', 'getMount']) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setMethods(['getMountsIn', 'getMount']) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $storage = $this->createMock(\OC\Files\Storage\Storage::class); $mount = new MountPoint($storage, '/bar'); $cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([''])->getMock(); @@ -757,8 +804,10 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setMethods(['getMountsIn', 'getMount']) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setMethods(['getMountsIn', 'getMount']) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $storage = $this->createMock(\OC\Files\Storage\Storage::class); $mount1 = new MountPoint($storage, '/bar'); $mount2 = new MountPoint($storage, '/bar/foo/asd'); @@ -837,8 +886,10 @@ class FolderTest extends \Test\TestCase { * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->createMock(View::class); - $root = $this->getMockBuilder(Root::class)->setMethods(['getUser', 'getMountsIn', 'getMount']) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setMethods(['getUser', 'getMountsIn', 'getMount']) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); $view->expects($this->any()) ->method('file_exists') @@ -863,8 +914,10 @@ class FolderTest extends \Test\TestCase { */ $view = $this->createMock(View::class); /** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\Node\Root $root */ - $root = $this->getMockBuilder(Root::class)->setMethods(['getUser', 'getMountsIn', 'getMount']) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setMethods(['getUser', 'getMountsIn', 'getMount']) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); /** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\FileInfo $folderInfo */ $folderInfo = $this->getMockBuilder('\OC\Files\FileInfo') ->disableOriginalConstructor()->getMock(); @@ -922,8 +975,10 @@ class FolderTest extends \Test\TestCase { */ $view = $this->createMock(View::class); /** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\Node\Root $root */ - $root = $this->getMockBuilder(Root::class)->setMethods(['getUser', 'getMountsIn', 'getMount']) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setMethods(['getUser', 'getMountsIn', 'getMount']) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); /** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\FileInfo $folderInfo */ $folderInfo = $this->getMockBuilder('\OC\Files\FileInfo') ->disableOriginalConstructor()->getMock(); @@ -979,8 +1034,10 @@ class FolderTest extends \Test\TestCase { */ $view = $this->createMock(View::class); /** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\Node\Root $root */ - $root = $this->getMockBuilder(Root::class)->setMethods(['getUser', 'getMountsIn', 'getMount']) - ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache])->getMock(); + $root = $this->getMockBuilder(Root::class) + ->setMethods(['getUser', 'getMountsIn', 'getMount']) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->getMock(); /** @var \PHPUnit_Framework_MockObject_MockObject|\OC\Files\FileInfo $folderInfo */ $folderInfo = $this->getMockBuilder('\OC\Files\FileInfo') ->disableOriginalConstructor()->getMock(); diff --git a/tests/lib/Files/Node/HookConnectorTest.php b/tests/lib/Files/Node/HookConnectorTest.php index 013fcabf222..765bb647a1a 100644 --- a/tests/lib/Files/Node/HookConnectorTest.php +++ b/tests/lib/Files/Node/HookConnectorTest.php @@ -13,6 +13,8 @@ use OC\Files\Node\Root; use OC\Files\Storage\Temporary; use OC\Files\View; use OCP\Files\Node; +use OCP\ILogger; +use OCP\IUserManager; use Test\TestCase; use Test\Traits\MountProviderTrait; use Test\Traits\UserTrait; @@ -54,7 +56,9 @@ class HookConnectorTest extends TestCase { Filesystem::getMountManager(), $this->view, \OC::$server->getUserManager()->get($this->userId), - \OC::$server->getUserMountCache() + \OC::$server->getUserMountCache(), + $this->createMock(ILogger::class), + $this->createMock(IUserManager::class) ); } diff --git a/tests/lib/Files/Node/IntegrationTest.php b/tests/lib/Files/Node/IntegrationTest.php index da753f833c2..b5cd832d1dd 100644 --- a/tests/lib/Files/Node/IntegrationTest.php +++ b/tests/lib/Files/Node/IntegrationTest.php @@ -12,6 +12,8 @@ use OC\Files\Node\Root; use OC\Files\Storage\Temporary; use OC\Files\View; use OC\User\User; +use OCP\ILogger; +use OCP\IUserManager; /** * Class IntegrationTest @@ -47,7 +49,14 @@ class IntegrationTest extends \Test\TestCase { $this->loginAsUser($user->getUID()); $this->view = new View(); - $this->root = new Root($manager, $this->view, $user, \OC::$server->getUserMountCache()); + $this->root = new Root( + $manager, + $this->view, + $user, + \OC::$server->getUserMountCache(), + $this->createMock(ILogger::class), + $this->createMock(IUserManager::class) + ); $storage = new Temporary(array()); $subStorage = new Temporary(array()); $this->storages[] = $storage; diff --git a/tests/lib/Files/Node/NodeTest.php b/tests/lib/Files/Node/NodeTest.php index b7e2f336a60..1a3a0472e97 100644 --- a/tests/lib/Files/Node/NodeTest.php +++ b/tests/lib/Files/Node/NodeTest.php @@ -9,21 +9,24 @@ namespace Test\Files\Node; use OC\Files\FileInfo; +use OCP\ILogger; +use OCP\IUserManager; class NodeTest extends \Test\TestCase { /** @var \OC\User\User */ private $user; - /** @var \OC\Files\Mount\Manager */ private $manager; - /** @var \OC\Files\View|\PHPUnit_Framework_MockObject_MockObject */ private $view; - /** @var \OC\Files\Node\Root|\PHPUnit_Framework_MockObject_MockObject */ private $root; /** @var \OCP\Files\Config\IUserMountCache|\PHPUnit_Framework_MockObject_MockObject */ private $userMountCache; + /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */ + private $logger; + /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */ + private $userManager; protected function setUp() { parent::setUp(); @@ -34,9 +37,7 @@ class NodeTest extends \Test\TestCase { $urlGenerator = $this->getMockBuilder('\OCP\IURLGenerator') ->disableOriginalConstructor() ->getMock(); - $this->user = new \OC\User\User('', new \Test\Util\User\Dummy, null, $config, $urlGenerator); - $this->manager = $this->getMockBuilder('\OC\Files\Mount\Manager') ->disableOriginalConstructor() ->getMock(); @@ -46,8 +47,10 @@ class NodeTest extends \Test\TestCase { $this->userMountCache = $this->getMockBuilder('\OCP\Files\Config\IUserMountCache') ->disableOriginalConstructor() ->getMock(); + $this->logger = $this->createMock(ILogger::class); + $this->userManager = $this->createMock(IUserManager::class); $this->root = $this->getMockBuilder('\OC\Files\Node\Root') - ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache]) + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) ->getMock(); } @@ -273,7 +276,14 @@ class NodeTest extends \Test\TestCase { $hooksRun++; }; - $root = new \OC\Files\Node\Root($this->manager, $this->view, $this->user, $this->userMountCache); + $root = new \OC\Files\Node\Root( + $this->manager, + $this->view, + $this->user, + $this->userMountCache, + $this->logger, + $this->userManager + ); $root->listen('\OC\Files', 'preTouch', $preListener); $root->listen('\OC\Files', 'postTouch', $postListener); diff --git a/tests/lib/Files/Node/RootTest.php b/tests/lib/Files/Node/RootTest.php index 534dd330328..fbc33cafcd8 100644 --- a/tests/lib/Files/Node/RootTest.php +++ b/tests/lib/Files/Node/RootTest.php @@ -8,18 +8,31 @@ namespace Test\Files\Node; +use OC\Cache\CappedMemoryCache; use OC\Files\FileInfo; use OC\Files\Mount\Manager; -use OC\User\NoUserException; +use OC\Files\Node\Folder; +use OC\Files\View; +use OCP\ILogger; +use OCP\IUser; +use OCP\IUserManager; +/** + * Class RootTest + * + * @package Test\Files\Node + */ class RootTest extends \Test\TestCase { /** @var \OC\User\User */ private $user; - /** @var \OC\Files\Mount\Manager */ private $manager; /** @var \OCP\Files\Config\IUserMountCache|\PHPUnit_Framework_MockObject_MockObject */ private $userMountCache; + /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */ + private $logger; + /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */ + private $userManager; protected function setUp() { parent::setUp(); @@ -32,13 +45,14 @@ class RootTest extends \Test\TestCase { ->getMock(); $this->user = new \OC\User\User('', new \Test\Util\User\Dummy, null, $config, $urlgenerator); - $this->manager = $this->getMockBuilder('\OC\Files\Mount\Manager') ->disableOriginalConstructor() ->getMock(); $this->userMountCache = $this->getMockBuilder('\OCP\Files\Config\IUserMountCache') ->disableOriginalConstructor() ->getMock(); + $this->logger = $this->createMock(ILogger::class); + $this->userManager = $this->createMock(IUserManager::class); } protected function getFileInfo($data) { @@ -58,7 +72,14 @@ class RootTest extends \Test\TestCase { $view = $this->getMockBuilder('\OC\Files\View') ->disableOriginalConstructor() ->getMock(); - $root = new \OC\Files\Node\Root($this->manager, $view, $this->user, $this->userMountCache); + $root = new \OC\Files\Node\Root( + $this->manager, + $view, + $this->user, + $this->userMountCache, + $this->logger, + $this->userManager + ); $view->expects($this->once()) ->method('getFileInfo') @@ -87,7 +108,14 @@ class RootTest extends \Test\TestCase { $view = $this->getMockBuilder('\OC\Files\View') ->disableOriginalConstructor() ->getMock(); - $root = new \OC\Files\Node\Root($this->manager, $view, $this->user, $this->userMountCache); + $root = new \OC\Files\Node\Root( + $this->manager, + $view, + $this->user, + $this->userMountCache, + $this->logger, + $this->userManager + ); $view->expects($this->once()) ->method('getFileInfo') @@ -108,7 +136,14 @@ class RootTest extends \Test\TestCase { $view = $this->getMockBuilder('\OC\Files\View') ->disableOriginalConstructor() ->getMock(); - $root = new \OC\Files\Node\Root($this->manager, $view, $this->user, $this->userMountCache); + $root = new \OC\Files\Node\Root( + $this->manager, + $view, + $this->user, + $this->userMountCache, + $this->logger, + $this->userManager + ); $root->get('/../foo'); } @@ -123,63 +158,82 @@ class RootTest extends \Test\TestCase { $view = $this->getMockBuilder('\OC\Files\View') ->disableOriginalConstructor() ->getMock(); - $root = new \OC\Files\Node\Root($this->manager, $view, $this->user, $this->userMountCache); + $root = new \OC\Files\Node\Root( + $this->manager, + $view, + $this->user, + $this->userMountCache, + $this->logger, + $this->userManager + ); $root->get('/bar/foo'); } public function testGetUserFolder() { - $this->logout(); - $manager = new Manager(); - /** - * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view - */ - $view = new \OC\Files\View(); - - $user1 = $this->getUniqueID('user1_'); - $user2 = $this->getUniqueID('user2_'); - - \OC_User::clearBackends(); - // needed for loginName2UserName mapping - $userBackend = $this->createMock(\OC\User\Database::class); - \OC::$server->getUserManager()->registerBackend($userBackend); - - $userBackend->expects($this->any()) - ->method('userExists') - ->will($this->returnValueMap([ - [$user1, true], - [$user2, true], - [strtoupper($user1), true], - [strtoupper($user2), true], - ])); - $userBackend->expects($this->any()) - ->method('loginName2UserName') - ->will($this->returnValueMap([ - [strtoupper($user1), $user1], - [$user1, $user1], - [strtoupper($user2), $user2], - [$user2, $user2], - ])); - - $this->loginAsUser($user1); - $root = new \OC\Files\Node\Root($manager, $view, null, $this->userMountCache); - - $folder = $root->getUserFolder($user1); - $this->assertEquals('/' . $user1 . '/files', $folder->getPath()); - - $folder = $root->getUserFolder($user2); - $this->assertEquals('/' . $user2 . '/files', $folder->getPath()); - - // case difference must not matter here - $folder = $root->getUserFolder(strtoupper($user2)); - $this->assertEquals('/' . $user2 . '/files', $folder->getPath()); - - $thrown = false; - try { - $folder = $root->getUserFolder($this->getUniqueID('unexist')); - } catch (NoUserException $e) { - $thrown = true; - } - $this->assertTrue($thrown); + $root = new \OC\Files\Node\Root( + $this->manager, + $this->createMock(View::class), + $this->user, + $this->userMountCache, + $this->logger, + $this->userManager + ); + $user = $this->createMock(IUser::class); + $user + ->expects($this->once()) + ->method('getUID') + ->willReturn('MyUserId'); + $this->userManager + ->expects($this->once()) + ->method('get') + ->with('MyUserId') + ->willReturn($user); + /** @var CappedMemoryCache|\PHPUnit_Framework_MockObject_MockObject $cappedMemoryCache */ + $cappedMemoryCache = $this->createMock(CappedMemoryCache::class); + $cappedMemoryCache + ->expects($this->once()) + ->method('hasKey') + ->willReturn(true); + $folder = $this->createMock(Folder::class); + $cappedMemoryCache + ->expects($this->once()) + ->method('get') + ->with('MyUserId') + ->willReturn($folder); + + $this->invokePrivate($root, 'userFolderCache', [$cappedMemoryCache]); + $this->assertEquals($folder, $root->getUserFolder('MyUserId')); + } + + /** + * @expectedException \OC\User\NoUserException + * @expectedExceptionMessage Backends provided no user object + */ + public function testGetUserFolderWithNoUserObj() { + $root = new \OC\Files\Node\Root( + $this->createMock(Manager::class), + $this->createMock(View::class), + null, + $this->userMountCache, + $this->logger, + $this->userManager + ); + $this->userManager + ->expects($this->once()) + ->method('get') + ->with('NotExistingUser') + ->willReturn(null); + $this->logger + ->expects($this->once()) + ->method('error') + ->with( + 'Backends provided no user object for NotExistingUser', + [ + 'app' => 'files', + ] + ); + + $root->getUserFolder('NotExistingUser'); } } |