Skip to content

Commit c30a05a

Browse files
authored
Merge pull request #1014 from magento-epam/PR-7
[Epam] Extend functional test sprint 7 - MTO-147: [Variation] Display images for a configurable product on store front - MTO-139: [Test] Price for configurable product
2 parents 45dce69 + c3c84dd commit c30a05a

File tree

19 files changed

+897
-23
lines changed

19 files changed

+897
-23
lines changed

dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/ProductForm.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ class ProductForm extends FormSections
7272
*/
7373
protected $newAttributeModal = '.product_form_product_form_add_attribute_modal_create_new_attribute_modal';
7474

75+
/**
76+
* Website checkbox xpath selector.
77+
*
78+
* @var string
79+
*/
80+
protected $websiteCheckbox = '//label[text()="%s"]/../input';
81+
7582
/**
7683
* Fill the product form.
7784
*
@@ -138,6 +145,17 @@ public function openSection($sectionName)
138145
return $this;
139146
}
140147

148+
/**
149+
* Unassign product from website by website name.
150+
*
151+
* @param string $name
152+
*/
153+
public function unassignFromWebsite($name)
154+
{
155+
$this->openSection('websites');
156+
$this->_rootElement->find(sprintf($this->websiteCheckbox, $name), Locator::SELECTOR_XPATH)->click();
157+
}
158+
141159
/**
142160
* Wait page to load.
143161
*

dev/tests/functional/tests/app/Magento/Catalog/Test/Page/Adminhtml/CatalogProductEdit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
<block name="addAttributeModal" class="Magento\Catalog\Test\Block\Adminhtml\Product\Modal\AddAttribute" locator=".product_form_product_form_add_attribute_modal" strategy="css selector"/>
1313
<block name="newAttributeModal" class="Magento\Catalog\Test\Block\Adminhtml\Product\Modal\NewAttribute" locator=".product_form_product_form_add_attribute_modal_create_new_attribute_modal" strategy="css selector"/>
1414
<block name="productForm" class="Magento\Catalog\Test\Block\Adminhtml\Product\ProductForm" locator="[id='page:main-container']" strategy="css selector"/>
15+
<block name="storeSwitcherBlock" class="Magento\Store\Test\Block\Switcher" locator=".store-switcher" strategy="css selector" />
1516
</page>
1617
</config>

dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/Product/CustomOptions.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,30 @@
592592
</field>
593593
</dataset>
594594

595+
<dataset name="two_fixed_drop_down_options">
596+
<field name="0" xsi:type="array">
597+
<item name="title" xsi:type="string">custom menu</item>
598+
<item name="is_require" xsi:type="string">No</item>
599+
<item name="type" xsi:type="string">Select/Drop-down</item>
600+
<item name="options" xsi:type="array">
601+
<item name="0" xsi:type="array">
602+
<item name="title" xsi:type="string">first</item>
603+
<item name="price" xsi:type="string">1</item>
604+
<item name="price_type" xsi:type="string">Fixed</item>
605+
<item name="sku" xsi:type="string">sku_radio_buttons_drop_down_1</item>
606+
<item name="sort_order" xsi:type="string">0</item>
607+
</item>
608+
<item name="1" xsi:type="array">
609+
<item name="title" xsi:type="string">second</item>
610+
<item name="price" xsi:type="string">2</item>
611+
<item name="price_type" xsi:type="string">Fixed</item>
612+
<item name="sku" xsi:type="string">sku_radio_buttons_drop_down_2</item>
613+
<item name="sort_order" xsi:type="string">0</item>
614+
</item>
615+
</item>
616+
</field>
617+
</dataset>
618+
595619
<dataset name="drop_down_with_three_options">
596620
<field name="0" xsi:type="array">
597621
<item name="title" xsi:type="string">custom option drop down %isolation%</item>

dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/Product/TierPrice.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,16 @@
101101
</item>
102102
</field>
103103
</dataset>
104+
105+
<dataset name="custom_for_qty_1">
106+
<field name="0" xsi:type="array">
107+
<item name="price" xsi:type="string">5</item>
108+
<item name="website" xsi:type="string">All Websites [USD]</item>
109+
<item name="price_qty" xsi:type="string">1</item>
110+
<item name="customer_group" xsi:type="array">
111+
<item name="dataset" xsi:type="string">ALL_GROUPS</item>
112+
</item>
113+
</field>
114+
</dataset>
104115
</repository>
105116
</config>
Loading

dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Block/Adminhtml/Product/Edit/Section/Variations/Config.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,16 @@ public function setFieldsData(array $fields, SimpleElement $element = null)
8484
? $fields['configurable_attributes_data']['value']
8585
: [];
8686

87-
$attributesValue = isset($fields['configurable_attributes_data']['source'])
88-
? $fields['configurable_attributes_data']['source']->getAttributesData()
89-
: [];
87+
$attributeSource = isset($fields['configurable_attributes_data']['source'])
88+
? $fields['configurable_attributes_data']['source']
89+
: null;
90+
$attributesValue = $attributeSource !== null ? $attributeSource->getAttributesData() : [];
91+
9092
foreach ($attributesValue as $key => $value) {
9193
$attributesValue[$key] = array_merge($value, $attributes['attributes_data'][$key]);
9294
}
9395
$this->createConfigurations();
94-
$this->getAttributeBlock()->fillAttributes($attributesValue);
96+
$this->getAttributeBlock()->fillAttributes($attributesValue, $attributeSource);
9597
if (!empty($attributes['matrix'])) {
9698
$this->generateVariations();
9799
$this->getVariationsBlock()->fillVariations($attributes['matrix']);

dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Block/Adminhtml/Product/Edit/Section/Variations/Config/Attribute.php

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\ConfigurableProduct\Test\Block\Adminhtml\Product\Edit\Section\Variations\Config;
88

99
use Magento\ConfigurableProduct\Test\Block\Adminhtml\Product\Edit\Section\Variations\Config\Attribute\AttributeSelector;
10+
use Magento\ConfigurableProduct\Test\Fixture\ConfigurableProduct\ConfigurableAttributesData;
1011
use Magento\Mtf\Block\Form;
1112
use Magento\Mtf\Client\Element\SimpleElement;
1213
use Magento\Mtf\Client\Locator;
@@ -159,13 +160,21 @@ class Attribute extends Form
159160
*/
160161
private $selectedAttributes = 'span[data-bind*="selectedAttributes"]';
161162

163+
/**
164+
* Wizard Images step CSS selector.
165+
*
166+
* @var string
167+
*/
168+
private $wizardImagesStep = '#variation-steps-wizard_step3';
169+
162170
/**
163171
* Fill attributes
164172
*
165173
* @param array $attributes
174+
* @param ConfigurableAttributesData $attributeSource
166175
* @return void
167176
*/
168-
public function fillAttributes(array $attributes)
177+
public function fillAttributes(array $attributes, ConfigurableAttributesData $attributeSource)
169178
{
170179
$attributesFilters = [];
171180
foreach ($attributes as $attribute) {
@@ -197,6 +206,7 @@ public function fillAttributes(array $attributes)
197206
}
198207

199208
$this->browser->find($this->nextButton)->click();
209+
$this->fillBulkImagesPriceAndQuantity($attributeSource, $attributes);
200210
$this->getTemplateBlock()->waitLoader();
201211
$this->browser->find($this->nextButton)->click();
202212
}
@@ -469,4 +479,47 @@ protected function getTemplateBlock()
469479
['element' => $this->_rootElement->find($this->templateBlock, Locator::SELECTOR_XPATH)]
470480
);
471481
}
482+
483+
/**
484+
* Fill Step 3: Bulk Images, Price and Quantity.
485+
*
486+
* @param ConfigurableAttributesData $attributeSource
487+
* @param array $attributes
488+
* @return void
489+
*/
490+
private function fillBulkImagesPriceAndQuantity(ConfigurableAttributesData $attributeSource, array $attributes)
491+
{
492+
if (empty($attributeSource->getBulkImagesPriceQuantity())) {
493+
return;
494+
}
495+
496+
$wizardStep = $this->browser->find($this->wizardImagesStep);
497+
$data = $this->prepareImageStepData($attributeSource->getBulkImagesPriceQuantity(), $attributes);
498+
$mapping = $this->dataMapping($data);
499+
$this->_fill($mapping, $wizardStep);
500+
}
501+
502+
/**
503+
* Prepare data for Step 3: Bulk Images, Price and Quantity.
504+
*
505+
* @param array $data
506+
* @param array $attributes
507+
* @return array
508+
*/
509+
private function prepareImageStepData(array $data, array $attributes)
510+
{
511+
if (isset($data['images'])) {
512+
$data['images']['image_attribute'] = $attributes['attribute_key_0']['attribute_code'];
513+
$data['images']['black_option_image'] = MTF_TESTS_PATH . array_shift($data['images']['images']);
514+
$data['images']['white_option_image'] = MTF_TESTS_PATH . array_shift($data['images']['images']);
515+
unset($data['images']['images']);
516+
}
517+
518+
if (isset($data['price'])) {
519+
$data['price']['price_option'] = $attributes['attribute_key_1']['attribute_code'];
520+
ksort($data['price']);
521+
}
522+
523+
return $data;
524+
}
472525
}

dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Block/Adminhtml/Product/Edit/Section/Variations/Config/Attribute.xml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,61 @@
1010
<label>
1111
<selector>[name=label]</selector>
1212
</label>
13+
<images composite="1">
14+
<image_unique>
15+
<selector>#apply-unique-images-radio</selector>
16+
<strategy>css selector</strategy>
17+
<input>radiobutton</input>
18+
</image_unique>
19+
<image_attribute>
20+
<selector>#apply-images-attributes</selector>
21+
<strategy>css selector</strategy>
22+
<input>select</input>
23+
</image_attribute>
24+
<black_option_image>
25+
<selector>//input[@name="image" and not(@id) and not(@class)]</selector>
26+
<strategy>xpath</strategy>
27+
<input>upload</input>
28+
</black_option_image>
29+
<white_option_image>
30+
<selector>//input[@name="image" and not(@id) and not(@class)]</selector>
31+
<strategy>xpath</strategy>
32+
<input>upload</input>
33+
</white_option_image>
34+
</images>
35+
<price composite="1">
36+
<price_attribute_unique>
37+
<selector>#apply-unique-prices-radio</selector>
38+
<strategy>css selector</strategy>
39+
<input>radiobutton</input>
40+
</price_attribute_unique>
41+
<price_option>
42+
<selector>#select-each-price</selector>
43+
<strategy>css selector</strategy>
44+
<input>select</input>
45+
</price_option>
46+
<xl_size_price>
47+
<selector>#apply-single-price-input-0</selector>
48+
<strategy>css selector</strategy>
49+
<input>input</input>
50+
</xl_size_price>
51+
<xxl_size_price>
52+
<selector>#apply-single-price-input-1</selector>
53+
<strategy>css selector</strategy>
54+
<input>input</input>
55+
</xxl_size_price>
56+
</price>
57+
<quantity composite="1">
58+
<quantity_single>
59+
<selector>#apply-single-inventory-radio</selector>
60+
<strategy>css selector</strategy>
61+
<input>radiobutton</input>
62+
</quantity_single>
63+
<quantity>
64+
<selector>#apply-single-inventory-input</selector>
65+
<strategy>css selector</strategy>
66+
<input>input</input>
67+
</quantity>
68+
</quantity>
1369
</fields>
1470
</mapping>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\ConfigurableProduct\Test\Constraint;
8+
9+
use Magento\Catalog\Test\Constraint\AssertProductPage;
10+
11+
/**
12+
* Verify displayed images on product page are correct.
13+
*/
14+
class AssertConfigurableProductImages extends AssertProductPage
15+
{
16+
/**
17+
* Displayed images.
18+
*
19+
* @var array
20+
*/
21+
private $displayedImages = [];
22+
23+
/**
24+
* Verify displayed images on product page are correct.
25+
*
26+
* @return array
27+
*/
28+
protected function verify()
29+
{
30+
$errors = [];
31+
$errors[] = $this->verifyBaseImage();
32+
$errors[] = $this->verifyOptionsImages();
33+
34+
return array_filter($errors);
35+
}
36+
37+
/**
38+
* Verify correct base image is shown.
39+
*
40+
* @return null|string
41+
*/
42+
private function verifyBaseImage()
43+
{
44+
$message = null;
45+
$data = $this->product->getData();
46+
47+
$displayedImage = $this->productView->getBaseImageSource();
48+
$this->displayedImages[] = $displayedImage;
49+
50+
if ($this->areImagesDifferent($displayedImage, $data['image'][0]['file'])) {
51+
$message = 'Product image is not correct.';
52+
}
53+
54+
return $message;
55+
}
56+
57+
/**
58+
* Verify displayed options images on product page are different.
59+
*
60+
* @return string|null
61+
*/
62+
protected function verifyOptionsImages()
63+
{
64+
$message = null;
65+
$configurableAttributes = $this->product->getData('configurable_attributes_data')['attributes_data'];
66+
$attribute = array_shift($configurableAttributes);
67+
$customOptions = [];
68+
69+
foreach ($attribute['options'] as $option) {
70+
$customOptions[] = [
71+
'type' => $attribute['frontend_input'],
72+
'title' => $attribute['frontend_label'],
73+
'value' => $option['label']
74+
];
75+
}
76+
77+
foreach ($customOptions as $customOption) {
78+
$this->productView->getCustomOptionsBlock()->fillCustomOptions([$customOption]);
79+
$displayedImage = $this->productView->getBaseImageSource();
80+
if (in_array($displayedImage, $this->displayedImages)) {
81+
$message = 'Option image is not correct.';
82+
break;
83+
}
84+
85+
$this->displayedImages[] = $displayedImage;
86+
}
87+
88+
return $message;
89+
}
90+
91+
/**
92+
* Compare images and return true if they are different.
93+
*
94+
* @param string $compared
95+
* @param string $toCompare
96+
* @return bool
97+
*/
98+
private function areImagesDifferent($compared, $toCompare)
99+
{
100+
preg_match('`/(\w*?)\.(\w*?)$`', $compared, $shownImage);
101+
preg_match('`/(\w*?)\.(\w*?)$`', $toCompare, $expectedImage);
102+
103+
return strpos($shownImage[1], $expectedImage[1]) === false || $expectedImage[2] !== $shownImage[2];
104+
}
105+
}

dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Fixture/ConfigurableProduct.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<field name="gallery" is_required="0" />
3838
<field name="gift_message_available" is_required="0" />
3939
<field name="has_options" is_required="0" />
40-
<field name="image" is_required="0" />
40+
<field name="image" is_required="0" group="gallery" source="Magento\Catalog\Test\Fixture\Product\Image" />
4141
<field name="image_label" is_required="0" />
4242
<field name="manufacturer" is_required="0" />
4343
<field name="media_gallery" is_required="0" />

0 commit comments

Comments
 (0)