public function testAfterSaveDeleteFiles() { $storeId = 1; $storeIds = ['store_1' => 1, 'store_2' => 2]; $attributeCode = 'test_code'; $toDelete = [1]; $mediaPath = 'catalog/media'; $filePathToRemove = $mediaPath . '/file/path'; $attributeValue = ['images' => [['removed' => true, 'value_id' => 1, 'file' => 'file/path'], ['removed' => false, 'value_id' => 1, 'file' => 'file/path2']]]; $assignedImages = [['filepath' => 'path_to_image']]; $attributeMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute')->disableOriginalConstructor()->getMock(); $attributeMock->expects($this->once())->method('getAttributeCode')->will($this->returnValue($attributeCode)); $this->dataObject->expects($this->once())->method('getIsDuplicate')->will($this->returnValue(false)); $this->dataObject->expects($this->once())->method('isLockedAttribute')->will($this->returnValue(false)); $this->dataObject->setData($attributeCode, $attributeValue); $this->dataObject->setId(1); $this->dataObject->setStoreId($storeId); $this->dataObject->setStoreIds($storeIds); $productMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['getAssignedImages', '__wakeup'])->getMock(); $productMock->expects($this->any())->method('getAssignedImages')->will($this->returnValue($assignedImages)); $this->productFactory->expects($this->once())->method('create')->will($this->returnValue($productMock)); $this->resourceModel->expects($this->once())->method('deleteGallery')->with($toDelete); $this->mediaConfig->expects($this->once())->method('getBaseMediaPath')->will($this->returnValue($mediaPath)); $this->mediaDirectory->expects($this->once())->method('delete')->with($filePathToRemove); $this->model->setAttribute($attributeMock); $this->assertNull($this->model->afterSave($this->dataObject)); }
/** * {@inheritdoc} */ public function afterSave($object) { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'afterSave'); if (!$pluginInfo) { return parent::afterSave($object); } else { return $this->___callPlugins('afterSave', func_get_args(), $pluginInfo); } }
public function testAfterSaveAndAfterLoad() { $product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product'); $product->setId(1); $product->setData('media_gallery', ['images' => ['image' => ['file' => 'magento_image.jpg']]]); $this->_model->afterSave($product); $this->assertEmpty($product->getData('media_gallery/images/0/value_id')); $this->_model->afterLoad($product); $this->assertNotEmpty($product->getData('media_gallery/images/0/value_id')); }