/** * @param \Magento\Catalog\Model\Product\Gallery\CreateHandler $mediaGalleryCreateHandler * @param \Magento\Catalog\Model\Product $product * @return \Magento\Catalog\Model\Product */ public function afterExecute(\Magento\Catalog\Model\Product\Gallery\CreateHandler $mediaGalleryCreateHandler, \Magento\Catalog\Model\Product $product) { $mediaCollection = $this->getMediaEntriesDataCollection($product, $mediaGalleryCreateHandler->getAttribute()); if (!empty($mediaCollection)) { $videoDataCollection = $this->collectVideoData($mediaCollection); $this->saveVideoData($videoDataCollection, $product->getStoreId()); $this->saveAdditionalStoreData($videoDataCollection); } return $product; }
/** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testBeforeExecute() { $mediaData = ['images' => ['72mljfhmasfilp9cuq' => ['position' => '3', 'media_type' => 'external-video', 'file' => '/i/n/index111111.jpg', 'value_id' => '4', 'label' => '', 'disabled' => '0', 'removed' => '', 'video_provider' => 'youtube', 'video_url' => 'https://www.youtube.com/watch?v=abcdefghij', 'video_title' => 'Some second title', 'video_description' => 'Description second', 'video_metadata' => 'meta two', 'role' => ''], 'w596fi79hv1p6wj21u' => ['position' => '4', 'media_type' => 'external-video', 'video_provider' => '', 'file' => '/h/d/hd_image.jpg', 'value_id' => '7', 'label' => '', 'disabled' => '0', 'removed' => '', 'video_url' => '', 'video_title' => '', 'video_description' => '', 'video_metadata' => '', 'role' => ''], 'tcodwd7e0dirifr64j' => ['position' => '4', 'media_type' => 'external-video', 'video_provider' => '', 'file' => '/h/d/hd_image.jpg', 'value_id' => '', 'label' => '', 'disabled' => '0', 'removed' => '', 'video_url' => '', 'video_title' => '', 'video_description' => '', 'video_metadata' => '', 'role' => '', 'save_data_from' => '7', 'new_file' => '/i/n/index_4.jpg']]]; $this->product->expects($this->any())->method('getData')->with('media_gallery')->willReturn($mediaData); $this->product->expects($this->any())->method('getStoreId')->willReturn(0); $resourceEntryResult = [['value_id' => '4', 'store_id' => 1, 'video_provider_default' => 'youtube', 'video_url_default' => 'https://www.youtube.com/watch?v=abcdefghij', 'video_title_default' => 'Some first title', 'video_description_default' => 'Description first', 'video_metadata_default' => 'meta one', 'video_provider' => 'youtube', 'video_url' => 'https://www.youtube.com/watch?v=abcdefghij', 'video_title' => 'Some first title', 'video_description' => 'Description first', 'video_metadata' => 'meta one'], ['value_id' => '7', 'store_id' => 1, 'video_provider_default' => 'youtube', 'video_url_default' => 'https://www.youtube.com/watch?v=ab123456', 'video_title_default' => 'Some second title', 'video_description_default' => 'Description second', 'video_metadata_default' => 'meta two', 'video_provider' => 'youtube', 'video_url' => 'https://www.youtube.com/watch?v=ab123456', 'video_title' => 'Some second title', 'video_description' => 'Description second', 'video_metadata' => '']]; $this->resourceModel->expects($this->once())->method('loadDataFromTableByValueId')->willReturn($resourceEntryResult); $this->mediaGalleryCreateHandler->expects($this->any())->method('getAttribute')->willReturn($this->attribute); $this->subject->beforeExecute($this->mediaGalleryCreateHandler, 'Magento\\Catalog\\Api\\Data\\ProductInterface', $this->product); }
/** * @covers \Magento\Catalog\Model\Product\Gallery\CreateHandler::execute */ public function testExecute() { $fileName = '/m/a/magento_image.jpg'; $fileLabel = 'Magento image'; /** @var $product \Magento\Catalog\Model\Product */ $product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product'); $product->load(1); $product->setData('media_gallery', ['images' => ['image' => ['file' => $fileName, 'label' => $fileLabel]]]); $product->setData('image', $fileName); $this->createHandler->execute($product); $this->assertStringStartsWith('/m/a/magento_image', $product->getData('media_gallery/images/image/new_file')); $this->assertEquals($fileLabel, $product->getData('image_label')); $product->setIsDuplicate(true); $product->setData('media_gallery', ['images' => ['image' => ['value_id' => '100', 'file' => $fileName, 'label' => $fileLabel]]]); $this->createHandler->execute($product); $this->assertStringStartsWith('/m/a/magento_image', $product->getData('media_gallery/duplicate/100')); $this->assertEquals($fileLabel, $product->getData('image_label')); }