Esempio n. 1
0
 /**
  * Adds validation rule for user password confirmation
  *
  * @param \Magento\Framework\Validator\Object $validator
  * @param string $passwordConfirmation
  * @return \Magento\Framework\Validator\Object
  */
 public function addPasswordConfirmationRule(\Magento\Framework\Validator\Object $validator, $passwordConfirmation)
 {
     $passwordConfirmation = new \Zend_Validate_Identical($passwordConfirmation);
     $passwordConfirmation->setMessage(__('Your password confirmation must match your password.'), \Zend_Validate_Identical::NOT_SAME);
     $validator->addRule($passwordConfirmation, 'password');
     return $validator;
 }
Esempio n. 2
0
 /**
  * @param array $inputEntityData
  * @param array $expectedErrors
  * @dataProvider validateDataProvider
  */
 public function testIsValid(array $inputEntityData, array $expectedErrors)
 {
     $entity = new \Magento\Framework\Object($inputEntityData);
     $isValid = $this->_model->isValid($entity);
     $this->assertFalse($isValid, 'Validation is expected to fail.');
     $actualMessages = $this->_model->getMessages();
     $this->assertCount(count($expectedErrors), $actualMessages, 'Number of messages does not meet expectations.');
     foreach ($expectedErrors as $errorIndex => $expectedErrorMessage) {
         /** @var $actualMessage \Magento\Framework\Message\AbstractMessage */
         $actualMessage = $actualMessages[$errorIndex];
         $this->assertEquals($expectedErrorMessage, $actualMessage);
     }
 }
Esempio n. 3
0
 /**
  * Add validation rules for the password management fields
  *
  * @param \Magento\Framework\Validator\Object $validator
  * @return void
  */
 protected function _addPasswordValidation(\Magento\Framework\Validator\Object $validator)
 {
     $passwordNotEmpty = new \Zend_Validate_NotEmpty();
     $passwordNotEmpty->setMessage(__('Password is required field.'), \Zend_Validate_NotEmpty::IS_EMPTY);
     $minPassLength = self::MIN_PASSWORD_LENGTH;
     $passwordLength = new \Zend_Validate_StringLength(array('min' => $minPassLength, 'encoding' => 'UTF-8'));
     $passwordLength->setMessage(__('Your password must be at least %1 characters.', $minPassLength), \Zend_Validate_StringLength::TOO_SHORT);
     $passwordChars = new \Zend_Validate_Regex('/[a-z].*\\d|\\d.*[a-z]/iu');
     $passwordChars->setMessage(__('Your password must include both numeric and alphabetic characters.'), \Zend_Validate_Regex::NOT_MATCH);
     $validator->addRule($passwordNotEmpty, 'password')->addRule($passwordLength, 'password')->addRule($passwordChars, 'password');
     if ($this->hasPasswordConfirmation()) {
         $passwordConfirmation = new \Zend_Validate_Identical($this->getPasswordConfirmation());
         $passwordConfirmation->setMessage(__('Your password confirmation must match your password.'), \Zend_Validate_Identical::NOT_SAME);
         $validator->addRule($passwordConfirmation, 'password');
     }
 }
Esempio n. 4
0
 public function testAddPasswordConfirmationRule()
 {
     $this->validator->expects($this->once())->method('addRule')->willReturn($this->validator);
     $this->assertSame($this->validator, $this->rules->addPasswordConfirmationRule($this->validator, ''));
 }