Skip to content

Commit

Permalink
Merge pull request #988 from magento-epam/PR-6
Browse files Browse the repository at this point in the history
[Epam] Extend functional test sprint 6

- MTO-128: [Test] Export Products
- MTO-105: [Test] Import Products
- MTO-148: [Constraint] Messages in Sales Reports Pages display correct date/time
  • Loading branch information
okolesnyk committed Apr 6, 2017
2 parents 3c8619d + b9956b9 commit 59e8864
Show file tree
Hide file tree
Showing 49 changed files with 2,177 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ class Bundle extends Section
*/
protected $deleteOption = './tr[%d]//*[@data-index="delete_button"]';

/**
* Selector for attribute sku.
*
* @var string
*/
private $attributeSku = 'span[data-index="sku"]';

/**
* Get bundle options block.
*
Expand Down Expand Up @@ -166,4 +173,14 @@ public function getFieldsData($fields = null, SimpleElement $element = null)

return $newFields;
}

/**
* Get attribute sku.
*
* @return string
*/
public function getAttributeSku()
{
return $this->_rootElement->find($this->attributeSku)->getText();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
<field name="visibility" is_required="0" group="product-details" />
<field name="id" />
<field name="bundle_selections" is_required="1" group="bundle" source="Magento\Bundle\Test\Fixture\BundleProduct\BundleSelections" repository="Magento\Bundle\Test\Repository\BundleProduct\BundleSelection" />
<field name="attribute_set_id" group="product-details" source="Magento\Catalog\Test\Fixture\Product\AttributeSetId" />
<field name="checkout_data" is_required="1" group="null" repository="Magento\Bundle\Test\Repository\BundleProduct\CheckoutData" />
<field name="custom_options" is_required="0" group="customer-options" source="Magento\Catalog\Test\Fixture\Product\CustomOptions" repository="Magento\Catalog\Test\Repository\Product\CustomOptions" />
<field name="type_id" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<field name="sku" xsi:type="string">sku_bundle_dynamic_product_%isolation%</field>
<field name="sku_type" xsi:type="string">Yes</field>
<field name="price_type" xsi:type="string">Yes</field>
<field name="shipment_type" xsi:type="string">Together</field>
<field name="quantity_and_stock_status" xsi:type="array">
<item name="is_in_stock" xsi:type="string">In Stock</item>
</field>
Expand Down Expand Up @@ -235,6 +236,37 @@
</field>
</dataset>

<dataset name="fixed_with_required_options_and_qty_and_textarea_attribute">
<field name="name" xsi:type="string">Bundle fixed product %isolation%</field>
<field name="url_key" xsi:type="string">bundle-fixed-product-%isolation%</field>
<field name="sku" xsi:type="string">sku_bundle_fixed_product_%isolation%</field>
<field name="sku_type" xsi:type="string">No</field>
<field name="price_type" xsi:type="string">No</field>
<field name="price" xsi:type="array">
<item name="value" xsi:type="string">100</item>
</field>
<field name="tax_class_id" xsi:type="array">
<item name="dataset" xsi:type="string">taxable_goods</item>
</field>
<field name="weight" xsi:type="string">1</field>
<field name="weight_type" xsi:type="string">No</field>
<field name="website_ids" xsi:type="array">
<item name="0" xsi:type="array">
<item name="dataset" xsi:type="string">default</item>
</item>
</field>
<field name="shipment_type" xsi:type="string">Separately</field>
<field name="bundle_selections" xsi:type="array">
<item name="dataset" xsi:type="string">required_three_fixed_options_with_qty</item>
</field>
<field name="attribute_set_id" xsi:type="array">
<item name="dataset" xsi:type="string">custom_attribute_set_with_textarea</item>
</field>
<field name="checkout_data" xsi:type="array">
<item name="dataset" xsi:type="string">bundle_required_three_fixed_options_with_qty</item>
</field>
</dataset>

<dataset name="bundle_fixed_100_dollar_product">
<field name="name" xsi:type="string">Bundle fixed product %isolation%</field>
<field name="sku" xsi:type="string">sku_bundle_fixed_product_%isolation%</field>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\BundleImportExport\Test\Constraint;

use Magento\CatalogImportExport\Test\Constraint\AssertImportedProducts;
use Magento\Mtf\Fixture\FixtureInterface;

/**
* Assert that products data from CSV import file and data from product edit page are correct and match.
*/
class AssertImportedBundleProducts extends AssertImportedProducts
{
/**
* Product type.
*
* @var string
*/
protected $productType = 'bundle';

/**
* Needed bundle product data.
*
* @var array
*/
protected $neededKeys = [
'sku',
'name',
'associated_skus',
'bundle_values',
'url_key',
];

/**
* Prepare bundle product data.
*
* @param FixtureInterface $product
* @return array
*/
protected function getDisplayedProductData(FixtureInterface $product)
{
$productData = $this->getDisplayedOnProductPageData($product);
$bundleSelection = $productData['bundle_selections'][0];
$assignedProduct = $bundleSelection['assigned_products'][0];

$form = $this->catalogProductEdit->getProductForm();
$form->openSection('bundle');
$attributeSku = $form->getSection('bundle')->getAttributeSku();

$productData['associated_skus'] = $attributeSku;
$productType = ($productData['price_type'] === 'Yes')
? 'dynamic'
: 'fixed';
$productData['bundle_values'] = 'name=' . $bundleSelection['title'] . ',type=select,required=1,sku='
. $attributeSku . ',price=0.0000,default=0,default_qty='
. $assignedProduct['selection_qty'] .'.0000,price_type=' . $productType;

return $this->getResultProductsData($productData);
}

/**
* Return string representation of object.
*
* @return string
*/
public function toString()
{
return 'Products data from CSV import file and data from product edit page are correct and match.';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\BundleImportExport\Test\Fixture\Import;

use Magento\Mtf\Fixture\FixtureInterface;
use Magento\Mtf\Fixture\FixtureFactory;

/**
* Bundle product class file.
*/
class File
{
/**
* Prepare bundle product data.
*
* @param FixtureInterface $product
* @param FixtureFactory $fixtureFactory
* @return array
*/
public function getData(FixtureInterface $product, FixtureFactory $fixtureFactory)
{
$newProduct = $fixtureFactory->createByCode('catalogProductSimple', ['dataset' => 'default']);
$newProduct->persist();
$newProductData = $newProduct->getData();
$productData = $product->getData();

$productData['bundle_attribute_sku'] = $newProductData['sku'];
$productData['bundle_attribute_name'] = $newProductData['name'];
$productData['bundle_attribute_url_key'] = $newProductData['url_key'];

return $productData;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd">
<testCase name="Magento\CatalogImportExport\Test\TestCase\ExportProductsTest" summary="Export products">
<variation name="ExportProductsTestVariation4" summary="Export bundle products" ticketId="MAGETWO-30602">
<data name="exportData" xsi:type="string">default</data>
<data name="products/0" xsi:type="array">
<item name="fixture" xsi:type="string">bundleProduct</item>
<item name="dataset" xsi:type="string">bundle_dynamic_product</item>
</data>
<data name="products/1" xsi:type="array">
<item name="fixture" xsi:type="string">bundleProduct</item>
<item name="dataset" xsi:type="string">bundle_fixed_product</item>
</data>
<data name="products/2" xsi:type="array">
<item name="fixture" xsi:type="string">bundleProduct</item>
<item name="dataset" xsi:type="string">fixed_with_required_options_and_qty_and_textarea_attribute</item>
</data>
<data name="exportedFields" xsi:type="array">
<item name="0" xsi:type="string">sku</item>
<item name="1" xsi:type="string">name</item>
<item name="2" xsi:type="string">weight</item>
<item name="3" xsi:type="string">visibility</item>
<item name="4" xsi:type="string">price</item>
<item name="5" xsi:type="string">url_key</item>
</data>
</variation>
</testCase>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd">
<testCase name="Magento\CatalogImportExport\Test\TestCase\ImportProductsTest" summary="Import Bundle Product with Replace Behavior">
<variation name="ImportProductVariation3" ticketId="MAGETWO-47720" summary="Import Bundle Product with Replace Behavior">
<data name="import/data/import_file/entities/3" xsi:type="string">bundleProduct::default_with_one_simple_product</data>
<constraint name="Magento\BundleImportExport\Test\Constraint\AssertImportedBundleProducts" />
</variation>
</testCase>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AttributeSetId extends DataSource
public function __construct(FixtureFactory $fixtureFactory, array $params, $data = [])
{
$this->params = $params;
if (isset($data['dataset'])) {
if (isset($data['dataset']) && $data['dataset'] !== 'Default') {
/** @var CatalogAttributeSet $attributeSet */
$attributeSet = $fixtureFactory->createByCode('catalogAttributeSet', ['dataset' => $data['dataset']]);
if (!$attributeSet->hasData('attribute_set_id')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ class Curl extends AbstractCurl implements CatalogProductSimpleInterface
*/
protected $fields;

/**
* Temporary media path.
*
* @var string
*/
protected $mediaPathTmp = '/pub/media/tmp/catalog/product/';

/**
* Product website.
*
Expand Down Expand Up @@ -288,6 +295,10 @@ public function prepareData(FixtureInterface $fixture)
$this->prepareCustomOptionsData();
$this->prepareAutosetting();
$this->prepareCustomAttributes();
if (isset($this->fields['product']['media_gallery'])) {
$this->fields['product']['media_gallery']
= $this->prepareMediaGallery($this->fields['product']['media_gallery']);
}

$this->fields['product'] = $this->replaceMappingData($this->fields['product']);
return $this->fields;
Expand Down Expand Up @@ -352,7 +363,20 @@ protected function prepareIsVirtual()
*/
protected function prepareAttributeSet()
{
if ($this->fixture->hasData('attribute_set_id')) {
if (
$this->fixture->hasData('attribute_set_id')
&& !empty($this->fixture->getDataFieldConfig('attribute_set_id')['source'])
&& $this->fixture->getDataFieldConfig('attribute_set_id')['source']->getAttributeSet()
) {
$this->fields['product']['attribute_set_id'] = $this->fixture
->getDataFieldConfig('attribute_set_id')['source']
->getAttributeSet()
->getAttributeSetId();
} else if (
$this->fixture->hasData('attribute_set_id')
&& !empty($this->fixture->getDataFieldConfig('attribute_set_id')['source'])
&& $this->fixture->getDataFieldConfig('attribute_set_id')['source']->getAttributeSet()
) {
$this->fields['product']['attribute_set_id'] = $this->fixture
->getDataFieldConfig('attribute_set_id')['source']
->getAttributeSet()
Expand Down Expand Up @@ -420,13 +444,14 @@ protected function prepareCategory()
protected function prepareWebsites()
{
if (!empty($this->fields['product']['website_ids'])) {
unset($this->fields['product']['website_ids']);
foreach ($this->fixture->getDataFieldConfig('website_ids')['source']->getWebsites() as $key => $website) {
$this->fields['product']['extension_attributes']['website_ids'][$key] = $website->getWebsiteId();
$this->fields['product']['website_ids'][$key] = $website->getWebsiteId();
}
} else {
$website = \Magento\Mtf\ObjectManagerFactory::getObjectManager()
->create(\Magento\Store\Test\Fixture\Website::class, ['dataset' => 'default']);
$this->fields['product']['extension_attributes']['website_ids'][] = $website->getWebsiteId();
$this->fields['product']['website_ids'][] = $website->getWebsiteId();
}
}

Expand Down Expand Up @@ -615,4 +640,49 @@ protected function prepareFpt()
unset($this->fields['product']['fpt']);
}
}

/**
* Create test image file.
*
* @param string $filename
* @return array
*/
protected function prepareMediaGallery($filename)
{
$filePath = $this->getFullPath($filename);

if (!file_exists($filePath)) {
$image = imagecreate(300, 200);
$colorYellow = imagecolorallocate($image, 255, 255, 0);
imagefilledrectangle($image, 50, 50, 250, 150, $colorYellow);
$directory = dirname($filePath);
if (!file_exists($directory)) {
mkdir($directory, 0777, true);
}
imagejpeg($image, $filePath);
imagedestroy($image);
}

return [
'images' => [
0 => [
'position' => 1,
'file' => $filename,
'disabled' => 0,
'label' => $filename,
],
],
];
}

/**
* Gets full path based on filename.
*
* @param string $filename
* @return string
*/
private function getFullPath($filename)
{
return BP . $this->mediaPathTmp . $filename;
}
}
Loading

0 comments on commit 59e8864

Please sign in to comment.