Skip to content

Commit dc5bd24

Browse files
author
Alexander Akimov
authored
Merge pull request #2347 from magento-tsg/2.2-develop-pr24
[TSG] Upporting for 2.2 (pr24) (2.2.5)
2 parents 1cfce89 + 7c1578c commit dc5bd24

File tree

2 files changed

+47
-22
lines changed

2 files changed

+47
-22
lines changed

dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Constraint/AssertConfigurableProductAttributeOptionInLayeredNavigation.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66

77
namespace Magento\ConfigurableProduct\Test\Constraint;
88

9-
use Magento\Mtf\Fixture\FixtureFactory;
10-
use Magento\Mtf\Fixture\InjectableFixture;
9+
use Magento\Catalog\Test\Page\Category\CatalogCategoryView;
1110
use Magento\Cms\Test\Page\CmsIndex;
1211
use Magento\Mtf\Constraint\AbstractConstraint;
13-
use Magento\Catalog\Test\Fixture\CatalogProductAttribute;
14-
use Magento\Catalog\Test\Page\Category\CatalogCategoryView;
15-
use Magento\ConfigurableProduct\Test\Fixture\ConfigurableProduct;
12+
use Magento\Mtf\Fixture\FixtureFactory;
13+
use Magento\Mtf\Fixture\InjectableFixture;
1614

1715
/**
1816
* Check whether OOS product attribute options for configurable product are displayed on frontend in Layered navigation.
@@ -43,25 +41,33 @@ public function processAssert(
4341
'data' => [
4442
'category_ids' => [
4543
'dataset' => null,
46-
'category' => $product->getDataFieldConfig('category_ids')['source']->getCategories()[0]
47-
]
44+
'category' => $product->getDataFieldConfig('category_ids')['source']->getCategories()[0],
45+
],
4846
],
4947
]
5048
)->persist();
5149

5250
$cmsIndex->open()->getTopmenu()->selectCategoryByName($product->getCategoryIds()[0]);
53-
$filters = $catalogCategoryView->getLayeredNavigationBlock()->getFilterContents();
5451

55-
\PHPUnit_Framework_Assert::assertFalse(
52+
$attributesData = $product->hasData('configurable_attributes_data')
53+
? $product->getConfigurableAttributesData()['attributes_data']
54+
: [];
55+
56+
$attributeData = !empty($attributesData) ? array_shift($attributesData) : [];
57+
$frontendAttributeLabel = !empty($attributeData) && isset($attributeData['frontend_label'])
58+
? $attributeData['frontend_label']
59+
: '';
60+
61+
$filters = $catalogCategoryView->getLayeredNavigationBlock()->getFilterContents($frontendAttributeLabel);
62+
63+
\PHPUnit\Framework\Assert::assertFalse(
5664
in_array(strtoupper($outOfStockOption), $filters),
5765
'Out of Stock attribute option is present in layered navigation on category page.'
5866
);
5967
}
6068

6169
/**
62-
* Return string representation of object.
63-
*
64-
* @return string
70+
* @inheritdoc
6571
*/
6672
public function toString()
6773
{

dev/tests/functional/tests/app/Magento/LayeredNavigation/Test/Block/Navigation.php

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,22 @@ public function getFilters()
104104
/**
105105
* Get all available filters.
106106
*
107+
* @param string $attributeLabel
107108
* @return array
108109
*/
109-
public function getFilterContents()
110+
public function getFilterContents($attributeLabel)
110111
{
111-
$this->waitForElementVisible($this->loadedNarrowByList);
112-
$optionContents = $this->_rootElement->find($this->optionContent, Locator::SELECTOR_XPATH);
113-
$data =[];
112+
$data = [];
113+
114+
if (trim($attributeLabel) === '') {
115+
return $data;
116+
}
117+
118+
$link = sprintf($this->filterLink, $attributeLabel);
119+
$this->openFilterContainer($attributeLabel, $link);
120+
121+
$optionContents = $this->_rootElement->getElements($link, Locator::SELECTOR_XPATH);
122+
114123
foreach ($optionContents as $optionContent) {
115124
$data[] = trim(strtoupper($optionContent->getText()));
116125
}
@@ -128,13 +137,8 @@ public function getFilterContents()
128137
*/
129138
public function applyFilter($filter, $linkPattern)
130139
{
131-
$expandFilterButton = sprintf($this->optionTitle, $filter);
132140
$links = sprintf($this->filterLink, $filter);
133-
134-
$this->waitForElementVisible($this->loadedNarrowByList);
135-
if (!$this->_rootElement->find($links, Locator::SELECTOR_XPATH)->isVisible()) {
136-
$this->_rootElement->find($expandFilterButton, Locator::SELECTOR_XPATH)->click();
137-
}
141+
$this->openFilterContainer($filter, $links);
138142

139143
$links = $this->_rootElement->getElements($links, Locator::SELECTOR_XPATH);
140144
foreach ($links as $link) {
@@ -160,4 +164,19 @@ public function isCategoryVisible(Category $category, $qty)
160164
Locator::SELECTOR_XPATH
161165
)->isVisible();
162166
}
167+
168+
/**
169+
* @param string $filter
170+
* @param string $link
171+
* @return void
172+
*/
173+
private function openFilterContainer($filter, $link)
174+
{
175+
$expandFilterButton = sprintf($this->optionTitle, $filter);
176+
177+
$this->waitForElementVisible($this->loadedNarrowByList);
178+
if (!$this->_rootElement->find($link, Locator::SELECTOR_XPATH)->isVisible()) {
179+
$this->_rootElement->find($expandFilterButton, Locator::SELECTOR_XPATH)->click();
180+
}
181+
}
163182
}

0 commit comments

Comments
 (0)