Skip to content

Commit dd74133

Browse files
author
Oleksandr Manchenko
committed
MTA-551: Re-factor Test for Out of Stock Item
- Fixed logical and code style errors
1 parent d790fc1 commit dd74133

File tree

5 files changed

+38
-64
lines changed

5 files changed

+38
-64
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Magento\Mtf\Block\Block;
1111
use Magento\Mtf\Client\Locator;
1212
use Magento\Mtf\Client\Element\SimpleElement;
13-
use Magento\Mtf\Factory\Factory;
1413
use Magento\Mtf\Fixture\InjectableFixture;
1514

1615
/**

dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertAddToCartButtonAbsent.php

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

77
namespace Magento\Catalog\Test\Constraint;
88

9-
use Magento\Catalog\Test\Fixture\CatalogProductSimple;
9+
use Magento\Catalog\Test\Fixture\Category;
1010
use Magento\Catalog\Test\Page\Category\CatalogCategoryView;
1111
use Magento\Catalog\Test\Page\Product\CatalogProductView;
1212
use Magento\Cms\Test\Page\CmsIndex;
1313
use Magento\Mtf\Constraint\AbstractConstraint;
14+
use Magento\Mtf\Fixture\InjectableFixture;
1415

1516
/**
1617
* Checks the button on the category/product pages.
@@ -24,21 +25,23 @@ class AssertAddToCartButtonAbsent extends AbstractConstraint
2425
/**
2526
* Assert that "Add to cart" button is not display on page.
2627
*
28+
* @param InjectableFixture $product
29+
* @param Category $category
2730
* @param CmsIndex $cmsIndex
2831
* @param CatalogCategoryView $catalogCategoryView
29-
* @param CatalogProductSimple $product
3032
* @param CatalogProductView $catalogProductView
3133
*
3234
* @return void
3335
*/
3436
public function processAssert(
37+
InjectableFixture $product,
38+
Category $category,
3539
CmsIndex $cmsIndex,
3640
CatalogCategoryView $catalogCategoryView,
37-
CatalogProductSimple $product,
3841
CatalogProductView $catalogProductView
3942
) {
4043
$cmsIndex->open();
41-
$cmsIndex->getTopmenu()->selectCategoryByName($product->getCategoryIds()[0]);
44+
$cmsIndex->getTopmenu()->selectCategoryByName($category->getName());
4245

4346
$isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product->getName());
4447
while (!$isProductVisible && $catalogCategoryView->getBottomToolbar()->nextPage()) {
@@ -48,7 +51,7 @@ public function processAssert(
4851

4952
\PHPUnit_Framework_Assert::assertFalse(
5053
$catalogCategoryView->getListProductBlock()->getProductItem($product)->isVisibleAddToCardButton(),
51-
"Button 'Add to Card' is present on Category page"
54+
"Button 'Add to Card' is present on Category page."
5255
);
5356

5457
$catalogCategoryView->getListProductBlock()->openProductViewPage($product->getName());

dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertAddToCartButtonPresent.php

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

77
namespace Magento\Catalog\Test\Constraint;
88

9-
use Magento\Catalog\Test\Fixture\CatalogProductSimple;
9+
use Magento\Catalog\Test\Fixture\Category;
1010
use Magento\Catalog\Test\Page\Category\CatalogCategoryView;
1111
use Magento\Catalog\Test\Page\Product\CatalogProductView;
1212
use Magento\Cms\Test\Page\CmsIndex;
@@ -25,21 +25,23 @@ class AssertAddToCartButtonPresent extends AbstractConstraint
2525
/**
2626
* Assert that "Add to cart" button is present on page.
2727
*
28+
* @param InjectableFixture $product
29+
* @param Category $category
2830
* @param CmsIndex $cmsIndex
2931
* @param CatalogCategoryView $catalogCategoryView
30-
* @param CatalogProductSimple $product
3132
* @param CatalogProductView $catalogProductView
3233
*
3334
* @return void
3435
*/
3536
public function processAssert(
37+
InjectableFixture $product,
38+
Category $category,
3639
CmsIndex $cmsIndex,
3740
CatalogCategoryView $catalogCategoryView,
38-
CatalogProductSimple $product,
3941
CatalogProductView $catalogProductView
4042
) {
4143
$cmsIndex->open();
42-
$cmsIndex->getTopmenu()->selectCategoryByName($product->getCategoryIds()[0]);
44+
$cmsIndex->getTopmenu()->selectCategoryByName($category->getName());
4345

4446
$isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product->getName());
4547
while (!$isProductVisible && $catalogCategoryView->getBottomToolbar()->nextPage()) {

dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/CreateSimpleProductEntityTest.php

Lines changed: 23 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Magento\Catalog\Test\Fixture\CatalogProductSimple;
1111
use Magento\Catalog\Test\Page\Adminhtml\CatalogProductIndex;
1212
use Magento\Catalog\Test\Page\Adminhtml\CatalogProductNew;
13-
use Magento\Mtf\Fixture\FixtureFactory;
1413
use Magento\Mtf\ObjectManager;
1514
use Magento\Mtf\TestCase\Injectable;
1615

@@ -35,95 +34,66 @@ class CreateSimpleProductEntityTest extends Injectable
3534
/* end tags */
3635

3736
/**
38-
* Configuration setting.
39-
*
40-
* @var string
41-
*/
42-
protected $configData;
43-
44-
/**
45-
* Category fixture.
37+
* Object Manager.
4638
*
47-
* @var Category
39+
* @var ObjectManager
4840
*/
49-
protected $category;
41+
protected $objectManager;
5042

5143
/**
52-
* Product page with a grid.
53-
*
54-
* @var CatalogProductIndex
55-
*/
56-
protected $productGrid;
57-
58-
/**
59-
* Page to create a product.
44+
* Configuration setting.
6045
*
61-
* @var CatalogProductNew
46+
* @var string
6247
*/
63-
protected $newProductPage;
48+
protected $configData;
6449

6550
/**
6651
* Prepare data.
6752
*
53+
* @param ObjectManager $objectManager
6854
* @param Category $category
6955
* @return array
7056
*/
71-
public function __prepare(Category $category)
57+
public function __prepare(ObjectManager $objectManager, Category $category)
7258
{
73-
$category->persist();
59+
$this->objectManager = $objectManager;
7460

61+
$category->persist();
7562
return [
7663
'category' => $category
7764
];
7865
}
7966

8067
/**
81-
* Injection data.
68+
* Run create product simple entity test.
8269
*
70+
* @param string $configData
71+
* @param CatalogProductSimple $product
8372
* @param Category $category
8473
* @param CatalogProductIndex $productGrid
8574
* @param CatalogProductNew $newProductPage
86-
* @return void
75+
* @return array
8776
*/
88-
public function __inject(
77+
public function testCreate(
78+
$configData,
79+
CatalogProductSimple $product,
8980
Category $category,
9081
CatalogProductIndex $productGrid,
9182
CatalogProductNew $newProductPage
9283
) {
93-
$this->category = $category;
94-
$this->productGrid = $productGrid;
95-
$this->newProductPage = $newProductPage;
96-
}
97-
98-
/**
99-
* Run create product simple entity test.
100-
*
101-
* @param string $configData
102-
* @param array $productData
103-
* @param Category $category
104-
* @param FixtureFactory $fixtureFactory
105-
* @return array
106-
*/
107-
public function testCreate($configData, array $productData, Category $category, FixtureFactory $fixtureFactory)
108-
{
10984
$this->configData = $configData;
11085

11186
// Preconditions
112-
ObjectManager::getInstance()->create(
87+
$this->objectManager->create(
11388
'Magento\Core\Test\TestStep\SetupConfigurationStep',
11489
['configData' => $this->configData]
11590
)->run();
116-
$product = $fixtureFactory->createByCode('catalogProductSimple',
117-
[
118-
'data' => array_merge($productData, ['category_ids' => ['category' => $category]])
119-
]
120-
);
12191

12292
// Steps
123-
$this->productGrid->open();
124-
$this->productGrid->getGridPageActionBlock()->addProduct('simple');
125-
$this->newProductPage->getProductForm()->fill($product, null, $category);
126-
$this->newProductPage->getFormPageActions()->save();
93+
$productGrid->open();
94+
$productGrid->getGridPageActionBlock()->addProduct('simple');
95+
$newProductPage->getProductForm()->fill($product, null, $category);
96+
$newProductPage->getFormPageActions()->save();
12797

12898
return ['product' => $product];
12999
}
@@ -135,7 +105,7 @@ public function testCreate($configData, array $productData, Category $category,
135105
*/
136106
public function tearDown()
137107
{
138-
ObjectManager::getInstance()->create(
108+
$this->objectManager->create(
139109
'Magento\Core\Test\TestStep\SetupConfigurationStep',
140110
['configData' => $this->configData, 'rollback' => true]
141111
)->run();

dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/CreateSimpleProductEntityTest/testCreate.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"description";"configData";"productData/url_key";"productData/name";"productData/sku";"productData/tax_class_id/dataSet";"productData/price/value";"productData/special_price";"productData/short_description";"productData/description";"productData/weight";"productData/quantity_and_stock_status/qty";"productData/quantity_and_stock_status/is_in_stock";"productData/visibility";"productData/custom_options/preset";"productData/checkout_data/preset";"productData/custom_options/import_products";"productData/price/preset";"productData/group_price/preset";"productData/tier_price/preset";"constraint";"tag"
1+
"description";"configData";"product/data/url_key";"product/data/name";"product/data/sku";"product/data/tax_class_id/dataSet";"product/data/price/value";"product/data/special_price";"product/data/short_description";"product/data/description";"product/data/weight";"product/data/quantity_and_stock_status/qty";"product/data/quantity_and_stock_status/is_in_stock";"product/data/visibility";"product/data/custom_options/preset";"product/data/checkout_data/preset";"product/data/custom_options/import_products";"product/data/price/preset";"product/data/group_price/preset";"product/data/tier_price/preset";"constraint";"tag"
22
"Create product with custom options(fixed price)";"-";"simple-product-%isolation%";"Simple Product %isolation%";"simple_sku_%isolation%";"-";"10000";"-";"Simple Product short_description %isolation%";"Simple Product description %isolation%";"50";"657";"-";"-";"drop_down_with_one_option_fixed_price";"drop_down_with_one_option_fixed_price";"-";"drop_down_with_one_option_fixed_price";"-";"-";"assertProductSaveMessage, assertProductInGrid, assertProductInCategory, assertProductPage, assertProductInCart";""
33
"Create product with custom options(percent price)";"-";"simple-product-%isolation%";"Simple Product %isolation%";"simple_sku_%isolation%";"-";"10001";"-";"Simple Product short_description %isolation%";"Simple Product description %isolation%";"51";"658";"-";"-";"drop_down_with_one_option_percent_price";"drop_down_with_one_option_percent_price";"-";"drop_down_with_one_option_percent_price";"-";"-";"assertProductSaveMessage, assertProductInGrid, assertProductInCategory, assertProductPage, assertProductInCart";""
44
"Create product with special price and custom options(fixed price)";"-";"simple-product-%isolation%";"Simple Product %isolation%";"simple_sku_%isolation%";"-";"10002";"90";"Simple Product short_description %isolation%";"Simple Product description %isolation%";"52";"659";"-";"-";"drop_down_with_one_option_fixed_price";"drop_down_with_one_option_fixed_price";"-";"MAGETWO-23029";"-";"-";"assertProductSaveMessage, assertProductInGrid, assertProductInCategory, assertProductPage, assertProductInCart";""

0 commit comments

Comments
 (0)