Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit fde3cc0

Browse files
committed
MAGETWO-80093: Create Functional Test to verify OOS Configuration product option not showing in Layered Navigation
- Added Functional test
1 parent e442de5 commit fde3cc0

File tree

8 files changed

+305
-0
lines changed

8 files changed

+305
-0
lines changed

dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductAttribute.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,33 @@
272272
</field>
273273
</dataset>
274274

275+
<dataset name="sizes_S_M_L_Filterable">
276+
<field name="frontend_label" xsi:type="string">size_%isolation%</field>
277+
<field name="attribute_code" xsi:type="string">size_%isolation%</field>
278+
<field name="frontend_input" xsi:type="string">Dropdown</field>
279+
<field name="is_required" xsi:type="string">No</field>
280+
<field name="is_searchable" xsi:type="string">Yes</field>
281+
<field name="is_filterable" xsi:type="string">Filterable (with results)</field>
282+
<field name="is_filterable_in_search" xsi:type="string">Yes</field>
283+
<field name="options" xsi:type="array">
284+
<item name="0" xsi:type="array">
285+
<item name="is_default" xsi:type="string">No</item>
286+
<item name="admin" xsi:type="string">SIZE_S</item>
287+
<item name="view" xsi:type="string">SIZE_S</item>
288+
</item>
289+
<item name="1" xsi:type="array">
290+
<item name="is_default" xsi:type="string">No</item>
291+
<item name="admin" xsi:type="string">SIZE_M</item>
292+
<item name="view" xsi:type="string">SIZE_M</item>
293+
</item>
294+
<item name="2" xsi:type="array">
295+
<item name="is_default" xsi:type="string">No</item>
296+
<item name="admin" xsi:type="string">SIZE_L</item>
297+
<item name="view" xsi:type="string">SIZE_L</item>
298+
</item>
299+
</field>
300+
</dataset>
301+
275302
<dataset name="sizes_for_promo_rules">
276303
<field name="frontend_label" xsi:type="string">size_%isolation%</field>
277304
<field name="attribute_code" xsi:type="string">size_%isolation%</field>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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\Mtf\Fixture\FixtureFactory;
10+
use Magento\Mtf\Fixture\InjectableFixture;
11+
use Magento\Cms\Test\Page\CmsIndex;
12+
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;
16+
17+
/**
18+
* Check whether the attribute filter is displayed on the frontend in Layered navigation.
19+
*/
20+
class AssertConfigurableProductAttributeOptionInLayeredNavigation extends AbstractConstraint
21+
{
22+
23+
/**
24+
* Get product attribute
25+
*
26+
* @param InjectableFixture $product
27+
* @return mixed
28+
29+
private function getAttribute(InjectableFixture $product)
30+
{
31+
$attributes = $product->getDataFieldConfig('configurable_attributes_data')['source']->getAttributes();
32+
if (is_array($attributes)) {
33+
$attribute = current($attributes);
34+
}
35+
return isset($attribute) ? $attribute : null;
36+
}
37+
*/
38+
39+
/**
40+
* @param InjectableFixture $product
41+
*/
42+
/**
43+
private function getOptions(InjectableFixture $product) {
44+
45+
46+
$attributesData = $product->hasData('configurable_attributes_data')
47+
? $product->getConfigurableAttributesData()['attributes_data']
48+
: [];
49+
foreach($attributesData as $option) {
50+
$optionValue = $option[0]['view'];
51+
}
52+
53+
}
54+
*/
55+
56+
/**
57+
* Check whether the attribute filter is displayed on the frontend in Layered navigation.
58+
*
59+
* @param CatalogCategoryView $catalogCategoryView
60+
* @param InjectableFixture $product
61+
* @param CatalogProductAttribute $attribute
62+
* @param CmsIndex $cmsIndex
63+
* @param FixtureFactory $fixtureFactory
64+
* @return void
65+
*/
66+
public function processAssert(
67+
CatalogCategoryView $catalogCategoryView,
68+
InjectableFixture $product,
69+
CmsIndex $cmsIndex,
70+
FixtureFactory $fixtureFactory,
71+
$outOfStockOption
72+
) {
73+
$fixtureFactory->createByCode(
74+
'catalogProductSimple',
75+
[
76+
'dataset' => 'product_with_category_with_anchor',
77+
'data' => [
78+
'category_ids' => [
79+
'dataset' => null,
80+
'category' => $product->getDataFieldConfig('category_ids')['source']->getCategories()[0]
81+
]
82+
],
83+
]
84+
)->persist();
85+
86+
$cmsIndex->open()->getTopmenu()->selectCategoryByName($product->getCategoryIds()[0]);
87+
/*$label = $attribute->hasData('manage_frontend_label')
88+
? $attribute->getManageFrontendLabel()
89+
: $attribute->getFrontendLabel();
90+
$attributeValue = $this->getAttribute($product);
91+
if($attributeValue)
92+
$label = $attributeValue->getOptions()[0]['view'];
93+
*/
94+
95+
$filters = $catalogCategoryView->getLayeredNavigationBlock()->getFilterContents();
96+
97+
\PHPUnit_Framework_Assert::assertFalse(
98+
in_array(strtoupper($outOfStockOption), $filters),
99+
'Out of Stock attribute option is present in layered navigation on category page.'
100+
);
101+
}
102+
103+
/**
104+
* Return string representation of object.
105+
*
106+
* @return string
107+
*/
108+
public function toString()
109+
{
110+
return 'Out of Stock attribute option is absent in layered navigation on category page.';
111+
}
112+
}

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,5 +1115,37 @@
11151115
</item>
11161116
</field>
11171117
</dataset>
1118+
<dataset name="product_with_3_sizes">
1119+
<field name="name" xsi:type="string">Configurable product with sizes %isolation%</field>
1120+
<field name="sku" xsi:type="string">sku_configurable_product_with_sizes_%isolation%</field>
1121+
<field name="product_has_weight" xsi:type="string">This item has weight</field>
1122+
<field name="weight" xsi:type="string">2</field>
1123+
<field name="status" xsi:type="string">Yes</field>
1124+
<field name="visibility" xsi:type="string">Catalog, Search</field>
1125+
<field name="tax_class_id" xsi:type="array">
1126+
<item name="dataset" xsi:type="string">taxable_goods</item>
1127+
</field>
1128+
<field name="url_key" xsi:type="string">configurable-product-with-size-%isolation%</field>
1129+
<field name="configurable_attributes_data" xsi:type="array">
1130+
<item name="dataset" xsi:type="string">size_3_items</item>
1131+
</field>
1132+
<field name="quantity_and_stock_status" xsi:type="array">
1133+
<item name="is_in_stock" xsi:type="string">In Stock</item>
1134+
</field>
1135+
<field name="website_ids" xsi:type="array">
1136+
<item name="0" xsi:type="array">
1137+
<item name="dataset" xsi:type="string">default</item>
1138+
</item>
1139+
</field>
1140+
<field name="category_ids" xsi:type="array">
1141+
<item name="dataset" xsi:type="string">default_anchor_subcategory</item>
1142+
</field>
1143+
<field name="attribute_set_id" xsi:type="array">
1144+
<item name="dataset" xsi:type="string">default</item>
1145+
</field>
1146+
<field name="price" xsi:type="array">
1147+
<item name="value" xsi:type="string">170</item>
1148+
</field>
1149+
</dataset>
11181150
</repository>
11191151
</config>

dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Repository/ConfigurableProduct/ConfigurableAttributesData.xml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,44 @@
623623
</field>
624624
</dataset>
625625

626+
<dataset name="size_3_items">
627+
<field name="attributes_data" xsi:type="array">
628+
<item name="attribute_key_0" xsi:type="array">
629+
<item name="options" xsi:type="array">
630+
<item name="option_key_0" xsi:type="array">
631+
<item name="pricing_value" xsi:type="string">40.00</item>
632+
<item name="include" xsi:type="string">Yes</item>
633+
</item>
634+
<item name="option_key_1" xsi:type="array">
635+
<item name="pricing_value" xsi:type="string">42.00</item>
636+
<item name="include" xsi:type="string">Yes</item>
637+
</item>
638+
<item name="option_key_2" xsi:type="array">
639+
<item name="pricing_value" xsi:type="string">44.00</item>
640+
<item name="include" xsi:type="string">Yes</item>
641+
</item>
642+
</item>
643+
</item>
644+
</field>
645+
<field name="attributes" xsi:type="array">
646+
<item name="attribute_key_0" xsi:type="string">catalogProductAttribute::sizes_S_M_L_Filterable</item>
647+
</field>
648+
<field name="matrix" xsi:type="array">
649+
<item name="attribute_key_0:option_key_0" xsi:type="array">
650+
<item name="qty" xsi:type="string">100</item>
651+
<item name="weight" xsi:type="string">1</item>
652+
</item>
653+
<item name="attribute_key_0:option_key_1" xsi:type="array">
654+
<item name="qty" xsi:type="string">100</item>
655+
<item name="weight" xsi:type="string">1</item>
656+
</item>
657+
<item name="attribute_key_0:option_key_2" xsi:type="array">
658+
<item name="qty" xsi:type="string">100</item>
659+
<item name="weight" xsi:type="string">1</item>
660+
</item>
661+
</field>
662+
</dataset>
663+
626664
<dataset name="color_and_size_with_images">
627665
<field name="attributes_data" xsi:type="array">
628666
<item name="attribute_key_0" xsi:type="array">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\ConfigurableProduct\Test\TestCase;
8+
9+
use Magento\Mtf\TestCase\Scenario;
10+
11+
/**
12+
* Preconditions:
13+
1. Choose the color attribute and set attribute properties to
14+
2. is_filterable = Filterable (with results)
15+
3. is_filterable_in_search = Yes
16+
*
17+
* Steps:
18+
* 1. Log in to Admin.
19+
* 2. Open Products -> Catalog.
20+
* 3. Search and open child of configurable product from preconditions.
21+
* 4. Fill in data according to dataset.
22+
* 5. Save product.
23+
* 6. Perform all assertions.
24+
*
25+
* @group Configurable_Product
26+
* @ZephyrId MAGETWO-60196, MAGETWO-60206, MAGETWO-60236, MAGETWO-60296, MAGETWO-60297, MAGETWO-60325, MAGETWO-60328,
27+
* MAGETWO-60329, MAGETWO-60330
28+
*/
29+
class VerifyConfigurableProductLayeredNavigationTest extends Scenario
30+
{
31+
/**
32+
* Verify configurable product price.
33+
*
34+
* @return array
35+
*/
36+
public function test()
37+
{
38+
$this->executeScenario();
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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\ConfigurableProduct\Test\TestCase\VerifyConfigurableProductLayeredNavigationTest" summary="Verify price for configurable product">
10+
<variation name="VerifyConfigurableProductEntityPriceTestVariation2" summary="Set child product Out of stock" ticketId="MAGETWO-60206">
11+
<data name="product" xsi:type="string">configurableProduct::product_with_3_sizes</data>
12+
<data name="productUpdate/childProductUpdate" xsi:type="array">
13+
<item name="data" xsi:type="array">
14+
<item name="quantity_and_stock_status" xsi:type="array">
15+
<item name="is_in_stock" xsi:type="string">Out of Stock</item>
16+
</item>
17+
</item>
18+
</data>
19+
<data name="productUpdate/optionNumber" xsi:type="string">1</data>
20+
<data name="outOfStockOption" xsi:type="string">SIZE_S</data>
21+
<constraint name="Magento\ConfigurableProduct\Test\Constraint\AssertConfigurableProductAttributeOptionInLayeredNavigation" />
22+
</variation>
23+
</testCase>
24+
</config>

dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/etc/testcase.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,8 @@
1717
<step name="createProduct" module="Magento_Catalog" next="updateChildProduct" />
1818
<step name="updateChildProduct" module="Magento_ConfigurableProduct" />
1919
</scenario>
20+
<scenario name="VerifyConfigurableProductLayeredNavigationTest" firstStep="createProduct">
21+
<step name="createProduct" module="Magento_Catalog" next="updateChildProduct" />
22+
<step name="updateChildProduct" module="Magento_ConfigurableProduct" />
23+
</scenario>
2024
</config>

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ class Navigation extends Block
3636
*/
3737
protected $optionTitle = './/div[@class="filter-options-title" and contains(text(),"%s")]';
3838

39+
/**
40+
* Locator value for correspondent Attribute filter option content.
41+
*
42+
* @var string
43+
*/
44+
45+
protected $optionContent = './/div[@class="filter-options-title" and contains(text(),"")]/following-sibling::div//a[contains(text(), \'SIZE\')]';
46+
47+
3948
/**
4049
* Locator value for correspondent "Filter" link.
4150
*
@@ -92,6 +101,25 @@ public function getFilters()
92101
return $data;
93102
}
94103

104+
/**
105+
* Get all available filters.
106+
*
107+
* @return array
108+
*/
109+
public function getFilterContents()
110+
{
111+
$this->waitForElementVisible($this->loadedNarrowByList);
112+
113+
// $optionContents = $this->_rootElement->getElements(sprintf($this->optionContent, ''), Locator::SELECTOR_XPATH);
114+
$optionContents = $this->_rootElement->find($this->optionContent,Locator::SELECTOR_XPATH);
115+
$data =[];
116+
foreach ($optionContents as $optionContent) {
117+
$data[] = trim(strtoupper($optionContent->getText()));
118+
}
119+
120+
return $data;
121+
}
122+
95123
/**
96124
* Apply Layered Navigation filter.
97125
*

0 commit comments

Comments
 (0)