public function testWalkAttributes() { $code = 'test_attr'; $set = 10; $object = $this->getMock('Mage_Catalog_Model_Product', null, array(), '', false); $object->setData(array('test_attr' => 'test_attr', 'attribute_set_id' => $set)); $entityType = new Varien_Object(); $entityType->setEntityTypeCode('test'); $entityType->setEntityTypeId(0); $entityType->setEntityTable('table'); $attributes = $this->_getAttributes(); $attribute = $this->getMock('Mage_Eav_Model_Entity_Attribute_Abstract', array('isInSet', 'getBackend'), array(), '', false); $attribute->setAttributeId($code); $attribute->setAttributeCode($code); $attribute->expects($this->once())->method('isInSet')->with($this->equalTo($set))->will($this->returnValue(false)); $attributes[$code] = $attribute; /** @var $model Mage_Catalog_Model_Resource_Abstract */ $model = $this->getMock('Mage_Catalog_Model_Resource_Abstract', null, array(array('type' => $entityType, 'entityTable' => 'entityTable', 'attributesByCode' => $attributes))); $model->walkAttributes('backend/afterSave', array($object)); }
public function testSave() { $code = 'test_attr'; $set = 10; $object = $this->getMock('Mage_Catalog_Model_Product', null, array(), '', false); $object->setEntityTypeId(1); $object->setData(array('test_attr' => 'test_attr', 'attribute_set_id' => $set)); $entityType = new Varien_Object(); $entityType->setEntityTypeCode('test'); $entityType->setEntityTypeId(0); $entityType->setEntityTable('table'); $attributes = $this->_getAttributes(); $attribute = $this->getMock('Mage_Eav_Model_Entity_Attribute_Abstract', array('getBackend', 'getBackendTable', 'isInSet', 'getApplyTo'), array(), '', false); $attribute->setAttributeId($code); /** @var $backendModel Mage_Eav_Model_Entity_Attribute_Backend_Abstract */ $backendModel = $this->getMock('Mage_Eav_Model_Entity_Attribute_Backend_Abstract', array('getBackend', 'getBackendTable', 'getAffectedFields')); $backendModel->expects($this->once())->method('getAffectedFields')->will($this->returnValue(array('test_table' => array('value_id' => 0, 'attribute_id' => $code)))); $backendModel->setAttribute($attribute); $attribute->expects($this->any())->method('getBackend')->will($this->returnValue($backendModel)); $attribute->expects($this->any())->method('getBackendTable')->will($this->returnValue($code . '_table')); $attribute->expects($this->any())->method('isInSet')->with($this->equalTo($set))->will($this->returnValue(false)); $attributes[$code] = $attribute; /** @var $model Mage_Eav_Model_Entity_Abstract */ $model = $this->getMock('Mage_Eav_Model_Entity_Abstract', null, array(array('type' => $entityType, 'entityTable' => 'entityTable', 'attributesByCode' => $attributes))); $model->setConnection($this->_getAdapterMock()); $model->isPartialSave(true); $model->save($object); }