Exemplo n.º 1
0
 /**
  * @param bool $result
  * @dataProvider validateCustomerPassword
  */
 public function testValidateCustomerPassword($result)
 {
     $customerId = 7;
     $password = '******';
     $hash = '1b2af329dd0';
     $customerMock = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false);
     $this->customerRepositoryMock->expects($this->any())->method('getById')->willReturn($customerMock);
     $this->customerSecure->expects($this->any())->method('getId')->willReturn($customerId);
     $this->customerSecure->expects($this->once())->method('getPasswordHash')->willReturn($hash);
     $this->customerRegistryMock->expects($this->any())->method('retrieveSecureData')->with($customerId)->willReturn($this->customerSecure);
     $this->encryptorMock->expects($this->once())->method('validateHash')->with($password, $hash)->willReturn($result);
     if ($result) {
         $this->assertTrue($this->authentication->authenticate($customerId, $password));
     } else {
         $this->backendConfigMock->expects($this->exactly(2))->method('getValue')->withConsecutive([\Magento\Customer\Model\Authentication::LOCKOUT_THRESHOLD_PATH], [\Magento\Customer\Model\Authentication::MAX_FAILURES_PATH])->willReturnOnConsecutiveCalls(1, 1);
         $this->customerSecure->expects($this->once())->method('isCustomerLocked')->willReturn(false);
         $this->customerRegistryMock->expects($this->once())->method('retrieve')->with($customerId)->willReturn($this->customerSecure);
         $this->customerRepositoryMock->expects($this->once())->method('save')->willReturn($customerMock);
         $this->setExpectedException('\\Magento\\Framework\\Exception\\InvalidEmailOrPasswordException');
         $this->authentication->authenticate($customerId, $password);
     }
 }