Skip to content

Commit

Permalink
Merge pull request #502 from magento-tango/MAGETWO-50944
Browse files Browse the repository at this point in the history
[Tango] Stabilize functional tests for configurable product and product attributes
  • Loading branch information
Korshenko, Oleksii(okorshenko) committed Apr 1, 2016
2 parents 3e9d612 + 41752f5 commit 0b62520
Show file tree
Hide file tree
Showing 57 changed files with 674 additions and 459 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
?>
<fieldset class="fieldset">
<legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Manage Options (Values of Your Attribute)') ?></span></legend>
<div id="manage-options-panel">
<table class="admin__control-table">
<div id="manage-options-panel" data-index="attribute_options_select_container">
<table class="admin__control-table" data-index="attribute_options_select">
<thead>
<tr id="attribute-options-table">
<th class="col-draggable"></th>
Expand All @@ -37,7 +37,7 @@
<tr>
<th colspan="<?php /* @escapeNotVerified */ echo $storetotal; ?>" class="col-actions-add">
<?php if (!$block->getReadOnly() && !$block->canManageOptionDefaultOnly()):?>
<button id="add_new_option_button" title="<?php /* @escapeNotVerified */ echo __('Add Option'); ?>"
<button id="add_new_option_button" data-action="add_new_row" title="<?php /* @escapeNotVerified */ echo __('Add Option'); ?>"
type="button" class="action- scalable add">
<span><?php /* @escapeNotVerified */ echo __('Add Option'); ?></span>
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ protected function fillSimpleProductData(
$product->setData($attribute->getAttributeCode(), $parentProduct->getData($attribute->getAttributeCode()));
}

$postData['stock_data'] = $parentProduct->getStockData();
$keysFilter = ['item_id', 'product_id', 'stock_id', 'type_id', 'website_id'];
$postData['stock_data'] = array_diff_key((array)$parentProduct->getStockData(), array_flip($keysFilter));
$postData['stock_data']['manage_stock'] = $postData['quantity_and_stock_status']['qty'] === '' ? 0 : 1;
if (!isset($postData['stock_data']['is_in_stock'])) {
$stockStatus = $parentProduct->getQuantityAndStockStatus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ protected function getNewAttributeSet()
'formElement' => Form\Element\Input::NAME,
'componentType' => Form\Field::NAME,
'dataScope' => 'configurableNewAttributeSetName',
'additionalClasses' => 'new-attribute-set-name',
'label' => __('New Attribute Set Name'),
'sortOrder' => 40,
'validation' => ['required-entry' => true],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
ko-focused="focused"
ko-value="value"
keyboard="keyboard"
attr="id: uid, name: inputName"/>
attr="id: uid, name: inputName, 'data-index': index"/>

<label class="admin__field-label" text="description" attr="for: uid"/>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function __construct(FixtureInterface $product)
$bundleOptions = $bundleSelection['bundle_options'][$attributeKey];
$value = $bundleSelectionAttribute[$optionKey]->getName();
$qty = $bundleOptions['assigned_products'][$optionKey]['data']['selection_qty'];
$price = $product->getPriceType() == 'Dynamic'
$price = $product->getPriceType() == 'Yes'
? number_format($bundleSelectionAttribute[$optionKey]->getPrice(), 2)
: number_format($bundleOptions['assigned_products'][$optionKey]['data']['selection_price_value'], 2);
$optionData = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected function prepareProductDetails()
parent::prepareProductDetails();

if (!isset($this->fields['product']['price_type'])) {
$this->fields['product']['price_type'] = 'Dynamic';
$this->fields['product']['price_type'] = 'Yes';
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,22 @@

namespace Magento\Catalog\Test\Block\Adminhtml\Product\Attribute;

use Magento\Backend\Test\Block\Widget\FormTabs;
use Magento\Backend\Test\Block\Widget\Tab;
use Magento\Mtf\Client\Element;
use Magento\Ui\Test\Block\Adminhtml\FormSections;
use Magento\Mtf\Client\Element\SimpleElement;
use Magento\Mtf\Client\Locator;
use Magento\Mtf\Fixture\FixtureInterface;

/**
* Edit attribute form on catalog product edit page.
*/
class AttributeForm extends FormTabs
class AttributeForm extends FormSections
{
/**
* Iframe locator.
*
* @var string
*/
protected $iFrame = '#create_new_attribute_container';

/**
* Save button selector.
*
* @var string
*/
protected $saveButton = '#save';

/**
* Attribute to determine whether tab is opened.
*
* @var string
*/
protected $isTabOpened = '.opened ';

/**
* Initialize block. Switch to frame.
*
* @return void
*/
protected function init()
{
parent::init();
$this->browser->switchToFrame(new Locator($this->iFrame));
}

/**
* Fill the attribute form.
*
Expand All @@ -67,28 +39,6 @@ function () use ($browser, $selector) {
}
);
parent::fill($fixture, $element);
$this->browser->switchToFrame();
}

/**
* Open tab.
*
* @param string $tabName
* @return Tab
*/
public function openTab($tabName)
{
$selector = $this->getTabs()[$tabName]['selector'];
$strategy = isset($this->getTabs()[$tabName]['strategy'])
? $this->getTabs()[$tabName]['strategy']
: Locator::SELECTOR_CSS;

$isTabOpened = $this->_rootElement->find($this->isTabOpened . $selector, $strategy);
if (!$isTabOpened->isVisible()) {
$this->_rootElement->find($selector, $strategy)->click();
}

return $this;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
* See COPYING.txt for license details.
*/
-->
<tabs>
<sections>
<properties>
<class>\Magento\Backend\Test\Block\Widget\Tab</class>
<selector>#edit_form</selector>
<class>\Magento\Ui\Test\Block\Adminhtml\Section</class>
<selector>.product_form_product_form_add_attribute_modal_create_new_attribute_modal_product_attribute_add_form</selector>
<strategy>css selector</strategy>
<fields>
<frontend_label>
Expand All @@ -18,36 +18,32 @@
<input>select</input>
</frontend_input>
<is_required>
<input>select</input>
<input>switcher</input>
</is_required>
<options>
<class>\Magento\Catalog\Test\Block\Adminhtml\Product\Attribute\Edit\Options</class>
<selector>#manage-options-panel</selector>
<selector>[data-index="attribute_options_select_container"]</selector>
<strategy>css selector</strategy>
</options>
</fields>
</properties>
<advanced-properties>
<class>\Magento\Backend\Test\Block\Widget\Tab</class>
<selector>[data-target="#advanced_fieldset-content"]</selector>
<class>\Magento\Ui\Test\Block\Adminhtml\Section</class>
<selector>[data-index="advanced_fieldset"]</selector>
<strategy>css selector</strategy>
<fields>
<attribute_code>
</attribute_code>
<attribute_code/>
<is_global>
<input>select</input>
</is_global>
<default_value>
<selector>[name^='default_value_']</selector>
</default_value>
<is_unique>
<input>select</input>
<input>switcher</input>
</is_unique>
</fields>
</advanced-properties>
<manage-labels>
<class>\Magento\Backend\Test\Block\Widget\Tab</class>
<selector>[data-target="#manage-titles-content"]</selector>
<class>\Magento\Ui\Test\Block\Adminhtml\Section</class>
<selector>[data-index="manage-titles"]</selector>
<strategy>css selector</strategy>
<fields>
<manage_frontend_label>
Expand All @@ -56,40 +52,40 @@
</fields>
</manage-labels>
<frontend-properties>
<class>\Magento\Backend\Test\Block\Widget\Tab</class>
<selector>[data-target="#front_fieldset-content"]</selector>
<class>\Magento\Ui\Test\Block\Adminhtml\Section</class>
<selector>[data-index="front_fieldset"]</selector>
<strategy>css selector</strategy>
<fields>
<is_searchable>
<input>select</input>
<input>switcher</input>
</is_searchable>
<is_visible_in_advanced_search>
<input>select</input>
<input>switcher</input>
</is_visible_in_advanced_search>
<is_comparable>
<input>select</input>
<input>switcher</input>
</is_comparable>
<is_filterable>
<input>select</input>
</is_filterable>
<is_filterable_in_search>
<input>select</input>
<input>switcher</input>
</is_filterable_in_search>
<is_used_for_promo_rules>
<input>select</input>
<input>switcher</input>
</is_used_for_promo_rules>
<is_html_allowed_on_front>
<input>select</input>
<input>switcher</input>
</is_html_allowed_on_front>
<is_visible_on_front>
<input>select</input>
<input>switcher</input>
</is_visible_on_front>
<used_in_product_listing>
<input>select</input>
<input>switcher</input>
</used_in_product_listing>
<used_for_sort_by>
<input>select</input>
<input>switcher</input>
</used_for_sort_by>
</fields>
</frontend-properties>
</tabs>
</sections>
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@ class CustomAttribute extends SimpleElement
*
* @var string
*/
protected $inputSelector = '.control [name]:not([type="hidden"]), table';
protected $inputSelector = '[name="product[%s]"]';

/**
* Attribute class to element type reference.
*
* @var array
*/
protected $classReference = [
'input-text' => null,
'admin__control-text' => null,
'textarea' => null,
'hasDatepicker' => 'datepicker',
'select' => 'select',
'multiselect' => 'multiselect',
'admin__control-select' => 'select',
'admin__control-multiselect' => 'multiselect',
'admin__actions-switch-checkbox' => 'switcher'
];

/**
Expand All @@ -43,10 +44,11 @@ class CustomAttribute extends SimpleElement
public function setValue($data)
{
$this->eventManager->dispatchEvent(['set_value'], [__METHOD__, $this->getAbsoluteSelector()]);
$element = $this->getElementByClass($this->getElementClass());
$code = isset($data['code']) ? $data['code'] : $this->getAttributeCode($this->getAbsoluteSelector());
$element = $this->getElementByClass($this->getElementClass($code));
$value = is_array($data) ? $data['value'] : $data;
if ($value !== null) {
$this->find($this->inputSelector, Locator::SELECTOR_CSS, $element)->setValue($value);
$this->find(sprintf($this->inputSelector, $code), Locator::SELECTOR_CSS, $element)->setValue($value);
}
}

Expand All @@ -58,8 +60,9 @@ public function setValue($data)
public function getValue()
{
$this->eventManager->dispatchEvent(['get_value'], [__METHOD__, $this->getAbsoluteSelector()]);
$inputType = $this->getElementByClass($this->getElementClass());
return $this->find($this->inputSelector, Locator::SELECTOR_CSS, $inputType)->getValue();
$code = $this->getAttributeCode($this->getAbsoluteSelector());
$inputType = $this->getElementByClass($this->getElementClass($code));
return $this->find(sprintf($this->inputSelector, $code), Locator::SELECTOR_CSS, $inputType)->getValue();
}

/**
Expand All @@ -68,7 +71,7 @@ public function getValue()
* @param string $class
* @return string
*/
protected function getElementByClass($class)
private function getElementByClass($class)
{
$element = null;
foreach ($this->classReference as $key => $reference) {
Expand All @@ -82,10 +85,25 @@ protected function getElementByClass($class)
/**
* Get element class.
*
* @param string $code
* @return string
*/
protected function getElementClass()
private function getElementClass($code)
{
return $this->find($this->inputSelector, Locator::SELECTOR_CSS)->getAttribute('class');
return $this->find(sprintf($this->inputSelector, $code), Locator::SELECTOR_CSS)->getAttribute('class');
}

/**
* Get attribute code.
*
* @param string $attributeSelector
* @return string
*/
private function getAttributeCode($attributeSelector)
{
preg_match('/data-index="(.*)"/', $attributeSelector, $matches);
$code = !empty($matches[1]) ? $matches[1] : '';

return $code;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ class Options extends SimpleElement
*
* @var string
*/
protected $addOption = '#add_new_option_button';
protected $addOption = 'button[data-action="add_new_row"]';

/**
* Option form selector.
*
* @var string
*/
protected $option = '.ui-sortable tr';
protected $option = '[data-index="attribute_options_select"] tbody tr';

/**
* Set value.
Expand Down
Loading

0 comments on commit 0b62520

Please sign in to comment.