Skip to content

Commit f575063

Browse files
author
Dmytro Aponasenko
committed
Merge branch 'MTA-551' of https://github.corp.ebay.com/magento-qmt/magento2ce into develop
2 parents b4a1072 + c83fd90 commit f575063

File tree

7 files changed

+160
-217
lines changed

7 files changed

+160
-217
lines changed

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

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,24 @@
66

77
namespace Magento\Catalog\Test\Block\Product;
88

9+
use Magento\Catalog\Test\Block\Product\ProductList\ProductItem;
910
use Magento\Mtf\Block\Block;
1011
use Magento\Mtf\Client\Locator;
1112
use Magento\Mtf\Client\Element\SimpleElement;
12-
use Magento\Mtf\Factory\Factory;
13+
use Magento\Mtf\Fixture\InjectableFixture;
1314

1415
/**
15-
* Product list.
16+
* Product list block.
1617
*/
1718
class ListProduct extends Block
1819
{
20+
/**
21+
* Locator for product item block.
22+
*
23+
* @var string
24+
*/
25+
protected $productItem = './/*[contains(@class,"product-item-link") and @title="%s"]/ancestor::li';
26+
1927
/**
2028
* This member holds the class name of the regular price block.
2129
*
@@ -58,13 +66,6 @@ class ListProduct extends Block
5866
*/
5967
protected $oldPrice = ".old-price .price-container";
6068

61-
/**
62-
* 'Add to Card' button.
63-
*
64-
* @var string
65-
*/
66-
protected $addToCard = "button.action.tocart";
67-
6869
/**
6970
* Price box CSS selector.
7071
*
@@ -86,16 +87,35 @@ class ListProduct extends Block
8687
*/
8788
protected $sorter = '#sorter';
8889

90+
/**
91+
* Return product item block.
92+
*
93+
* @param InjectableFixture $product
94+
* @return ProductItem
95+
*/
96+
public function getProductItem(InjectableFixture $product)
97+
{
98+
$locator = sprintf($this->productItem, $product->getName());
99+
100+
return $this->blockFactory->create(
101+
'Magento\Catalog\Test\Block\Product\ProductList\ProductItem',
102+
['element' => $this->_rootElement->find($locator, Locator::SELECTOR_XPATH)]
103+
);
104+
}
105+
89106
/**
90107
* This method returns the price box block for the named product.
91108
*
92-
* @param string $productName String containing the name of the product to find.
109+
* @param string $productName
93110
* @return Price
94111
*/
95112
public function getProductPriceBlock($productName)
96113
{
97-
return Factory::getBlockFactory()->getMagentoCatalogProductPrice(
98-
$this->getProductDetailsElement($productName)->find($this->priceBlockClass, Locator::SELECTOR_CLASS_NAME)
114+
$productDetails = $this->getProductDetailsElement($productName);
115+
116+
return $this->blockFactory->create(
117+
'Magento\Catalog\Test\Block\Product\Price',
118+
['element' => $productDetails->find($this->priceBlockClass, Locator::SELECTOR_CLASS_NAME)]
99119
);
100120
}
101121

@@ -186,18 +206,7 @@ public function getOldPriceCategoryPage()
186206
*/
187207
public function getPrice($productId)
188208
{
189-
return $this->_rootElement->find(sprintf($this->priceBox, $productId), Locator::SELECTOR_CSS)
190-
->getText();
191-
}
192-
193-
/**
194-
* Check 'Add To Card' button availability.
195-
*
196-
* @return bool
197-
*/
198-
public function checkAddToCardButton()
199-
{
200-
return $this->_rootElement->find($this->addToCard, Locator::SELECTOR_CSS)->isVisible();
209+
return $this->_rootElement->find(sprintf($this->priceBox, $productId), Locator::SELECTOR_CSS)->getText();
201210
}
202211

203212
/**
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Test\Block\Product\ProductList;
8+
9+
use Magento\Mtf\Block\Block;
10+
use Magento\Mtf\Client\Locator;
11+
12+
/**
13+
* Product item block on frontend category view.
14+
*/
15+
class ProductItem extends Block
16+
{
17+
/**
18+
* 'Add to Card' button.
19+
*
20+
* @var string
21+
*/
22+
protected $addToCard = "button.action.tocart";
23+
24+
/**
25+
* Checking that "Add to Card" button is visible
26+
*
27+
* @return bool
28+
*/
29+
public function isVisibleAddToCardButton()
30+
{
31+
return $this->_rootElement->find($this->addToCard, Locator::SELECTOR_CSS)->isVisible();
32+
}
33+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ public function openMapBlockOnProductPage()
351351
*
352352
* @return bool
353353
*/
354-
public function checkAddToCardButton()
354+
public function isVisibleAddToCardButton()
355355
{
356356
return $this->_rootElement->find($this->addToCart, Locator::SELECTOR_CSS)->isVisible();
357357
}

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

Lines changed: 20 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
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
/**
16-
* Class AssertAddToCartButtonAbsent
17-
* Checks the button on the category/product pages
17+
* Checks the button on the category/product pages.
1818
*/
1919
class AssertAddToCartButtonAbsent extends AbstractConstraint
2020
{
@@ -23,95 +23,46 @@ class AssertAddToCartButtonAbsent extends AbstractConstraint
2323
/* end tags */
2424

2525
/**
26-
* Category Page
27-
*
28-
* @var CatalogCategoryView
29-
*/
30-
protected $catalogCategoryView;
31-
32-
/**
33-
* Index Page
34-
*
35-
* @var CmsIndex
36-
*/
37-
protected $cmsIndex;
38-
39-
/**
40-
* Product simple fixture
41-
*
42-
* @var CatalogProductSimple
43-
*/
44-
protected $product;
45-
46-
/**
47-
* Product Page on Frontend
48-
*
49-
* @var CatalogProductView
50-
*/
51-
protected $catalogProductView;
52-
53-
/**
54-
* Assert that "Add to cart" button is not display on page
26+
* Assert that "Add to cart" button is not display on page.
5527
*
28+
* @param InjectableFixture $product
29+
* @param Category $category
5630
* @param CmsIndex $cmsIndex
5731
* @param CatalogCategoryView $catalogCategoryView
58-
* @param CatalogProductSimple $product
5932
* @param CatalogProductView $catalogProductView
6033
*
6134
* @return void
6235
*/
6336
public function processAssert(
37+
InjectableFixture $product,
38+
Category $category,
6439
CmsIndex $cmsIndex,
6540
CatalogCategoryView $catalogCategoryView,
66-
CatalogProductSimple $product,
6741
CatalogProductView $catalogProductView
6842
) {
69-
$this->catalogCategoryView = $catalogCategoryView;
70-
$this->cmsIndex = $cmsIndex;
71-
$this->product = $product;
72-
$this->catalogProductView = $catalogProductView;
43+
$cmsIndex->open();
44+
$cmsIndex->getTopmenu()->selectCategoryByName($category->getName());
7345

74-
$this->addToCardAbsentOnCategory();
75-
$this->addToCardAbsentOnProduct();
76-
}
46+
$isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product->getName());
47+
while (!$isProductVisible && $catalogCategoryView->getBottomToolbar()->nextPage()) {
48+
$isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product->getName());
49+
}
50+
\PHPUnit_Framework_Assert::assertTrue($isProductVisible, 'Product is absent on category page.');
7751

78-
/**
79-
* "Add to cart" button is not displayed on Category page
80-
*
81-
* @return void
82-
*/
83-
protected function addToCardAbsentOnCategory()
84-
{
85-
$this->cmsIndex->open();
86-
$this->cmsIndex->getTopmenu()->selectCategoryByName(
87-
$this->product->getCategoryIds()[0]
88-
);
8952
\PHPUnit_Framework_Assert::assertFalse(
90-
$this->catalogCategoryView->getListProductBlock()->checkAddToCardButton(),
91-
"Button 'Add to Card' is present on Category page"
53+
$catalogCategoryView->getListProductBlock()->getProductItem($product)->isVisibleAddToCardButton(),
54+
"Button 'Add to Card' is present on Category page."
9255
);
93-
}
9456

95-
/**
96-
* "Add to cart" button is not display on Product page
97-
*
98-
* @return void
99-
*/
100-
protected function addToCardAbsentOnProduct()
101-
{
102-
$this->cmsIndex->open();
103-
$this->cmsIndex->getTopmenu()->selectCategoryByName(
104-
$this->product->getCategoryIds()[0]
105-
);
106-
$this->catalogCategoryView->getListProductBlock()->openProductViewPage($this->product->getName());
57+
$catalogCategoryView->getListProductBlock()->openProductViewPage($product->getName());
10758
\PHPUnit_Framework_Assert::assertFalse(
108-
$this->catalogProductView->getViewBlock()->checkAddToCardButton(),
59+
$catalogProductView->getViewBlock()->isVisibleAddToCardButton(),
10960
"Button 'Add to Card' is present on Product page."
11061
);
11162
}
11263

11364
/**
114-
* Text absent button "Add to Cart" on the category/product pages
65+
* Text absent button "Add to Cart" on the category/product pages.
11566
*
11667
* @return string
11768
*/

0 commit comments

Comments
 (0)