Exemplo n.º 1
0
 /**
  * Validate input data against validation rules, defined in config group.
  *
  * @param array $data
  * @throws Magento_Exception
  * @return bool
  */
 public function isValid(array $data)
 {
     $isValid = true;
     $rules = $this->_config->getValidationRules($this->_entityName, $this->_groupName);
     foreach ($rules as $rule) {
         foreach ($rule as $constraintConfig) {
             $constraint = $constraintConfig['constraint'];
             $field = isset($constraintConfig['field']) ? $constraintConfig['field'] : null;
             if ($constraint instanceof Zend_Validate_Interface) {
                 /** @var Zend_Validate_Interface $constraint */
                 $value = isset($data[$field]) ? $data[$field] : null;
                 if (!$constraint->isValid($value)) {
                     foreach ($constraint->getMessages() as $error) {
                         $this->_messages[$field][] = $error;
                     }
                     $isValid = false;
                 }
             } else {
                 /** @var Magento_Validator_ConstraintAbstract $constraint */
                 if (!$constraint->isValidData($data, $field)) {
                     foreach ($constraint->getErrors() as $errorFieldName => $errors) {
                         foreach ($errors as $error) {
                             $this->_messages[$errorFieldName][] = $error;
                         }
                     }
                     $isValid = false;
                 }
             }
         }
     }
     return $isValid;
 }
Exemplo n.º 2
0
 /**
  * Test createValidatorBuilder call
  */
 public function testCreateValidator()
 {
     $this->_validatorConfig->expects($this->once())->method('createValidator')->with('test', 'class', array())->will($this->returnValue(new Magento_Validator()));
     $factory = new Mage_Core_Model_Validator_Factory($this->_objectManager, $this->_config, $this->_translateAdapter);
     $this->assertInstanceOf('Magento_Validator', $factory->createValidator('test', 'class', array()));
 }
Exemplo n.º 3
0
 public function testGetSchemaFile()
 {
     $this->assertFileExists(self::$_model->getSchemaFile());
 }
Exemplo n.º 4
0
 /**
  * Test schema file exists
  */
 public function testGetSchemaFile()
 {
     $this->_initConfig();
     $this->assertFileExists($this->_config->getSchemaFile());
 }
Exemplo n.º 5
0
 /**
  * Get validator
  *
  * @param array $data
  * @return Magento_Validator
  */
 protected function _getValidator(array $data)
 {
     if (is_null($this->_validator)) {
         $configFiles = Mage::getConfig()->getModuleConfigurationFiles('validation.xml');
         $validatorFactory = new Magento_Validator_Config($configFiles);
         $builder = $validatorFactory->createValidatorBuilder('eav_entity', 'form');
         $builder->addConfiguration('eav_data_validator', array('method' => 'setAttributes', 'arguments' => array($this->getAllowedAttributes())));
         $builder->addConfiguration('eav_data_validator', array('method' => 'setData', 'arguments' => array($data)));
         $this->_validator = $builder->createValidator();
     }
     return $this->_validator;
 }