diff --git a/app/code/core/Mage/Eav/Model/Attribute/Data/Text.php b/app/code/core/Mage/Eav/Model/Attribute/Data/Text.php index c48ed5932025..15432541815d 100644 --- a/app/code/core/Mage/Eav/Model/Attribute/Data/Text.php +++ b/app/code/core/Mage/Eav/Model/Attribute/Data/Text.php @@ -64,7 +64,7 @@ public function validateValue($value) $value = $this->getEntity()->getDataUsingMethod($attribute->getAttributeCode()); } - if ($attribute->getIsRequired() && empty($value)) { + if ($attribute->getIsRequired() && empty($value) && $value !=='0') { $errors[] = Mage::helper('Mage_Eav_Helper_Data')->__('"%s" is a required value.', $label); } diff --git a/dev/tests/unit/testsuite/Mage/Eav/Model/Attribute/Data/TextTest.php b/dev/tests/unit/testsuite/Mage/Eav/Model/Attribute/Data/TextTest.php new file mode 100644 index 000000000000..e7f438cf5a5a --- /dev/null +++ b/dev/tests/unit/testsuite/Mage/Eav/Model/Attribute/Data/TextTest.php @@ -0,0 +1,102 @@ +_model = $this->getMock('Mage_Eav_Model_Attribute_Data_Text', array('getAttribute'), array(), '', false); + $attributeData = array( + 'store_label' => 'Test', + 'attribute_code' => 'test', + 'is_required' => 1, + 'validate_rules' => array( + 'min_text_length' => 0, + 'max_text_length' => 0, + 'input_validation' => 0 + ) + ); + + /** @var $model Mage_Core_Model_Abstract */ + $attribute = $this->getMock('Mage_Core_Model_Abstract', null, array($attributeData)); + + $this->_attribute = $attribute; + $this->_model->expects($this->any()) + ->method('getAttribute') + ->will($this->returnValue($this->_attribute)); + $helper = $this->getMockBuilder('Mage_Core_Helper_String') + ->setMethods(array('__')) + ->disableOriginalConstructor() + ->getMock(); + $helper->expects($this->any()) + ->method('__') + ->will($this->returnArgument(0)); + Mage::register('_helper/Mage_Eav_Helper_Data', $helper); + Mage::register('_helper/Mage_Core_Helper_String', $helper); + + + } + + protected function tearDown() + { + $this->_model = null; + Mage::unregister('_helper/Mage_Eav_Helper_Data'); + Mage::unregister('_helper/Mage_Core_Helper_String'); + } + + /** + * This test is to check the change made to validateValue. + * A bug was found where a text attribute that has is_required==1 + * would not accept the string value of "0" (zero) as an input. + * That bug was fixed. + * @covers Mage_Eav_Model_Attribute_Data_Text::validateValue + * @param string|int|float|array $value + * @param string|int|float|array $expectedResult + * @dataProvider dataGetValuesAndResults + */ + public function testValidateValue($value, $expectedResult) + { + $this->assertEquals($expectedResult, $this->_model->validateValue($value)); + } + + public static function dataGetValuesAndResults() + { + return array( + array("0",true), //The string value of zero should be a valid input + array(0, array('"%s" is a required value.')) //Integer value of zero remains invalid + ); + } +} \ No newline at end of file