/** * Validate entity. * If the $partial parameter is TRUE, then we validate only those parameters that were passed. * * If fails validation, then this method returns false, and * getErrors() will return an array of errors that explain why the * validation failed. * * @param array $data * @param bool $partial * @return bool */ public function isValidData(array $data, $partial = false) { $errors = array(); foreach ($this->_eavForm->getAttributes() as $attribute) { if ($partial && !array_key_exists($attribute->getAttributeCode(), $data)) { continue; } if ($this->_eavForm->ignoreInvisible() && !$attribute->getIsVisible()) { continue; } $attrValue = isset($data[$attribute->getAttributeCode()]) ? $data[$attribute->getAttributeCode()] : null; $result = Mage_Eav_Model_Attribute_Data::factory($attribute, $this->_eavForm->getEntity())->setExtractedData($data)->validateValue($attrValue); if ($result !== true) { $errors = array_merge($errors, $result); } else { $result = $this->_validateAttributeWithSource($attribute, $attrValue); if (true !== $result) { $errors = array_merge($errors, $result); } } } $this->_setErrors($errors); return $errors ? false : true; }
/** * Test getAttributes */ public function testGetAttributes() { $expected = array('attribute_visible_user' => $this->_userAttribute, 'attribute_invisible_system' => $this->_systemAttribute); $this->assertEquals($expected, $this->_model->getAttributes()); }