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


PHP UserInterface::expects方法代碼示例

本文整理匯總了PHP中Drupal\user\UserInterface::expects方法的典型用法代碼示例。如果您正苦於以下問題:PHP UserInterface::expects方法的具體用法?PHP UserInterface::expects怎麽用?PHP UserInterface::expects使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Drupal\user\UserInterface的用法示例。


在下文中一共展示了UserInterface::expects方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     new Settings(array('hash_salt' => 'test'));
     // The mocked super user account, with the same roles as Account 2.
     $this->account1 = $this->getMockBuilder('Drupal\\user\\Entity\\User')->disableOriginalConstructor()->setMethods(array('getRoles', 'id'))->getMock();
     $this->account1->expects($this->any())->method('id')->willReturn(1);
     $this->account1->expects($this->never())->method('getRoles');
     // Account 2: 'administrator' and 'authenticated' roles.
     $roles_1 = array('administrator', 'authenticated');
     $this->account2 = $this->getMockBuilder('Drupal\\user\\Entity\\User')->disableOriginalConstructor()->setMethods(array('getRoles', 'id'))->getMock();
     $this->account2->expects($this->any())->method('getRoles')->will($this->returnValue($roles_1));
     $this->account2->expects($this->any())->method('id')->willReturn(2);
     // Account 3: 'authenticated' and 'administrator' roles (different order).
     $roles_3 = array('authenticated', 'administrator');
     $this->account3 = $this->getMockBuilder('Drupal\\user\\Entity\\User')->disableOriginalConstructor()->setMethods(array('getRoles', 'id'))->getMock();
     $this->account3->expects($this->any())->method('getRoles')->will($this->returnValue($roles_3));
     $this->account3->expects($this->any())->method('id')->willReturn(3);
     // Updated account 2: now also 'editor' role.
     $roles_2_updated = array('editor', 'administrator', 'authenticated');
     $this->account2Updated = $this->getMockBuilder('Drupal\\user\\Entity\\User')->disableOriginalConstructor()->setMethods(array('getRoles', 'id'))->getMock();
     $this->account2Updated->expects($this->any())->method('getRoles')->will($this->returnValue($roles_2_updated));
     $this->account2Updated->expects($this->any())->method('id')->willReturn(2);
     // Mocked private key + cache services.
     $random = Crypt::randomBytesBase64(55);
     $this->privateKey = $this->getMockBuilder('Drupal\\Core\\PrivateKey')->disableOriginalConstructor()->setMethods(array('get'))->getMock();
     $this->privateKey->expects($this->any())->method('get')->will($this->returnValue($random));
     $this->cache = $this->getMockBuilder('Drupal\\Core\\Cache\\CacheBackendInterface')->disableOriginalConstructor()->getMock();
     $this->staticCache = $this->getMockBuilder('Drupal\\Core\\Cache\\CacheBackendInterface')->disableOriginalConstructor()->getMock();
     $this->permissionsHash = new PermissionsHashGenerator($this->privateKey, $this->cache, $this->staticCache);
 }
開發者ID:aWEBoLabs,項目名稱:taxi,代碼行數:34,代碼來源:PermissionsHashGeneratorTest.php

示例2: testPasswordRehashing

 /**
  * Tests password rehashing.
  *
  * @covers ::hash
  * @covers ::getCountLog2
  * @covers ::check
  * @covers ::userNeedsNewHash
  */
 public function testPasswordRehashing()
 {
     // Increment the log2 iteration to MIN + 1.
     $this->passwordHasher = new PhpassHashedPassword(PhpassHashedPassword::MIN_HASH_COUNT + 1);
     $this->assertTrue($this->passwordHasher->userNeedsNewHash($this->user), 'User needs a new hash after incrementing the log2 count.');
     // Re-hash the password.
     $rehashed_password = $this->passwordHasher->hash($this->password);
     $this->user->expects($this->any())->method('getPassword')->will($this->returnValue($rehashed_password));
     $this->assertSame($this->passwordHasher->getCountLog2($rehashed_password), PhpassHashedPassword::MIN_HASH_COUNT + 1, 'Re-hashed password has the correct number of log2 iterations.');
     $this->assertNotEquals($rehashed_password, $this->hashedPassword, 'Password hash changed again.');
     // Now the hash should be OK.
     $this->assertFalse($this->passwordHasher->userNeedsNewHash($this->user), 'Re-hashed password does not need a new hash.');
     $this->assertTrue($this->passwordHasher->check($this->password, $this->user), 'Password check succeeds with re-hashed password.');
 }
開發者ID:nstielau,項目名稱:drops-8,代碼行數:22,代碼來源:PasswordHashingTest.php


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