diff --git a/Test/Integration/DataProviders/ProductTest.php b/Test/Integration/DataProviders/ProductTest.php index 443df9c..3c534bc 100644 --- a/Test/Integration/DataProviders/ProductTest.php +++ b/Test/Integration/DataProviders/ProductTest.php @@ -68,7 +68,7 @@ private function itReturnsDefaultTags() $this->assertEquals('Product without og tags', $tags['og:title']); $this->assertEquals('Description', $tags['og:description']); - $this->assertContains('image.png', $tags['og:image']); + $this->assertContains('magento_image.jpg', $tags['og:image']); $this->assertEquals('product', $tags['og:type']); } diff --git a/Test/Integration/_files/og_image.png b/Test/Integration/_files/og_image.png new file mode 100644 index 0000000..0816984 Binary files /dev/null and b/Test/Integration/_files/og_image.png differ diff --git a/Test/Integration/_files/product_image.php b/Test/Integration/_files/product_image.php new file mode 100644 index 0000000..30fcda8 --- /dev/null +++ b/Test/Integration/_files/product_image.php @@ -0,0 +1,29 @@ +get(\Magento\Catalog\Model\Product\Media\Config::class); + +/** @var $mediaDirectory \Magento\Framework\Filesystem\Directory\WriteInterface */ +$mediaDirectory = $objectManager->get(\Magento\Framework\Filesystem::class) + ->getDirectoryWrite(DirectoryList::MEDIA); + +$images = [ + 'magento_image.jpg', + 'og_image.png' +]; + +foreach($images as $fileName) { + $targetDirPath = $mediaConfig->getBaseMediaPath() . str_replace('/', DIRECTORY_SEPARATOR, '/'.$fileName[0].'/'.$fileName[1].'/'); + $targetTmpDirPath = $mediaConfig->getBaseTmpMediaPath() . str_replace('/', DIRECTORY_SEPARATOR, '/'.$fileName[0].'/'.$fileName[1].'/'); + + $mediaDirectory->create($targetDirPath); + $mediaDirectory->create($targetTmpDirPath); + + $targetTmpFilePath = $mediaDirectory->getAbsolutePath() . DIRECTORY_SEPARATOR . $targetTmpDirPath + . DIRECTORY_SEPARATOR . $fileName; + + copy(__DIR__ . '/' . $fileName, $targetTmpFilePath); +} diff --git a/Test/Integration/_files/product_image_rollback.php b/Test/Integration/_files/product_image_rollback.php new file mode 100644 index 0000000..d8ab2e5 --- /dev/null +++ b/Test/Integration/_files/product_image_rollback.php @@ -0,0 +1,18 @@ +get( + \Magento\Catalog\Model\Product\Media\Config::class +); + +/** @var \Magento\Framework\Filesystem\Directory\WriteInterface $mediaDirectory */ +$mediaDirectory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( + \Magento\Framework\Filesystem::class +)->getDirectoryWrite( + DirectoryList::MEDIA +); + +$mediaDirectory->delete($config->getBaseMediaPath()); +$mediaDirectory->delete($config->getBaseTmpMediaPath()); diff --git a/Test/Integration/_files/products.php b/Test/Integration/_files/products.php index 1a16475..beff607 100644 --- a/Test/Integration/_files/products.php +++ b/Test/Integration/_files/products.php @@ -1,8 +1,10 @@ create('Magento\Catalog\Model\Product'); +$product = $objectManager->create(\Magento\Catalog\Model\Product::class); $product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE) ->setId(555) ->setAttributeSetId(4) @@ -15,12 +17,24 @@ ->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1]) ->setCanSaveCustomOptions(true) ->setDescription('

Description

') - ->setImage('image.png') + ->setImage('/m/a/magento_image.jpg') + ->setSmallImage('/m/a/magento_image.jpg') + ->setThumbnail('/m/a/magento_image.jpg') + ->setData('media_gallery', ['images' => [ + [ + 'file' => '/m/a/magento_image.jpg', + 'position' => 1, + 'label' => 'Image Alt Text', + 'disabled' => 0, + 'media_type' => 'image' + ], + ]]) ->save(); + $product->reindex(); $product->priceReindexCallback(); -$product = $objectManager->create('Magento\Catalog\Model\Product'); +$product = $objectManager->create(\Magento\Catalog\Model\Product::class); $product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE) ->setId(556) ->setAttributeSetId(4) @@ -34,11 +48,20 @@ ->setCanSaveCustomOptions(true) ->setMetaTitle('Meta Title') ->setDescription('

Description

') - ->setImage('image.png') + ->setData('media_gallery', ['images' => [ + [ + 'file' => '/o/g/og_image.png', + 'position' => 1, + 'label' => 'Image Alt Text', + 'disabled' => 0, + 'media_type' => 'image' + ], + ]]) ->setOgTitle('Og Title') ->setOgDescription('Og Description') - ->setOgImage('og_image.png') + ->setOgImage('/o/g/og_image.png') ->setOgType('article') ->save(); + $product->reindex(); $product->priceReindexCallback(); \ No newline at end of file diff --git a/Test/Integration/_files/products_rollback.php b/Test/Integration/_files/products_rollback.php index 8ee7779..c9c57c9 100644 --- a/Test/Integration/_files/products_rollback.php +++ b/Test/Integration/_files/products_rollback.php @@ -1,5 +1,7 @@ get('Magento\Framework\Registry'); diff --git a/etc/module.xml b/etc/module.xml index bfdb3bd..80ca91f 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,5 +1,8 @@ + + + \ No newline at end of file