Skip to content

Commit

Permalink
Merge pull request #1014 from magento-epam/PR-7
Browse files Browse the repository at this point in the history
[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
  • Loading branch information
okolesnyk authored Apr 18, 2017
2 parents 45dce69 + c3c84dd commit c30a05a
Show file tree
Hide file tree
Showing 19 changed files with 897 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ class ProductForm extends FormSections
*/
protected $newAttributeModal = '.product_form_product_form_add_attribute_modal_create_new_attribute_modal';

/**
* Website checkbox xpath selector.
*
* @var string
*/
protected $websiteCheckbox = '//label[text()="%s"]/../input';

/**
* Fill the product form.
*
Expand Down Expand Up @@ -138,6 +145,17 @@ public function openSection($sectionName)
return $this;
}

/**
* Unassign product from website by website name.
*
* @param string $name
*/
public function unassignFromWebsite($name)
{
$this->openSection('websites');
$this->_rootElement->find(sprintf($this->websiteCheckbox, $name), Locator::SELECTOR_XPATH)->click();
}

/**
* Wait page to load.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
<block name="addAttributeModal" class="Magento\Catalog\Test\Block\Adminhtml\Product\Modal\AddAttribute" locator=".product_form_product_form_add_attribute_modal" strategy="css selector"/>
<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"/>
<block name="productForm" class="Magento\Catalog\Test\Block\Adminhtml\Product\ProductForm" locator="[id='page:main-container']" strategy="css selector"/>
<block name="storeSwitcherBlock" class="Magento\Store\Test\Block\Switcher" locator=".store-switcher" strategy="css selector" />
</page>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,30 @@
</field>
</dataset>

<dataset name="two_fixed_drop_down_options">
<field name="0" xsi:type="array">
<item name="title" xsi:type="string">custom menu</item>
<item name="is_require" xsi:type="string">No</item>
<item name="type" xsi:type="string">Select/Drop-down</item>
<item name="options" xsi:type="array">
<item name="0" xsi:type="array">
<item name="title" xsi:type="string">first</item>
<item name="price" xsi:type="string">1</item>
<item name="price_type" xsi:type="string">Fixed</item>
<item name="sku" xsi:type="string">sku_radio_buttons_drop_down_1</item>
<item name="sort_order" xsi:type="string">0</item>
</item>
<item name="1" xsi:type="array">
<item name="title" xsi:type="string">second</item>
<item name="price" xsi:type="string">2</item>
<item name="price_type" xsi:type="string">Fixed</item>
<item name="sku" xsi:type="string">sku_radio_buttons_drop_down_2</item>
<item name="sort_order" xsi:type="string">0</item>
</item>
</item>
</field>
</dataset>

<dataset name="drop_down_with_three_options">
<field name="0" xsi:type="array">
<item name="title" xsi:type="string">custom option drop down %isolation%</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,16 @@
</item>
</field>
</dataset>

<dataset name="custom_for_qty_1">
<field name="0" xsi:type="array">
<item name="price" xsi:type="string">5</item>
<item name="website" xsi:type="string">All Websites [USD]</item>
<item name="price_qty" xsi:type="string">1</item>
<item name="customer_group" xsi:type="array">
<item name="dataset" xsi:type="string">ALL_GROUPS</item>
</item>
</field>
</dataset>
</repository>
</config>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,16 @@ public function setFieldsData(array $fields, SimpleElement $element = null)
? $fields['configurable_attributes_data']['value']
: [];

$attributesValue = isset($fields['configurable_attributes_data']['source'])
? $fields['configurable_attributes_data']['source']->getAttributesData()
: [];
$attributeSource = isset($fields['configurable_attributes_data']['source'])
? $fields['configurable_attributes_data']['source']
: null;
$attributesValue = $attributeSource !== null ? $attributeSource->getAttributesData() : [];

foreach ($attributesValue as $key => $value) {
$attributesValue[$key] = array_merge($value, $attributes['attributes_data'][$key]);
}
$this->createConfigurations();
$this->getAttributeBlock()->fillAttributes($attributesValue);
$this->getAttributeBlock()->fillAttributes($attributesValue, $attributeSource);
if (!empty($attributes['matrix'])) {
$this->generateVariations();
$this->getVariationsBlock()->fillVariations($attributes['matrix']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace Magento\ConfigurableProduct\Test\Block\Adminhtml\Product\Edit\Section\Variations\Config;

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

/**
* Wizard Images step CSS selector.
*
* @var string
*/
private $wizardImagesStep = '#variation-steps-wizard_step3';

/**
* Fill attributes
*
* @param array $attributes
* @param ConfigurableAttributesData $attributeSource
* @return void
*/
public function fillAttributes(array $attributes)
public function fillAttributes(array $attributes, ConfigurableAttributesData $attributeSource)
{
$attributesFilters = [];
foreach ($attributes as $attribute) {
Expand Down Expand Up @@ -197,6 +206,7 @@ public function fillAttributes(array $attributes)
}

$this->browser->find($this->nextButton)->click();
$this->fillBulkImagesPriceAndQuantity($attributeSource, $attributes);
$this->getTemplateBlock()->waitLoader();
$this->browser->find($this->nextButton)->click();
}
Expand Down Expand Up @@ -469,4 +479,47 @@ protected function getTemplateBlock()
['element' => $this->_rootElement->find($this->templateBlock, Locator::SELECTOR_XPATH)]
);
}

/**
* Fill Step 3: Bulk Images, Price and Quantity.
*
* @param ConfigurableAttributesData $attributeSource
* @param array $attributes
* @return void
*/
private function fillBulkImagesPriceAndQuantity(ConfigurableAttributesData $attributeSource, array $attributes)
{
if (empty($attributeSource->getBulkImagesPriceQuantity())) {
return;
}

$wizardStep = $this->browser->find($this->wizardImagesStep);
$data = $this->prepareImageStepData($attributeSource->getBulkImagesPriceQuantity(), $attributes);
$mapping = $this->dataMapping($data);
$this->_fill($mapping, $wizardStep);
}

/**
* Prepare data for Step 3: Bulk Images, Price and Quantity.
*
* @param array $data
* @param array $attributes
* @return array
*/
private function prepareImageStepData(array $data, array $attributes)
{
if (isset($data['images'])) {
$data['images']['image_attribute'] = $attributes['attribute_key_0']['attribute_code'];
$data['images']['black_option_image'] = MTF_TESTS_PATH . array_shift($data['images']['images']);
$data['images']['white_option_image'] = MTF_TESTS_PATH . array_shift($data['images']['images']);
unset($data['images']['images']);
}

if (isset($data['price'])) {
$data['price']['price_option'] = $attributes['attribute_key_1']['attribute_code'];
ksort($data['price']);
}

return $data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,61 @@
<label>
<selector>[name=label]</selector>
</label>
<images composite="1">
<image_unique>
<selector>#apply-unique-images-radio</selector>
<strategy>css selector</strategy>
<input>radiobutton</input>
</image_unique>
<image_attribute>
<selector>#apply-images-attributes</selector>
<strategy>css selector</strategy>
<input>select</input>
</image_attribute>
<black_option_image>
<selector>//input[@name="image" and not(@id) and not(@class)]</selector>
<strategy>xpath</strategy>
<input>upload</input>
</black_option_image>
<white_option_image>
<selector>//input[@name="image" and not(@id) and not(@class)]</selector>
<strategy>xpath</strategy>
<input>upload</input>
</white_option_image>
</images>
<price composite="1">
<price_attribute_unique>
<selector>#apply-unique-prices-radio</selector>
<strategy>css selector</strategy>
<input>radiobutton</input>
</price_attribute_unique>
<price_option>
<selector>#select-each-price</selector>
<strategy>css selector</strategy>
<input>select</input>
</price_option>
<xl_size_price>
<selector>#apply-single-price-input-0</selector>
<strategy>css selector</strategy>
<input>input</input>
</xl_size_price>
<xxl_size_price>
<selector>#apply-single-price-input-1</selector>
<strategy>css selector</strategy>
<input>input</input>
</xxl_size_price>
</price>
<quantity composite="1">
<quantity_single>
<selector>#apply-single-inventory-radio</selector>
<strategy>css selector</strategy>
<input>radiobutton</input>
</quantity_single>
<quantity>
<selector>#apply-single-inventory-input</selector>
<strategy>css selector</strategy>
<input>input</input>
</quantity>
</quantity>
</fields>
</mapping>
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\ConfigurableProduct\Test\Constraint;

use Magento\Catalog\Test\Constraint\AssertProductPage;

/**
* Verify displayed images on product page are correct.
*/
class AssertConfigurableProductImages extends AssertProductPage
{
/**
* Displayed images.
*
* @var array
*/
private $displayedImages = [];

/**
* Verify displayed images on product page are correct.
*
* @return array
*/
protected function verify()
{
$errors = [];
$errors[] = $this->verifyBaseImage();
$errors[] = $this->verifyOptionsImages();

return array_filter($errors);
}

/**
* Verify correct base image is shown.
*
* @return null|string
*/
private function verifyBaseImage()
{
$message = null;
$data = $this->product->getData();

$displayedImage = $this->productView->getBaseImageSource();
$this->displayedImages[] = $displayedImage;

if ($this->areImagesDifferent($displayedImage, $data['image'][0]['file'])) {
$message = 'Product image is not correct.';
}

return $message;
}

/**
* Verify displayed options images on product page are different.
*
* @return string|null
*/
protected function verifyOptionsImages()
{
$message = null;
$configurableAttributes = $this->product->getData('configurable_attributes_data')['attributes_data'];
$attribute = array_shift($configurableAttributes);
$customOptions = [];

foreach ($attribute['options'] as $option) {
$customOptions[] = [
'type' => $attribute['frontend_input'],
'title' => $attribute['frontend_label'],
'value' => $option['label']
];
}

foreach ($customOptions as $customOption) {
$this->productView->getCustomOptionsBlock()->fillCustomOptions([$customOption]);
$displayedImage = $this->productView->getBaseImageSource();
if (in_array($displayedImage, $this->displayedImages)) {
$message = 'Option image is not correct.';
break;
}

$this->displayedImages[] = $displayedImage;
}

return $message;
}

/**
* Compare images and return true if they are different.
*
* @param string $compared
* @param string $toCompare
* @return bool
*/
private function areImagesDifferent($compared, $toCompare)
{
preg_match('`/(\w*?)\.(\w*?)$`', $compared, $shownImage);
preg_match('`/(\w*?)\.(\w*?)$`', $toCompare, $expectedImage);

return strpos($shownImage[1], $expectedImage[1]) === false || $expectedImage[2] !== $shownImage[2];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<field name="gallery" is_required="0" />
<field name="gift_message_available" is_required="0" />
<field name="has_options" is_required="0" />
<field name="image" is_required="0" />
<field name="image" is_required="0" group="gallery" source="Magento\Catalog\Test\Fixture\Product\Image" />
<field name="image_label" is_required="0" />
<field name="manufacturer" is_required="0" />
<field name="media_gallery" is_required="0" />
Expand Down
Loading

0 comments on commit c30a05a

Please sign in to comment.