/** * @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()); }
/** * Tests adding of custom options with different behaviours * * @param $behavior * * @magentoDataFixture Mage/Catalog/_files/product_simple.php * @dataProvider getBehaviorDataProvider * @covers Mage_ImportExport_Model_Import_Entity_Product::_saveCustomOptions */ public function testSaveCustomOptionsDuplicate($behavior) { // import data from CSV file $pathToFile = __DIR__ . '/_files/product_with_custom_options.csv'; $source = new Mage_ImportExport_Model_Import_Adapter_Csv($pathToFile); $this->_model->setSource($source)->setParameters(array('behavior' => $behavior))->isDataValid(); $this->_model->importData(); $product = new Mage_Catalog_Model_Product(); $product->load(1); // product from fixture $options = $product->getProductOptionsCollection(); $expectedData = $this->_getExpectedOptionsData($pathToFile); $expectedData = $this->_mergeWithExistingData($expectedData, $options); $actualData = $this->_getActualOptionsData($options); // assert of equal type+titles $expectedOptions = $expectedData['options']; // we need to save key values $actualOptions = $actualData['options']; sort($expectedOptions); sort($actualOptions); $this->assertEquals($expectedOptions, $actualOptions); // assert of options data $this->assertCount(count($expectedData['data']), $actualData['data']); $this->assertCount(count($expectedData['values']), $actualData['values']); foreach ($expectedData['options'] as $expectedId => $expectedOption) { $elementExist = false; // find value in actual options and values foreach ($actualData['options'] as $actualId => $actualOption) { if ($actualOption == $expectedOption) { $elementExist = true; $this->assertEquals($expectedData['data'][$expectedId], $actualData['data'][$actualId]); if (array_key_exists($expectedId, $expectedData['values'])) { $this->assertEquals($expectedData['values'][$expectedId], $actualData['values'][$actualId]); } unset($actualData['options'][$actualId]); // remove value in case of duplicating key values break; } } $this->assertTrue($elementExist, 'Element must exist.'); } }