本文整理汇总了PHP中OCP\Security\ISecureRandom::method方法的典型用法代码示例。如果您正苦于以下问题:PHP ISecureRandom::method方法的具体用法?PHP ISecureRandom::method怎么用?PHP ISecureRandom::method使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OCP\Security\ISecureRandom
的用法示例。
在下文中一共展示了ISecureRandom::method方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCreateShareLink
public function testCreateShareLink()
{
$manager = $this->createManagerMock()->setMethods(['canShare', 'generalCreateChecks', 'linkCreateChecks', 'pathCreateChecks', 'validateExpirationDate', 'verifyPassword', 'setLinkParent'])->getMock();
$shareOwner = $this->getMock('\\OCP\\IUser');
$shareOwner->method('getUID')->willReturn('shareOwner');
$storage = $this->getMock('\\OCP\\Files\\Storage');
$path = $this->getMock('\\OCP\\Files\\File');
$path->method('getOwner')->willReturn($shareOwner);
$path->method('getName')->willReturn('target');
$path->method('getId')->willReturn(1);
$path->method('getStorage')->willReturn($storage);
$date = new \DateTime();
$share = $this->manager->newShare();
$share->setShareType(\OCP\Share::SHARE_TYPE_LINK)->setNode($path)->setSharedBy('sharedBy')->setPermissions(\OCP\Constants::PERMISSION_ALL)->setExpirationDate($date)->setPassword('password');
$manager->expects($this->once())->method('canShare')->with($share)->willReturn(true);
$manager->expects($this->once())->method('generalCreateChecks')->with($share);
$manager->expects($this->once())->method('linkCreateChecks')->with($share);
$manager->expects($this->once())->method('pathCreateChecks')->with($path);
$manager->expects($this->once())->method('validateExpirationDate')->with($share);
$manager->expects($this->once())->method('verifyPassword')->with('password');
$manager->expects($this->once())->method('setLinkParent')->with($share);
$this->hasher->expects($this->once())->method('hash')->with('password')->willReturn('hashed');
$this->secureRandom->method('getMediumStrengthGenerator')->will($this->returnSelf());
$this->secureRandom->method('generate')->willReturn('token');
$this->defaultProvider->expects($this->once())->method('create')->with($share)->will($this->returnCallback(function (Share $share) {
return $share->setId(42);
}));
$hookListner = $this->getMockBuilder('Dummy')->setMethods(['pre', 'post'])->getMock();
\OCP\Util::connectHook('OCP\\Share', 'pre_shared', $hookListner, 'pre');
\OCP\Util::connectHook('OCP\\Share', 'post_shared', $hookListner, 'post');
$hookListnerExpectsPre = ['itemType' => 'file', 'itemSource' => 1, 'shareType' => \OCP\Share::SHARE_TYPE_LINK, 'uidOwner' => 'sharedBy', 'permissions' => 31, 'fileSource' => 1, 'expiration' => $date, 'token' => 'token', 'run' => true, 'error' => '', 'itemTarget' => '/target', 'shareWith' => null];
$hookListnerExpectsPost = ['itemType' => 'file', 'itemSource' => 1, 'shareType' => \OCP\Share::SHARE_TYPE_LINK, 'uidOwner' => 'sharedBy', 'permissions' => 31, 'fileSource' => 1, 'expiration' => $date, 'token' => 'token', 'id' => 42, 'itemTarget' => '/target', 'fileTarget' => '/target', 'shareWith' => null];
$hookListner->expects($this->once())->method('pre')->with($this->equalTo($hookListnerExpectsPre));
$hookListner->expects($this->once())->method('post')->with($this->equalTo($hookListnerExpectsPost));
/** @var IShare $share */
$share = $manager->createShare($share);
$this->assertSame('shareOwner', $share->getShareOwner());
$this->assertEquals('/target', $share->getTarget());
$this->assertSame($date, $share->getExpirationDate());
$this->assertEquals('token', $share->getToken());
$this->assertEquals('hashed', $share->getPassword());
}
示例2: testCreateShareLink
public function testCreateShareLink()
{
$manager = $this->getMockBuilder('\\OC\\Share20\\Manager')->setConstructorArgs([$this->logger, $this->config, $this->defaultProvider, $this->secureRandom, $this->hasher, $this->mountManager, $this->groupManager, $this->l])->setMethods(['canShare', 'generalCreateChecks', 'linkCreateChecks', 'pathCreateChecks', 'validateExpiredate', 'verifyPassword'])->getMock();
$sharedBy = $this->getMock('\\OCP\\IUser');
$sharedBy->method('getUID')->willReturn('sharedBy');
$shareOwner = $this->getMock('\\OCP\\IUser');
$path = $this->getMock('\\OCP\\Files\\File');
$path->method('getOwner')->willReturn($shareOwner);
$path->method('getName')->willReturn('target');
$path->method('getId')->willReturn(1);
$date = new \DateTime();
$share = $this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $path, null, $sharedBy, null, \OCP\Constants::PERMISSION_ALL, $date, 'password');
$manager->expects($this->once())->method('canShare')->with($share)->willReturn(true);
$manager->expects($this->once())->method('generalCreateChecks')->with($share);
$manager->expects($this->once())->method('linkCreateChecks')->with($share);
$manager->expects($this->once())->method('pathCreateChecks')->with($path);
$manager->expects($this->once())->method('validateExpiredate')->with($date)->will($this->returnArgument(0));
$manager->expects($this->once())->method('verifyPassword')->with('password');
$this->hasher->expects($this->once())->method('hash')->with('password')->willReturn('hashed');
$this->secureRandom->method('getMediumStrengthGenerator')->will($this->returnSelf());
$this->secureRandom->method('generate')->willReturn('token');
$this->defaultProvider->expects($this->once())->method('create')->with($share)->will($this->returnArgument(0));
$share->expects($this->once())->method('setShareOwner')->with($shareOwner);
$share->expects($this->once())->method('setTarget')->with('/target');
$share->expects($this->once())->method('setExpirationDate')->with($date);
$share->expects($this->once())->method('setPassword')->with('hashed');
$share->method('getToken')->willReturn('token');
$hookListner = $this->getMockBuilder('Dummy')->setMethods(['pre', 'post'])->getMock();
\OCP\Util::connectHook('OCP\\Share', 'pre_shared', $hookListner, 'pre');
\OCP\Util::connectHook('OCP\\Share', 'post_shared', $hookListner, 'post');
$hookListnerExpectsPre = ['itemType' => 'file', 'itemSource' => 1, 'shareType' => \OCP\Share::SHARE_TYPE_LINK, 'uidOwner' => 'sharedBy', 'permissions' => 31, 'fileSource' => 1, 'expiration' => $date, 'token' => 'token', 'run' => true, 'error' => ''];
$hookListnerExpectsPost = ['itemType' => 'file', 'itemSource' => 1, 'shareType' => \OCP\Share::SHARE_TYPE_LINK, 'uidOwner' => 'sharedBy', 'permissions' => 31, 'fileSource' => 1, 'expiration' => $date, 'token' => 'token', 'id' => 42];
$share->method('getId')->willReturn(42);
$hookListner->expects($this->once())->method('pre')->with($this->equalTo($hookListnerExpectsPre));
$hookListner->expects($this->once())->method('post')->with($this->equalTo($hookListnerExpectsPost));
$manager->createShare($share);
}