diff options
author | Vincent Petry <pvince81@owncloud.com> | 2016-11-24 17:17:15 +0100 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2017-01-12 13:52:59 +0100 |
commit | 269b6527544a4a91687e1e443c6de3f2d42e05dd (patch) | |
tree | bcb5619f11f11274cc3ee046a655d0002beb979a /tests | |
parent | e667b28298add5b6ecc6a3956bfb93cb4a047097 (diff) | |
download | nextcloud-server-269b6527544a4a91687e1e443c6de3f2d42e05dd.tar.gz nextcloud-server-269b6527544a4a91687e1e443c6de3f2d42e05dd.zip |
Add tests for move/copy hooks in Node API
Signed-off-by: Vincent Petry <pvince81@owncloud.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Files/Node/NodeTest.php | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/tests/lib/Files/Node/NodeTest.php b/tests/lib/Files/Node/NodeTest.php index 03f9118d9e4..5e18caa2014 100644 --- a/tests/lib/Files/Node/NodeTest.php +++ b/tests/lib/Files/Node/NodeTest.php @@ -579,6 +579,87 @@ abstract class NodeTest extends \Test\TestCase { $this->assertEquals('/bar/asd', $node->getPath()); } + public function moveOrCopyProvider() { + return [ + ['move', 'rename', 'preRename', 'postRename'], + ['copy', 'copy', 'preCopy', 'postCopy'], + ]; + } + + /** + * @dataProvider moveOrCopyProvider + * @param string $operationMethod + * @param string $viewMethod + * @param string $preHookName + * @param string $postHookName + */ + public function testMoveCopyHooks($operationMethod, $viewMethod, $preHookName, $postHookName) { + /** @var IRootFolder|\PHPUnit_Framework_MockObject_MockObject $root */ + $root = $this->getMockBuilder('\OC\Files\Node\Root') + ->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager]) + ->setMethods(['get']) + ->getMock(); + + $this->view->expects($this->any()) + ->method($viewMethod) + ->with('/bar/foo', '/bar/asd') + ->will($this->returnValue(true)); + + $this->view->expects($this->any()) + ->method('getFileInfo') + ->will($this->returnValue($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1]))); + + /** + * @var \OC\Files\Node\File|\PHPUnit_Framework_MockObject_MockObject $node + */ + $node = $this->createTestNode($root, $this->view, '/bar/foo'); + $parentNode = new \OC\Files\Node\Folder($root, $this->view, '/bar'); + $targetTestNode = $this->createTestNode($root, $this->view, '/bar/asd'); + + $root->expects($this->any()) + ->method('get') + ->will($this->returnValueMap([['/bar', $parentNode], ['/bar/asd', $targetTestNode]])); + + $hooksRun = 0; + + $preListener = function (Node $sourceNode, Node $targetNode) use (&$hooksRun, $node) { + $this->assertSame($node, $sourceNode); + $this->assertInstanceOf($this->getNodeClass(), $sourceNode); + $this->assertInstanceOf($this->getNonExistingNodeClass(), $targetNode); + $this->assertEquals('/bar/asd', $targetNode->getPath()); + $hooksRun++; + }; + + $postListener = function (Node $sourceNode, Node $targetNode) use (&$hooksRun, $node, $targetTestNode) { + $this->assertSame($node, $sourceNode); + $this->assertNotSame($node, $targetNode); + $this->assertSame($targetTestNode, $targetNode); + $this->assertInstanceOf($this->getNodeClass(), $sourceNode); + $this->assertInstanceOf($this->getNodeClass(), $targetNode); + $hooksRun++; + }; + + $preWriteListener = function (Node $targetNode) use (&$hooksRun) { + $this->assertInstanceOf($this->getNonExistingNodeClass(), $targetNode); + $this->assertEquals('/bar/asd', $targetNode->getPath()); + $hooksRun++; + }; + + $postWriteListener = function (Node $targetNode) use (&$hooksRun, $targetTestNode) { + $this->assertSame($targetTestNode, $targetNode); + $hooksRun++; + }; + + $root->listen('\OC\Files', $preHookName, $preListener); + $root->listen('\OC\Files', 'preWrite', $preWriteListener); + $root->listen('\OC\Files', $postHookName, $postListener); + $root->listen('\OC\Files', 'postWrite', $postWriteListener); + + $node->$operationMethod('/bar/asd'); + + $this->assertEquals(4, $hooksRun); + } + /** * @expectedException \OCP\Files\NotPermittedException */ |