Skip to content

Commit

Permalink
Fixed tests by placing correctly image files in directories
Browse files Browse the repository at this point in the history
  • Loading branch information
diwipl committed Apr 17, 2019
1 parent 96acb78 commit 9b91fdb
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Test/Integration/DataProviders/ProductTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

Expand Down
Binary file added Test/Integration/_files/og_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions Test/Integration/_files/product_image.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

use Magento\Framework\App\Filesystem\DirectoryList;

$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var $mediaConfig \Magento\Catalog\Model\Product\Media\Config */
$mediaConfig = $objectManager->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);
}
18 changes: 18 additions & 0 deletions Test/Integration/_files/product_image_rollback.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

use Magento\Framework\App\Filesystem\DirectoryList;

/** @var $config \Magento\Catalog\Model\Product\Media\Config */
$config = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->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());
33 changes: 28 additions & 5 deletions Test/Integration/_files/products.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

require __DIR__ . '/product_image.php';

$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();

$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(555)
->setAttributeSetId(4)
Expand All @@ -15,12 +17,24 @@
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
->setCanSaveCustomOptions(true)
->setDescription('<p>Description</p>')
->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)
Expand All @@ -34,11 +48,20 @@
->setCanSaveCustomOptions(true)
->setMetaTitle('Meta Title')
->setDescription('<p>Description</p>')
->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();
2 changes: 2 additions & 0 deletions Test/Integration/_files/products_rollback.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

include __DIR__.'/product_image_rollback.php';

/** @var \Magento\Framework\Registry $registry */
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\Framework\Registry');

Expand Down
3 changes: 3 additions & 0 deletions etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="MageSuite_Opengraph" setup_version="1.0.4">
<sequence>
<module name="Magento_Catalog" />
</sequence>
</module>
</config>

0 comments on commit 9b91fdb

Please sign in to comment.