/** * @magentoDataIsolation enabled * @magentoDataFixture mediaImportImageFixture */ public function testSaveMediaImage() { if (Magento_Test_Bootstrap::getInstance()->getDbVendorName() != 'mysql') { $this->markTestIncomplete('bug: MAGETWO-4227'); } $attribute = Mage::getModel('Mage_Catalog_Model_Entity_Attribute'); $attribute->loadByCode('catalog_product', 'media_gallery'); $data = implode(',', array('sku', '_attribute_set', '_type', '_product_websites', 'name', 'price', 'description', 'short_description', 'weight', 'status', 'visibility', 'tax_class_id', '_media_attribute_id', '_media_image', '_media_label', '_media_position', '_media_is_disabled')) . "\n"; $data .= implode(',', array('test_sku', 'Default', Mage_Catalog_Model_Product_Type::DEFAULT_TYPE, 'base', 'Product Name', '9.99', 'Product description', 'Short desc.', '1', Mage_Catalog_Model_Product_Status::STATUS_ENABLED, Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH, 0, $attribute->getId(), 'magento_image.jpg', 'Image Label', '1', '0')) . "\n"; $data = 'data://text/plain;base64,' . base64_encode($data); $fixture = new Mage_ImportExport_Model_Import_Source_Csv($data); foreach (new Mage_Catalog_Model_Resource_Product_Collection() as $product) { $this->fail("Unexpected precondition - product exists: '{$product->getId()}'."); } $this->_model->setSource($fixture)->setParameters(array('behavior' => Mage_ImportExport_Model_Import::BEHAVIOR_APPEND))->isDataValid(); $this->_model->importData(); $resource = new Mage_Catalog_Model_Resource_Product(); $productId = $resource->getIdBySku('test_sku'); // fixture $product = Mage::getModel('Mage_Catalog_Model_Product'); $product->load($productId); $gallery = $product->getMediaGalleryImages(); $this->assertInstanceOf('Varien_Data_Collection', $gallery); $items = $gallery->getItems(); $this->assertCount(1, $items); $item = array_pop($items); $this->assertInstanceOf('Varien_Object', $item); $this->assertEquals('/m/a/magento_image.jpg', $item->getFile()); $this->assertEquals('Image Label', $item->getLabel()); }