Skip to content

Commit 59e8864

Browse files
authored
Merge pull request #988 from magento-epam/PR-6
[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
2 parents 3c8619d + b9956b9 commit 59e8864

File tree

49 files changed

+2177
-33
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2177
-33
lines changed

dev/tests/functional/tests/app/Magento/Bundle/Test/Block/Adminhtml/Catalog/Product/Edit/Section/Bundle.php

+17
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ class Bundle extends Section
5959
*/
6060
protected $deleteOption = './tr[%d]//*[@data-index="delete_button"]';
6161

62+
/**
63+
* Selector for attribute sku.
64+
*
65+
* @var string
66+
*/
67+
private $attributeSku = 'span[data-index="sku"]';
68+
6269
/**
6370
* Get bundle options block.
6471
*
@@ -166,4 +173,14 @@ public function getFieldsData($fields = null, SimpleElement $element = null)
166173

167174
return $newFields;
168175
}
176+
177+
/**
178+
* Get attribute sku.
179+
*
180+
* @return string
181+
*/
182+
public function getAttributeSku()
183+
{
184+
return $this->_rootElement->find($this->attributeSku)->getText();
185+
}
169186
}

dev/tests/functional/tests/app/Magento/Bundle/Test/Fixture/BundleProduct.xml

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
<field name="visibility" is_required="0" group="product-details" />
8484
<field name="id" />
8585
<field name="bundle_selections" is_required="1" group="bundle" source="Magento\Bundle\Test\Fixture\BundleProduct\BundleSelections" repository="Magento\Bundle\Test\Repository\BundleProduct\BundleSelection" />
86+
<field name="attribute_set_id" group="product-details" source="Magento\Catalog\Test\Fixture\Product\AttributeSetId" />
8687
<field name="checkout_data" is_required="1" group="null" repository="Magento\Bundle\Test\Repository\BundleProduct\CheckoutData" />
8788
<field name="custom_options" is_required="0" group="customer-options" source="Magento\Catalog\Test\Fixture\Product\CustomOptions" repository="Magento\Catalog\Test\Repository\Product\CustomOptions" />
8889
<field name="type_id" />

dev/tests/functional/tests/app/Magento/Bundle/Test/Repository/BundleProduct.xml

+32
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
<field name="sku" xsi:type="string">sku_bundle_dynamic_product_%isolation%</field>
3636
<field name="sku_type" xsi:type="string">Yes</field>
3737
<field name="price_type" xsi:type="string">Yes</field>
38+
<field name="shipment_type" xsi:type="string">Together</field>
3839
<field name="quantity_and_stock_status" xsi:type="array">
3940
<item name="is_in_stock" xsi:type="string">In Stock</item>
4041
</field>
@@ -235,6 +236,37 @@
235236
</field>
236237
</dataset>
237238

239+
<dataset name="fixed_with_required_options_and_qty_and_textarea_attribute">
240+
<field name="name" xsi:type="string">Bundle fixed product %isolation%</field>
241+
<field name="url_key" xsi:type="string">bundle-fixed-product-%isolation%</field>
242+
<field name="sku" xsi:type="string">sku_bundle_fixed_product_%isolation%</field>
243+
<field name="sku_type" xsi:type="string">No</field>
244+
<field name="price_type" xsi:type="string">No</field>
245+
<field name="price" xsi:type="array">
246+
<item name="value" xsi:type="string">100</item>
247+
</field>
248+
<field name="tax_class_id" xsi:type="array">
249+
<item name="dataset" xsi:type="string">taxable_goods</item>
250+
</field>
251+
<field name="weight" xsi:type="string">1</field>
252+
<field name="weight_type" xsi:type="string">No</field>
253+
<field name="website_ids" xsi:type="array">
254+
<item name="0" xsi:type="array">
255+
<item name="dataset" xsi:type="string">default</item>
256+
</item>
257+
</field>
258+
<field name="shipment_type" xsi:type="string">Separately</field>
259+
<field name="bundle_selections" xsi:type="array">
260+
<item name="dataset" xsi:type="string">required_three_fixed_options_with_qty</item>
261+
</field>
262+
<field name="attribute_set_id" xsi:type="array">
263+
<item name="dataset" xsi:type="string">custom_attribute_set_with_textarea</item>
264+
</field>
265+
<field name="checkout_data" xsi:type="array">
266+
<item name="dataset" xsi:type="string">bundle_required_three_fixed_options_with_qty</item>
267+
</field>
268+
</dataset>
269+
238270
<dataset name="bundle_fixed_100_dollar_product">
239271
<field name="name" xsi:type="string">Bundle fixed product %isolation%</field>
240272
<field name="sku" xsi:type="string">sku_bundle_fixed_product_%isolation%</field>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\BundleImportExport\Test\Constraint;
8+
9+
use Magento\CatalogImportExport\Test\Constraint\AssertImportedProducts;
10+
use Magento\Mtf\Fixture\FixtureInterface;
11+
12+
/**
13+
* Assert that products data from CSV import file and data from product edit page are correct and match.
14+
*/
15+
class AssertImportedBundleProducts extends AssertImportedProducts
16+
{
17+
/**
18+
* Product type.
19+
*
20+
* @var string
21+
*/
22+
protected $productType = 'bundle';
23+
24+
/**
25+
* Needed bundle product data.
26+
*
27+
* @var array
28+
*/
29+
protected $neededKeys = [
30+
'sku',
31+
'name',
32+
'associated_skus',
33+
'bundle_values',
34+
'url_key',
35+
];
36+
37+
/**
38+
* Prepare bundle product data.
39+
*
40+
* @param FixtureInterface $product
41+
* @return array
42+
*/
43+
protected function getDisplayedProductData(FixtureInterface $product)
44+
{
45+
$productData = $this->getDisplayedOnProductPageData($product);
46+
$bundleSelection = $productData['bundle_selections'][0];
47+
$assignedProduct = $bundleSelection['assigned_products'][0];
48+
49+
$form = $this->catalogProductEdit->getProductForm();
50+
$form->openSection('bundle');
51+
$attributeSku = $form->getSection('bundle')->getAttributeSku();
52+
53+
$productData['associated_skus'] = $attributeSku;
54+
$productType = ($productData['price_type'] === 'Yes')
55+
? 'dynamic'
56+
: 'fixed';
57+
$productData['bundle_values'] = 'name=' . $bundleSelection['title'] . ',type=select,required=1,sku='
58+
. $attributeSku . ',price=0.0000,default=0,default_qty='
59+
. $assignedProduct['selection_qty'] .'.0000,price_type=' . $productType;
60+
61+
return $this->getResultProductsData($productData);
62+
}
63+
64+
/**
65+
* Return string representation of object.
66+
*
67+
* @return string
68+
*/
69+
public function toString()
70+
{
71+
return 'Products data from CSV import file and data from product edit page are correct and match.';
72+
}
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\BundleImportExport\Test\Fixture\Import;
7+
8+
use Magento\Mtf\Fixture\FixtureInterface;
9+
use Magento\Mtf\Fixture\FixtureFactory;
10+
11+
/**
12+
* Bundle product class file.
13+
*/
14+
class File
15+
{
16+
/**
17+
* Prepare bundle product data.
18+
*
19+
* @param FixtureInterface $product
20+
* @param FixtureFactory $fixtureFactory
21+
* @return array
22+
*/
23+
public function getData(FixtureInterface $product, FixtureFactory $fixtureFactory)
24+
{
25+
$newProduct = $fixtureFactory->createByCode('catalogProductSimple', ['dataset' => 'default']);
26+
$newProduct->persist();
27+
$newProductData = $newProduct->getData();
28+
$productData = $product->getData();
29+
30+
$productData['bundle_attribute_sku'] = $newProductData['sku'];
31+
$productData['bundle_attribute_name'] = $newProductData['name'];
32+
$productData['bundle_attribute_url_key'] = $newProductData['url_key'];
33+
34+
return $productData;
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd">
9+
<testCase name="Magento\CatalogImportExport\Test\TestCase\ExportProductsTest" summary="Export products">
10+
<variation name="ExportProductsTestVariation4" summary="Export bundle products" ticketId="MAGETWO-30602">
11+
<data name="exportData" xsi:type="string">default</data>
12+
<data name="products/0" xsi:type="array">
13+
<item name="fixture" xsi:type="string">bundleProduct</item>
14+
<item name="dataset" xsi:type="string">bundle_dynamic_product</item>
15+
</data>
16+
<data name="products/1" xsi:type="array">
17+
<item name="fixture" xsi:type="string">bundleProduct</item>
18+
<item name="dataset" xsi:type="string">bundle_fixed_product</item>
19+
</data>
20+
<data name="products/2" xsi:type="array">
21+
<item name="fixture" xsi:type="string">bundleProduct</item>
22+
<item name="dataset" xsi:type="string">fixed_with_required_options_and_qty_and_textarea_attribute</item>
23+
</data>
24+
<data name="exportedFields" xsi:type="array">
25+
<item name="0" xsi:type="string">sku</item>
26+
<item name="1" xsi:type="string">name</item>
27+
<item name="2" xsi:type="string">weight</item>
28+
<item name="3" xsi:type="string">visibility</item>
29+
<item name="4" xsi:type="string">price</item>
30+
<item name="5" xsi:type="string">url_key</item>
31+
</data>
32+
</variation>
33+
</testCase>
34+
</config>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd">
9+
<testCase name="Magento\CatalogImportExport\Test\TestCase\ImportProductsTest" summary="Import Bundle Product with Replace Behavior">
10+
<variation name="ImportProductVariation3" ticketId="MAGETWO-47720" summary="Import Bundle Product with Replace Behavior">
11+
<data name="import/data/import_file/entities/3" xsi:type="string">bundleProduct::default_with_one_simple_product</data>
12+
<constraint name="Magento\BundleImportExport\Test\Constraint\AssertImportedBundleProducts" />
13+
</variation>
14+
</testCase>
15+
</config>

dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Product/AttributeSetId.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class AttributeSetId extends DataSource
3535
public function __construct(FixtureFactory $fixtureFactory, array $params, $data = [])
3636
{
3737
$this->params = $params;
38-
if (isset($data['dataset'])) {
38+
if (isset($data['dataset']) && $data['dataset'] !== 'Default') {
3939
/** @var CatalogAttributeSet $attributeSet */
4040
$attributeSet = $fixtureFactory->createByCode('catalogAttributeSet', ['dataset' => $data['dataset']]);
4141
if (!$attributeSet->hasData('attribute_set_id')) {

dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductSimple/Curl.php

+73-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ class Curl extends AbstractCurl implements CatalogProductSimpleInterface
3131
*/
3232
protected $fields;
3333

34+
/**
35+
* Temporary media path.
36+
*
37+
* @var string
38+
*/
39+
protected $mediaPathTmp = '/pub/media/tmp/catalog/product/';
40+
3441
/**
3542
* Product website.
3643
*
@@ -288,6 +295,10 @@ public function prepareData(FixtureInterface $fixture)
288295
$this->prepareCustomOptionsData();
289296
$this->prepareAutosetting();
290297
$this->prepareCustomAttributes();
298+
if (isset($this->fields['product']['media_gallery'])) {
299+
$this->fields['product']['media_gallery']
300+
= $this->prepareMediaGallery($this->fields['product']['media_gallery']);
301+
}
291302

292303
$this->fields['product'] = $this->replaceMappingData($this->fields['product']);
293304
return $this->fields;
@@ -352,7 +363,20 @@ protected function prepareIsVirtual()
352363
*/
353364
protected function prepareAttributeSet()
354365
{
355-
if ($this->fixture->hasData('attribute_set_id')) {
366+
if (
367+
$this->fixture->hasData('attribute_set_id')
368+
&& !empty($this->fixture->getDataFieldConfig('attribute_set_id')['source'])
369+
&& $this->fixture->getDataFieldConfig('attribute_set_id')['source']->getAttributeSet()
370+
) {
371+
$this->fields['product']['attribute_set_id'] = $this->fixture
372+
->getDataFieldConfig('attribute_set_id')['source']
373+
->getAttributeSet()
374+
->getAttributeSetId();
375+
} else if (
376+
$this->fixture->hasData('attribute_set_id')
377+
&& !empty($this->fixture->getDataFieldConfig('attribute_set_id')['source'])
378+
&& $this->fixture->getDataFieldConfig('attribute_set_id')['source']->getAttributeSet()
379+
) {
356380
$this->fields['product']['attribute_set_id'] = $this->fixture
357381
->getDataFieldConfig('attribute_set_id')['source']
358382
->getAttributeSet()
@@ -420,13 +444,14 @@ protected function prepareCategory()
420444
protected function prepareWebsites()
421445
{
422446
if (!empty($this->fields['product']['website_ids'])) {
447+
unset($this->fields['product']['website_ids']);
423448
foreach ($this->fixture->getDataFieldConfig('website_ids')['source']->getWebsites() as $key => $website) {
424-
$this->fields['product']['extension_attributes']['website_ids'][$key] = $website->getWebsiteId();
449+
$this->fields['product']['website_ids'][$key] = $website->getWebsiteId();
425450
}
426451
} else {
427452
$website = \Magento\Mtf\ObjectManagerFactory::getObjectManager()
428453
->create(\Magento\Store\Test\Fixture\Website::class, ['dataset' => 'default']);
429-
$this->fields['product']['extension_attributes']['website_ids'][] = $website->getWebsiteId();
454+
$this->fields['product']['website_ids'][] = $website->getWebsiteId();
430455
}
431456
}
432457

@@ -615,4 +640,49 @@ protected function prepareFpt()
615640
unset($this->fields['product']['fpt']);
616641
}
617642
}
643+
644+
/**
645+
* Create test image file.
646+
*
647+
* @param string $filename
648+
* @return array
649+
*/
650+
protected function prepareMediaGallery($filename)
651+
{
652+
$filePath = $this->getFullPath($filename);
653+
654+
if (!file_exists($filePath)) {
655+
$image = imagecreate(300, 200);
656+
$colorYellow = imagecolorallocate($image, 255, 255, 0);
657+
imagefilledrectangle($image, 50, 50, 250, 150, $colorYellow);
658+
$directory = dirname($filePath);
659+
if (!file_exists($directory)) {
660+
mkdir($directory, 0777, true);
661+
}
662+
imagejpeg($image, $filePath);
663+
imagedestroy($image);
664+
}
665+
666+
return [
667+
'images' => [
668+
0 => [
669+
'position' => 1,
670+
'file' => $filename,
671+
'disabled' => 0,
672+
'label' => $filename,
673+
],
674+
],
675+
];
676+
}
677+
678+
/**
679+
* Gets full path based on filename.
680+
*
681+
* @param string $filename
682+
* @return string
683+
*/
684+
private function getFullPath($filename)
685+
{
686+
return BP . $this->mediaPathTmp . $filename;
687+
}
618688
}

0 commit comments

Comments
 (0)