summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDaniel Calviño Sánchez <danxuliu@gmail.com>2017-04-23 19:11:06 +0200
committerDaniel Calviño Sánchez <danxuliu@gmail.com>2017-04-24 11:33:07 +0200
commita56fb75e690bffcc0c2d35c6748a5778721fe369 (patch)
tree1cf229cae0c3298eddb4c2ea1c8e54e6275e8b95 /tests
parentde6b05a911118583178830a33f19b9010c480398 (diff)
downloadnextcloud-server-a56fb75e690bffcc0c2d35c6748a5778721fe369.tar.gz
nextcloud-server-a56fb75e690bffcc0c2d35c6748a5778721fe369.zip
Add missing unit test for updateShare with email share
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Share20/ManagerTest.php75
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php
index d8a637ef021..13556285b61 100644
--- a/tests/lib/Share20/ManagerTest.php
+++ b/tests/lib/Share20/ManagerTest.php
@@ -2560,6 +2560,81 @@ class ManagerTest extends \Test\TestCase {
$manager->updateShare($share);
}
+ public function testUpdateShareMail() {
+ $manager = $this->createManagerMock()
+ ->setMethods([
+ 'canShare',
+ 'getShareById',
+ 'generalCreateChecks',
+ 'verifyPassword',
+ 'pathCreateChecks',
+ 'linkCreateChecks',
+ 'validateExpirationDate',
+ ])
+ ->getMock();
+
+ $originalShare = $this->manager->newShare();
+ $originalShare->setShareType(\OCP\Share::SHARE_TYPE_EMAIL)
+ ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+
+ $tomorrow = new \DateTime();
+ $tomorrow->setTime(0,0,0);
+ $tomorrow->add(new \DateInterval('P1D'));
+
+ $file = $this->createMock(File::class);
+ $file->method('getId')->willReturn(100);
+
+ $share = $this->manager->newShare();
+ $share->setProviderId('foo')
+ ->setId('42')
+ ->setShareType(\OCP\Share::SHARE_TYPE_EMAIL)
+ ->setToken('token')
+ ->setSharedBy('owner')
+ ->setShareOwner('owner')
+ ->setPassword('password')
+ ->setExpirationDate($tomorrow)
+ ->setNode($file)
+ ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+
+ $manager->expects($this->once())->method('canShare')->willReturn(true);
+ $manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
+ $manager->expects($this->once())->method('generalCreateChecks')->with($share);
+ $manager->expects($this->once())->method('verifyPassword')->with('password');
+ $manager->expects($this->once())->method('pathCreateChecks')->with($file);
+ $manager->expects($this->never())->method('linkCreateChecks');
+ $manager->expects($this->never())->method('validateExpirationDate');
+
+ $this->hasher->expects($this->once())
+ ->method('hash')
+ ->with('password')
+ ->willReturn('hashed');
+
+ $this->defaultProvider->expects($this->once())
+ ->method('update')
+ ->with($share, 'password')
+ ->willReturn($share);
+
+ $hookListner = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListner, 'post');
+ $hookListner->expects($this->never())->method('post');
+
+ $hookListner2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ \OCP\Util::connectHook('OCP\Share', 'post_update_password', $hookListner2, 'post');
+ $hookListner2->expects($this->once())->method('post')->with([
+ 'itemType' => 'file',
+ 'itemSource' => 100,
+ 'uidOwner' => 'owner',
+ 'token' => 'token',
+ 'disabled' => false,
+ ]);
+
+ $hookListner3 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
+ \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListner3, 'post');
+ $hookListner3->expects($this->never())->method('post');
+
+ $manager->updateShare($share);
+ }
+
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Can't change target of link share