示例#1
0
 /**
  * @return void
  */
 public function testValidateInvalid()
 {
     $messages = ['Invalid username'];
     /** @var $validatorMock \Magento\Framework\Validator\DataObject|\PHPUnit_Framework_MockObject_MockObject */
     $validatorMock = $this->getMockBuilder('Magento\\Framework\\Validator\\DataObject')->disableOriginalConstructor()->setMethods([])->getMock();
     $this->validatorObjectFactoryMock->expects($this->once())->method('create')->willReturn($validatorMock);
     $this->validationRulesMock->expects($this->once())->method('addUserInfoRules')->with($validatorMock);
     $validatorMock->expects($this->once())->method('isValid')->willReturn(false);
     $validatorMock->expects($this->once())->method('getMessages')->willReturn($messages);
     $this->assertEquals($messages, $this->model->validate());
 }
 public function testCheckPasswordChangeValid()
 {
     /** @var $validatorMock \Magento\Framework\Validator\DataObject|\PHPUnit_Framework_MockObject_MockObject */
     $validatorMock = $this->getMockBuilder('Magento\\Framework\\Validator\\DataObject')->disableOriginalConstructor()->setMethods([])->getMock();
     $this->validatorObjectFactoryMock->expects($this->once())->method('create')->willReturn($validatorMock);
     $this->validationRulesMock->expects($this->once())->method('addUserInfoRules')->with($validatorMock);
     $validatorMock->expects($this->once())->method('isValid')->willReturn(true);
     $newPassword = "******";
     $oldPassword = "******";
     $this->model->setPassword($newPassword)->setId(1)->setOrigData('password', $oldPassword);
     $this->encryptorMock->expects($this->atLeastOnce())->method('isValidHash')->will($this->onConsecutiveCalls(false, false, false));
     $this->resourceMock->expects($this->once())->method('getOldPasswords')->willReturn(['hash1', 'hash2']);
     $result = $this->model->validate();
     $this->assertTrue($result);
 }