Skip to content

Commit 99dca3e

Browse files
author
Aponasenko, Dmytro(daponasenko)
committed
Merge pull request #272 from magento-qmt/develop
[Mavericks] Re-factor end-to-end tests and maintain functional tests
2 parents ade3933 + 18a38a2 commit 99dca3e

File tree

79 files changed

+1865
-697
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+1865
-697
lines changed

dev/tests/functional/lib/Magento/Mtf/Client/Element/ConditionsElement.php

Lines changed: 203 additions & 111 deletions
Large diffs are not rendered by default.

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ class ListProduct extends Block
2323
*/
2424
protected $productItem = './/*[contains(@class,"product-item-link") and normalize-space(text())="%s"]/ancestor::li';
2525

26+
/**
27+
* Locator for product item link.
28+
*
29+
* @var string
30+
*/
31+
protected $productItemLink = '.product-item-link';
32+
2633
/**
2734
* Sorter dropdown selector.
2835
*
@@ -46,6 +53,23 @@ public function getProductItem(FixtureInterface $product)
4653
);
4754
}
4855

56+
/**
57+
* Get product names list.
58+
*
59+
* @return array
60+
*/
61+
public function getProductNames()
62+
{
63+
$itemLinks = $this->_rootElement->getElements($this->productItemLink);
64+
$productNames = [];
65+
66+
foreach ($itemLinks as $itemLink) {
67+
$productNames[] = trim($itemLink->getText());
68+
}
69+
70+
return $productNames;
71+
}
72+
4973
/**
5074
* Get all terms used in sort.
5175
*

dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/Category/Curl.php

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Magento\Catalog\Test\Handler\Category;
88

9+
use Magento\Catalog\Test\Fixture\Category;
910
use Magento\Mtf\Fixture\FixtureInterface;
1011
use Magento\Mtf\Handler\Curl as AbstractCurl;
1112
use Magento\Mtf\Util\Protocol\CurlInterface;
@@ -58,20 +59,24 @@ class Curl extends AbstractCurl implements CategoryInterface
5859
*
5960
* @param FixtureInterface|null $fixture [optional]
6061
* @return array
62+
* @throws \Exception
6163
*/
6264
public function persist(FixtureInterface $fixture = null)
6365
{
6466
$data = $this->prepareData($fixture);
65-
6667
$url = $_ENV['app_backend_url'] . 'catalog/category/save/store/0/parent/' . $data['general']['parent_id'] . '/';
6768
$curl = new BackendDecorator(new CurlTransport(), $this->_configuration);
6869
$curl->write(CurlInterface::POST, $url, '1.0', [], $data);
6970
$response = $curl->read();
7071
$curl->close();
7172

73+
if (!strpos($response, 'data-ui-id="messages-message-success"')) {
74+
$this->_eventManager->dispatchEvent(['curl_failed'], [$response]);
75+
throw new \Exception('Category creation by curl handler was not successful!');
76+
}
77+
7278
preg_match('#http://.+/id/(\d+).+store/#m', $response, $matches);
7379
$id = isset($matches[1]) ? (int)$matches[1] : null;
74-
7580
return ['id' => $id];
7681
}
7782

@@ -83,12 +88,16 @@ public function persist(FixtureInterface $fixture = null)
8388
*/
8489
protected function prepareData(FixtureInterface $fixture)
8590
{
86-
$data['general'] = $this->replaceMappingData($fixture->getData());
87-
$data['is_anchor'] = isset($data['is_anchor']) ? $data['is_anchor'] : 0;
91+
$data = ['general' => $this->replaceMappingData($fixture->getData())];
92+
$data['general']['is_anchor'] = isset($data['general']['is_anchor']) ? $data['general']['is_anchor'] : 0;
93+
8894
if ($fixture->hasData('landing_page')) {
8995
$data['general']['landing_page'] = $this->getBlockId($fixture->getLandingPage());
9096
}
9197

98+
$data['category_products'] = $this->prepareCategoryProducts($fixture);
99+
unset($data['general']['category_products']);
100+
92101
$diff = array_diff($this->dataUseConfig, array_keys($data['general']));
93102
if (!empty($diff)) {
94103
$data['use_config'] = $diff;
@@ -97,6 +106,28 @@ protected function prepareData(FixtureInterface $fixture)
97106
return $data;
98107
}
99108

109+
/**
110+
* Prepare category products data for curl.
111+
*
112+
* @param FixtureInterface $category
113+
* @return array
114+
*/
115+
protected function prepareCategoryProducts(FixtureInterface $category)
116+
{
117+
$categoryProducts = [];
118+
$defaultPosition = 0;
119+
120+
/** @var Category $category */
121+
if ($category->hasData('category_products')) {
122+
$products = $category->getDataFieldConfig('category_products')['source']->getProducts();
123+
foreach ($products as $product) {
124+
$categoryProducts[$product->getId()] = $defaultPosition;
125+
}
126+
}
127+
128+
return json_encode($categoryProducts);
129+
}
130+
100131
/**
101132
* Getting block id by name.
102133
*

dev/tests/functional/tests/app/Magento/Catalog/Test/Page/Category/CatalogCategoryView.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../vendor/magento/mtf/etc/pages.xsd">
99
<page name="CatalogCategoryView" area="Category" mca="catalog/category/view" module="Magento_Catalog">
1010
<block name="titleBlock" class="Magento\Theme\Test\Block\Html\Title" locator=".page-title-wrapper h1.page-title .base" strategy="css selector"/>
11-
<block name="layeredNavigationBlock" class="Magento\LayeredNavigation\Test\Block\Navigation" locator=".block.filter" strategy="css selector"/>
1211
<block name="widgetView" class="Magento\Widget\Test\Block\WidgetView" locator=".widget" strategy="css selector"/>
1312
<block name="viewBlock" class="Magento\Catalog\Test\Block\Category\View" locator="#maincontent" strategy="css selector"/>
1413
<block name="listProductBlock" class="Magento\Catalog\Test\Block\Product\ListProduct" locator=".products.wrapper.grid" strategy="css selector"/>

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,31 @@
6565
</field>
6666
</dataset>
6767

68+
<dataset name="product_20_dollar">
69+
<field name="attribute_set_id" xsi:type="array">
70+
<item name="dataSet" xsi:type="string">default</item>
71+
</field>
72+
<field name="name" xsi:type="string">product_20_dollar %isolation%</field>
73+
<field name="sku" xsi:type="string">sku_product_20_dollar_%isolation%</field>
74+
<field name="is_virtual" xsi:type="string">No</field>
75+
<field name="weight" xsi:type="string">1</field>
76+
<field name="quantity_and_stock_status" xsi:type="array">
77+
<item name="qty" xsi:type="string">1000</item>
78+
<item name="is_in_stock" xsi:type="string">In Stock</item>
79+
</field>
80+
<field name="price" xsi:type="array">
81+
<item name="value" xsi:type="string">20</item>
82+
</field>
83+
<field name="tax_class_id" xsi:type="array">
84+
<item name="dataSet" xsi:type="string">taxable_goods</item>
85+
</field>
86+
<field name="website_ids" xsi:type="array">
87+
<item name="0" xsi:type="string">Main Website</item>
88+
</field>
89+
<field name="visibility" xsi:type="string">Catalog, Search</field>
90+
<field name="url_key" xsi:type="string">product-20-dollar-%isolation%</field>
91+
</dataset>
92+
6893
<dataset name="product_with_url_key">
6994
<field name="name" xsi:type="string">Simple Product %isolation%</field>
7095
<field name="sku" xsi:type="string">sku_simple_product_%isolation%</field>

dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/CreateCategoryEntityTest.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
<data name="category/data/available_product_listing_config" xsi:type="string">Yes</data>
7070
<data name="category/data/default_product_listing_config" xsi:type="string">Yes</data>
7171
<data name="category/data/use_config_price_range" xsi:type="string">Yes</data>
72-
<data name="category/data/category_products_data/preset" xsi:type="string">default</data>
7372
<data name="category/data/category_products/dataSet" xsi:type="string">catalogProductSimple::default,catalogProductSimple::default</data>
7473
<constraint name="Magento\Catalog\Test\Constraint\AssertCategorySaveMessage" />
7574
<constraint name="Magento\Catalog\Test\Constraint\AssertCategoryForm" />
@@ -97,7 +96,6 @@
9796
<data name="category/data/default_sort_by" xsi:type="string">Price</data>
9897
<data name="category/data/use_config_price_range" xsi:type="string">No</data>
9998
<data name="category/data/layered_navigation_price_step" xsi:type="string">50</data>
100-
<data name="category/data/category_products_data/preset" xsi:type="string">default</data>
10199
<data name="category/data/category_products/dataSet" xsi:type="string">catalogProductSimple::default,catalogProductSimple::default</data>
102100
<constraint name="Magento\Catalog\Test\Constraint\AssertCategorySaveMessage" />
103101
<constraint name="Magento\Catalog\Test\Constraint\AssertCategoryForm" />

dev/tests/functional/tests/app/Magento/CatalogRule/Test/TestCase/AbstractCatalogRuleEntityTest.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,6 @@ abstract class AbstractCatalogRuleEntityTest extends Injectable
3838
*/
3939
protected $adminCache;
4040

41-
/**
42-
* Fixture CatalogRule.
43-
*
44-
* @var array
45-
*/
46-
protected $catalogRules = [];
47-
4841
/**
4942
* Fixture factory.
5043
*
@@ -80,12 +73,6 @@ public function __inject(
8073
*/
8174
public function tearDown()
8275
{
83-
foreach ($this->catalogRules as $catalogRule) {
84-
$filter = ['name' => $catalogRule->getName()];
85-
$this->catalogRuleIndex->open();
86-
$this->catalogRuleIndex->getCatalogRuleGrid()->searchAndOpen($filter);
87-
$this->catalogRuleNew->getFormPageActions()->delete();
88-
}
89-
$this->catalogRules = [];
76+
$this->objectManager->create('\Magento\CatalogRule\Test\TestStep\DeleteAllCatalogRulesStep')->run();
9077
}
9178
}

dev/tests/functional/tests/app/Magento/CatalogRule/Test/TestCase/ApplySeveralCatalogPriceRuleEntityTest.php

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,15 @@
99
use Magento\Catalog\Test\Fixture\CatalogProductSimple;
1010

1111
/**
12-
* Test Creation for Apply several CatalogPriceRuleEntity
13-
*
14-
* Test Flow:
1512
* Preconditions:
16-
* 1. Execute before each variation:
17-
* - Delete all active catalog price rules
18-
* - Create catalog price rule from dataSet using Curl
13+
* 1. Execute before each variation:
14+
* - Delete all active catalog price rules
15+
* - Create catalog price rule from dataSet using Curl
16+
*
1917
* Steps:
20-
* 1. Apply all created rules
21-
* 2. Create simple product
22-
* 3. Perform all assertions
18+
* 1. Apply all created rules.
19+
* 2. Create simple product.
20+
* 3. Perform all assertions.
2321
*
2422
* @group Catalog_Price_Rules_(MX)
2523
* @ZephyrId MAGETWO-24780
@@ -32,7 +30,7 @@ class ApplySeveralCatalogPriceRuleEntityTest extends AbstractCatalogRuleEntityTe
3230
/* end tags */
3331

3432
/**
35-
* Apply several catalog price rules
33+
* Apply several catalog price rules.
3634
*
3735
* @param array $catalogRulesOriginal
3836
* @return array
@@ -44,15 +42,15 @@ public function testApplySeveralCatalogPriceRules(array $catalogRulesOriginal)
4442
if ($catalogPriceRule == '-') {
4543
continue;
4644
}
47-
$this->catalogRules[$key] = $this->fixtureFactory->createByCode(
45+
$catalogRules[$key] = $this->fixtureFactory->createByCode(
4846
'catalogRule',
4947
['dataSet' => $catalogPriceRule]
5048
);
51-
$this->catalogRules[$key]->persist();
49+
$catalogRules[$key]->persist();
5250

5351
$filter = [
54-
'name' => $this->catalogRules[$key]->getName(),
55-
'rule_id' => $this->catalogRules[$key]->getId(),
52+
'name' => $catalogRules[$key]->getName(),
53+
'rule_id' => $catalogRules[$key]->getId(),
5654
];
5755
$this->catalogRuleIndex->getCatalogRuleGrid()->searchAndOpen($filter);
5856
$this->catalogRuleNew->getFormPageActions()->saveAndApply();

dev/tests/functional/tests/app/Magento/CatalogRule/Test/TestCase/CreateCatalogPriceRuleEntityTest.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99
use Magento\CatalogRule\Test\Fixture\CatalogRule;
1010

1111
/**
12-
* Test Creation for Create CatalogPriceRuleEntity
13-
*
14-
* Test Flow:
12+
* Steps:
1513
* 1. Log in as default admin user.
16-
* 2. Go to Marketing > Catalog Price Rules
17-
* 3. Press "+" button to start create new catalog price rule
18-
* 4. Fill in all data according to data set
19-
* 5. Save rule
20-
* 6. Perform appropriate assertions
14+
* 2. Go to Marketing > Catalog Price Rules.
15+
* 3. Press "+" button to start create new catalog price rule.
16+
* 4. Fill in all data according to data set.
17+
* 5. Save rule.
18+
* 6. Perform appropriate assertions.
2119
*
2220
* @group Catalog_Price_Rules_(MX)
2321
* @ZephyrId MAGETWO-24341
@@ -42,8 +40,5 @@ public function testCreateCatalogPriceRule(CatalogRule $catalogPriceRule)
4240
$this->catalogRuleIndex->getGridPageActions()->addNew();
4341
$this->catalogRuleNew->getEditForm()->fill($catalogPriceRule);
4442
$this->catalogRuleNew->getFormPageActions()->save();
45-
46-
// Prepare data for tear down
47-
$this->catalogRules[] = $catalogPriceRule;
4843
}
4944
}

dev/tests/functional/tests/app/Magento/CatalogRule/Test/TestCase/CreateCatalogRuleTest.php

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,16 @@
1212
use Magento\Customer\Test\Fixture\CustomerGroupInjectable;
1313

1414
/**
15-
* Test Coverage for Create Catalog Rule
16-
*
17-
* Test Flow:
15+
* Steps:
1816
* 1. Log in as default admin user.
19-
* 2. Go to Marketing > Catalog Price Rules
20-
* 3. Press "+" button to start create new catalog price rule
21-
* 4. Fill in all data according to data set
22-
* 5. Save rule
23-
* 6. Apply newly created catalog rule
24-
* 7. Create simple product
25-
* 8. Clear cache
26-
* 9. Perform all assertions
17+
* 2. Go to Marketing > Catalog Price Rules.
18+
* 3. Press "+" button to start create new catalog price rule.
19+
* 4. Fill in all data according to data set.
20+
* 5. Save rule.
21+
* 6. Apply newly created catalog rule.
22+
* 7. Create simple product.
23+
* 8. Clear cache.
24+
* 9. Perform all assertions.
2725
*
2826
* @ticketId MAGETWO-23036
2927
*/
@@ -37,7 +35,7 @@ class CreateCatalogRuleTest extends AbstractCatalogRuleEntityTest
3735
/* end tags */
3836

3937
/**
40-
* Create Catalog Price Rule
38+
* Create Catalog Price Rule.
4139
*
4240
* @param CatalogRule $catalogPriceRule
4341
* @param Customer $customer
@@ -70,9 +68,6 @@ public function testCreate(
7068
$this->catalogRuleNew->getEditForm()->fill($catalogPriceRule, null, $replace);
7169
$this->catalogRuleNew->getFormPageActions()->save();
7270

73-
// Prepare data for tear down
74-
$this->catalogRules[] = $catalogPriceRule;
75-
7671
// Apply Catalog Price Rule
7772
$this->catalogRuleIndex->getGridPageActions()->applyRules();
7873

dev/tests/functional/tests/app/Magento/CatalogRule/Test/TestCase/UpdateCatalogPriceRuleEntityTest.php

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,17 @@
1111
use Magento\CatalogRule\Test\Fixture\CatalogRule;
1212

1313
/**
14-
* Test Creation for UpdateCatalogPriceRuleEntity
15-
*
16-
* Test Flow:
1714
* Preconditions:
18-
* 1. Catalog Price Rule is created
15+
* 1. Catalog Price Rule is created.
16+
*
1917
* Steps:
20-
* 1. Login to backend
21-
* 2. Navigate to MARKETING > Catalog Price Rules
22-
* 3. Click Catalog Price Rule from grid
23-
* 4. Edit test value(s) according to dataSet
24-
* 5. Click 'Save'/ 'Apply' button
25-
* 6. Create simple product with category
26-
* 7. Perform all asserts
18+
* 1. Login to backend.
19+
* 2. Navigate to MARKETING > Catalog Price Rules.
20+
* 3. Click Catalog Price Rule from grid.
21+
* 4. Edit test value(s) according to dataSet.
22+
* 5. Click 'Save'/ 'Apply' button.
23+
* 6. Create simple product with category.
24+
* 7. Perform all asserts.
2725
*
2826
* @group Catalog_Price_Rules_(MX)
2927
* @ZephyrId MAGETWO-25187
@@ -37,7 +35,7 @@ class UpdateCatalogPriceRuleEntityTest extends AbstractCatalogRuleEntityTest
3735
/* end tags */
3836

3937
/**
40-
* Update catalog price rule
38+
* Update catalog price rule.
4139
*
4240
* @param CatalogRule $catalogPriceRule
4341
* @param CatalogRule $catalogPriceRuleOriginal
@@ -81,9 +79,6 @@ public function testUpdateCatalogPriceRule(
8179
$this->catalogRuleNew->getEditForm()->fill($catalogPriceRule, null, $replace);
8280
$this->catalogRuleNew->getFormPageActions()->$saveAction();
8381

84-
// Prepare data for tear down
85-
$this->catalogRules[] = $catalogPriceRule;
86-
8782
// Create simple product with category
8883
$productSimple->persist();
8984

dev/tests/functional/tests/app/Magento/CatalogRule/Test/TestStep/DeleteAllCatalogRulesStep.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public function __construct(
5151
public function run()
5252
{
5353
$this->catalogRuleIndex->open();
54+
$this->catalogRuleIndex->getCatalogRuleGrid()->resetFilter();
5455
while ($this->catalogRuleIndex->getCatalogRuleGrid()->isFirstRowVisible()) {
5556
$this->catalogRuleIndex->getCatalogRuleGrid()->openFirstRow();
5657
$this->catalogRuleNew->getFormPageActions()->delete();

0 commit comments

Comments
 (0)