當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ISecureRandom::method方法代碼示例

本文整理匯總了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());
 }
開發者ID:GitHubUser4234,項目名稱:core,代碼行數:42,代碼來源:ManagerTest.php

示例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);
 }
開發者ID:gcstang,項目名稱:core,代碼行數:37,代碼來源:managertest.php


注:本文中的OCP\Security\ISecureRandom::method方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。