Beispiel #1
0
 /**
  * Test isValid method
  *
  * @dataProvider isValidDataProvider
  *
  * @param mixed $value
  * @param Magento_Validator_ValidatorInterface[] $validators
  * @param boolean $expectedResult
  * @param array $expectedMessages
  * @param boolean $breakChainOnFailure
  */
 public function testIsValid($value, $validators, $expectedResult, $expectedMessages = array(), $breakChainOnFailure = false)
 {
     foreach ($validators as $validator) {
         $this->_validator->addValidator($validator, $breakChainOnFailure);
     }
     $this->assertEquals($expectedResult, $this->_validator->isValid($value));
     $this->assertEquals($expectedMessages, $this->_validator->getMessages($value));
 }
Beispiel #2
0
 /**
  * @param array $dataToValidate
  * @param PHPUnit_Framework_MockObject_MockObject $zendConstraintMock
  * @param PHPUnit_Framework_MockObject_MockObject $mageConstraintMock
  * @param Magento_Validator_Config $configMock
  * @dataProvider dataProviderForValidator
  */
 public function testGetErrors($dataToValidate, $zendConstraintMock, $mageConstraintMock, $configMock)
 {
     $expectedZendErrors = array('Test Zend_Validate_Interface constraint error.');
     $zendConstraintMock->expects($this->once())->method('isValid')->with($dataToValidate['test_field'])->will($this->returnValue(false));
     $zendConstraintMock->expects($this->once())->method('getMessages')->will($this->returnValue($expectedZendErrors));
     $expectedMageErrors = array('test_field_constraint' => array('Test Magento_Validator_ConstraintInterface constraint error.'));
     $mageConstraintMock->expects($this->once())->method('isValidData')->with($dataToValidate, 'test_field_constraint')->will($this->returnValue(false));
     $mageConstraintMock->expects($this->once())->method('getErrors')->will($this->returnValue($expectedMageErrors));
     $validator = new Magento_Validator('test_entity', 'test_group_a', $configMock);
     $this->assertFalse($validator->isValid($dataToValidate));
     $expectedErrors = array_merge(array('test_field' => $expectedZendErrors), $expectedMageErrors);
     $actualErrors = $validator->getMessages();
     $this->assertEquals($expectedErrors, $actualErrors);
 }