Skip to content

Commit 6ada614

Browse files
author
Oleksandr Manchenko
committed
MTA-1899: Re-factor price blocks
1 parent 133c332 commit 6ada614

File tree

46 files changed

+426
-513
lines changed

Some content is hidden

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

46 files changed

+426
-513
lines changed

dev/tests/functional/tests/app/Magento/Bundle/Test/Constraint/AssertBundleInCategory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ protected function assertPrice(FixtureInterface $bundle, CatalogCategoryView $ca
2929
/** @var BundleProduct $bundle */
3030
$priceData = $bundle->getDataFieldConfig('price')['source']->getPreset();
3131
//Price from/to verification
32-
$priceBlock = $catalogCategoryView->getListProductBlock()->getProductPriceBlock($bundle->getName());
32+
$priceBlock = $catalogCategoryView->getListProductBlock()->getProductItem($bundle)->getPriceBlock();
3333

3434
if ($bundle->hasData('special_price') || $bundle->hasData('group_price')) {
35-
$priceLow = $priceBlock->getFinalPrice();
35+
$priceLow = $priceBlock->getPrice();
3636
} else {
3737
$priceLow = ($bundle->getPriceView() == 'Price Range')
3838
? $priceBlock->getPriceFrom()
39-
: $priceBlock->getRegularPrice();
39+
: $priceBlock->getPrice();
4040
}
4141

4242
\PHPUnit_Framework_Assert::assertEquals(

dev/tests/functional/tests/app/Magento/Bundle/Test/Constraint/AssertBundlePriceView.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ protected function assertPrice(BundleProduct $product, CatalogProductView $catal
5050
$priceBlock = $catalogProductView->getViewBlock()->getPriceBlock();
5151

5252
if ($product->hasData('special_price') || $product->hasData('group_price')) {
53-
$priceLow = $priceBlock->getFinalPrice();
53+
$priceLow = $priceBlock->getPrice();
5454
} else {
55-
$priceLow = ($priceView == 'Price Range') ? $priceBlock->getPriceFrom() : $priceBlock->getRegularPrice();
55+
$priceLow = ($priceView == 'Price Range') ? $priceBlock->getPriceFrom() : $priceBlock->getPrice();
5656
}
5757

5858
\PHPUnit_Framework_Assert::assertEquals(

dev/tests/functional/tests/app/Magento/Bundle/Test/Constraint/AssertBundleProductPage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ protected function verifyPrice()
2727
$priceBlock = $this->productView->getPriceBlock();
2828

2929
if ($this->product->hasData('special_price') || $this->product->hasData('group_price')) {
30-
$priceLow = $priceBlock->getFinalPrice();
30+
$priceLow = $priceBlock->getPrice();
3131
} else {
32-
$priceLow = ($priceView == 'Price Range') ? $priceBlock->getPriceFrom() : $priceBlock->getRegularPrice();
32+
$priceLow = ($priceView == 'Price Range') ? $priceBlock->getPriceFrom() : $priceBlock->getPrice();
3333
}
3434

3535
$errors = [];
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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;
8+
9+
use Magento\Mtf\Block\Block;
10+
use Magento\Mtf\Client\Locator;
11+
use Magento\Mtf\Client\Element\SimpleElement;
12+
13+
/**
14+
* Base Price Block.
15+
*/
16+
abstract class AbstractPriceBlock extends Block
17+
{
18+
/**
19+
* Mapping for different type of price.
20+
*
21+
* @var array
22+
*/
23+
protected $mapTypePrices = [];
24+
25+
/**
26+
* Get specify type price.
27+
*
28+
* @param string $type
29+
* @param string $currency [optional]
30+
* @return string|null
31+
*/
32+
protected function getTypePrice($type, $currency = '$')
33+
{
34+
$typePriceElement = $this->getTypePriceElement($type);
35+
return $typePriceElement->isVisible() ? $this->escape($typePriceElement->getText(), $currency) : null;
36+
}
37+
38+
/**
39+
* Get specify type price element.
40+
*
41+
* @param string $type
42+
* @return SimpleElement
43+
*/
44+
protected function getTypePriceElement($type)
45+
{
46+
$mapTypePrice = $this->mapTypePrices[$type];
47+
return $this->_rootElement->find(
48+
$mapTypePrice['selector'],
49+
isset($mapTypePrice['strategy']) ? $mapTypePrice['strategy'] : Locator::SELECTOR_CSS
50+
);
51+
}
52+
53+
/**
54+
* Escape currency and separator for price.
55+
*
56+
* @param string $price
57+
* @param string $currency
58+
* @return string
59+
*/
60+
protected function escape($price, $currency = '$')
61+
{
62+
return str_replace([',', $currency], '', $price);
63+
}
64+
}

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

Lines changed: 3 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
use Magento\Catalog\Test\Block\Product\ProductList\ProductItem;
1010
use Magento\Mtf\Block\Block;
1111
use Magento\Mtf\Client\Locator;
12-
use Magento\Mtf\Client\Element\SimpleElement;
13-
use Magento\Mtf\Fixture\InjectableFixture;
12+
use Magento\Mtf\Fixture\FixtureInterface;
1413

1514
/**
1615
* Product list block.
@@ -24,62 +23,6 @@ class ListProduct extends Block
2423
*/
2524
protected $productItem = './/*[contains(@class,"product-item-link") and text()="%s"]/ancestor::li';
2625

27-
/**
28-
* This member holds the class name of the regular price block.
29-
*
30-
* @var string
31-
*/
32-
protected $regularPriceClass = ".regular-price";
33-
34-
/**
35-
* This member holds the class name for the price block found inside the product details.
36-
*
37-
* @var string
38-
*/
39-
protected $priceBlockClass = 'price-box';
40-
41-
/**
42-
* This member contains the selector to find the product details for the named product.
43-
*
44-
* @var string
45-
*/
46-
protected $productDetailsSelector = '//*[contains(@class, "product details") and .//*[text()="%s"]]';
47-
48-
/**
49-
* Product name.
50-
*
51-
* @var string
52-
*/
53-
protected $productTitle = './/*[@class="product name product-item-name"]/a[text()="%s"]';
54-
55-
/**
56-
* Click for Price link on category page.
57-
*
58-
* @var string
59-
*/
60-
protected $clickForPrice = "//div[contains(@class, 'product details') and ('%s')]//a[contains(@id, 'msrp-popup')]";
61-
62-
/**
63-
* Minimum Advertised Price on category page.
64-
*
65-
* @var string
66-
*/
67-
protected $oldPrice = ".old-price .price-container";
68-
69-
/**
70-
* Price box CSS selector.
71-
*
72-
* @var string
73-
*/
74-
protected $priceBox = '.price-box #product-price-%s .price';
75-
76-
/**
77-
* Popup map price.
78-
*
79-
* @var string
80-
*/
81-
protected $mapPopupPrice = '//ancestor::*[@id="map-popup-click-for-price"]';
82-
8326
/**
8427
* Sorter dropdown selector.
8528
*
@@ -90,10 +33,10 @@ class ListProduct extends Block
9033
/**
9134
* Return product item block.
9235
*
93-
* @param InjectableFixture $product
36+
* @param FixtureInterface $product
9437
* @return ProductItem
9538
*/
96-
public function getProductItem(InjectableFixture $product)
39+
public function getProductItem(FixtureInterface $product)
9740
{
9841
$locator = sprintf($this->productItem, $product->getName());
9942

@@ -103,112 +46,6 @@ public function getProductItem(InjectableFixture $product)
10346
);
10447
}
10548

106-
/**
107-
* This method returns the price box block for the named product.
108-
*
109-
* @param string $productName
110-
* @return Price
111-
*/
112-
public function getProductPriceBlock($productName)
113-
{
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)]
119-
);
120-
}
121-
122-
/**
123-
* Check if product with specified name is visible.
124-
*
125-
* @param string $productName
126-
* @return bool
127-
*/
128-
public function isProductVisible($productName)
129-
{
130-
return $this->getProductNameElement($productName)->isVisible();
131-
}
132-
133-
/**
134-
* Check if regular price is visible.
135-
*
136-
* @return bool
137-
*/
138-
public function isRegularPriceVisible()
139-
{
140-
return $this->_rootElement->find($this->regularPriceClass)->isVisible();
141-
}
142-
143-
/**
144-
* Open product view page by clicking on product name.
145-
*
146-
* @param string $productName
147-
* @return void
148-
*/
149-
public function openProductViewPage($productName)
150-
{
151-
$this->getProductNameElement($productName)->click();
152-
}
153-
154-
/**
155-
* This method returns the element representing the product details for the named product.
156-
*
157-
* @param string $productName String containing the name of the product
158-
* @return SimpleElement
159-
*/
160-
protected function getProductDetailsElement($productName)
161-
{
162-
return $this->_rootElement->find(
163-
sprintf($this->productDetailsSelector, $productName),
164-
Locator::SELECTOR_XPATH
165-
);
166-
}
167-
168-
/**
169-
* This method returns the element on the page associated with the product name.
170-
*
171-
* @param string $productName String containing the name of the product
172-
* @return SimpleElement
173-
*/
174-
protected function getProductNameElement($productName)
175-
{
176-
return $this->_rootElement->find(sprintf($this->productTitle, $productName), Locator::SELECTOR_XPATH);
177-
}
178-
179-
/**
180-
* Open MAP block on category page.
181-
*
182-
* @param string $productName
183-
* @return void
184-
*/
185-
public function openMapBlockOnCategoryPage($productName)
186-
{
187-
$this->_rootElement->find(sprintf($this->clickForPrice, $productName), Locator::SELECTOR_XPATH)->click();
188-
$this->waitForElementVisible($this->mapPopupPrice, Locator::SELECTOR_XPATH);
189-
}
190-
191-
/**
192-
* Get Minimum Advertised Price on Category page.
193-
*
194-
* @return string
195-
*/
196-
public function getOldPriceCategoryPage()
197-
{
198-
return $this->_rootElement->find($this->oldPrice, Locator::SELECTOR_CSS)->getText();
199-
}
200-
201-
/**
202-
* Retrieve product price by specified Id.
203-
*
204-
* @param int $productId
205-
* @return string
206-
*/
207-
public function getPrice($productId)
208-
{
209-
return $this->_rootElement->find(sprintf($this->priceBox, $productId), Locator::SELECTOR_CSS)->getText();
210-
}
211-
21249
/**
21350
* Get all terms used in sort.
21451
*
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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;
8+
9+
/**
10+
* Minimum Advertised Price block.
11+
*/
12+
class Map extends \Magento\Catalog\Test\Block\AbstractPriceBlock
13+
{
14+
/**
15+
* Mapping for different type of price.
16+
*
17+
* @var array
18+
*/
19+
protected $mapTypePrices = [
20+
'actual_price' => [
21+
'selector' => '.actual-price .price',
22+
],
23+
'old_price' => [
24+
'selector' => '.old-price .price-wrapper',
25+
]
26+
];
27+
28+
/**
29+
* 'Add to Cart' button.
30+
*
31+
* @var string
32+
*/
33+
protected $addToCart = '.action.tocart';
34+
35+
/**
36+
* 'Close' button.
37+
*
38+
* @var string
39+
*/
40+
protected $close = '.class="ui-dialog-buttonset .action.close';
41+
42+
/**
43+
* Get actual Price value on frontend.
44+
*
45+
* @param string $currency
46+
* @return null|string
47+
*/
48+
public function getActualPrice($currency = '$')
49+
{
50+
return $this->getTypePrice('actual_price', $currency);
51+
}
52+
53+
/**
54+
* Get old Price value on frontend.
55+
*
56+
* @param string $currency
57+
* @return null|string
58+
*/
59+
public function getOldPrice($currency = '$')
60+
{
61+
return $this->getTypePrice('old_price', $currency);
62+
}
63+
64+
/**
65+
* Add product to shopping cart from MAP Block.
66+
*
67+
* @return void
68+
*/
69+
public function addToCart()
70+
{
71+
$this->_rootElement->find($this->addToCart)->click();
72+
}
73+
74+
/**
75+
* Close MAP Block.
76+
*
77+
* @return void
78+
*/
79+
public function close()
80+
{
81+
$this->_rootElement->find($this->close)->click();
82+
$this->waitForElementNotVisible($this->close);
83+
}
84+
}

0 commit comments

Comments
 (0)