Add missing unit test for updateShare with email share
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
parent
de6b05a911
commit
a56fb75e69
1 changed files with 75 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue