Skip to content

Commit a976f4b

Browse files
author
Oleksandr Manchenko
committed
MTA-1898: Re-factor existing tests for MAP
1 parent e5741f5 commit a976f4b

File tree

11 files changed

+491
-1
lines changed

11 files changed

+491
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ListProduct extends Block
2222
*
2323
* @var string
2424
*/
25-
protected $productItem = './/*[contains(@class,"product-item-link") and .//*[text()="%s"]]/ancestor::li';
25+
protected $productItem = './/*[contains(@class,"product-item-link") and text()="%s"]/ancestor::li';
2626

2727
/**
2828
* This member holds the class name of the regular price block.

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

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

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

9+
use Magento\Catalog\Test\Block\Product\Price;
910
use Magento\Mtf\Block\Block;
1011
use Magento\Mtf\Client\Locator;
1112

@@ -21,6 +22,13 @@ class ProductItem extends Block
2122
*/
2223
protected $link = 'a.product-item-link';
2324

25+
/**
26+
* Locator for price box.
27+
*
28+
* @var string
29+
*/
30+
protected $priceBox = '.price-box';
31+
2432
/**
2533
* 'Add to Card' button.
2634
*
@@ -58,6 +66,19 @@ public function getProductName()
5866
return trim($this->_rootElement->find($this->link)->getText());
5967
}
6068

69+
/**
70+
* Return price block.
71+
*
72+
* @return Price
73+
*/
74+
public function getPriceBlock()
75+
{
76+
return $this->blockFactory->create(
77+
'Magento\Catalog\Test\Block\Product\Price',
78+
['element' => $this->_rootElement->find($this->priceBox)]
79+
);
80+
}
81+
6182
/**
6283
* Checking that "Add to Card" button is visible
6384
*

dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Fixture/ConfigurableProduct/ConfigurableAttributesData.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,33 @@ class ConfigurableAttributesData implements FixtureInterface
204204
],
205205
],
206206

207+
'one_variation_one_dollar' => [
208+
'attributes_data' => [
209+
'attribute_key_0' => [
210+
'options' => [
211+
'option_key_0' => [
212+
'pricing_value' => 1.00,
213+
'include' => 'Yes',
214+
'is_percent' => 'No',
215+
],
216+
],
217+
],
218+
],
219+
'products' => [],
220+
'attributes' => [
221+
'attribute_key_0' => 'catalogProductAttribute::attribute_type_dropdown_one_option',
222+
],
223+
'matrix' => [
224+
'attribute_key_0:option_key_0' => [
225+
'display' => 'Yes',
226+
'quantity_and_stock_status' => [
227+
'qty' => 10,
228+
],
229+
'weight' => 1,
230+
],
231+
],
232+
],
233+
207234
'two_options' => [
208235
'attributes_data' => [
209236
'attribute_key_0' => [
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Msrp\Test\Constraint;
8+
9+
use Magento\Mtf\Constraint\AbstractConstraint;
10+
use Magento\Cms\Test\Page\CmsIndex;
11+
use Magento\Catalog\Test\Page\Category\CatalogCategoryView;
12+
use Magento\Catalog\Test\Page\Product\CatalogProductView;
13+
use Magento\Mtf\Fixture\InjectableFixture;
14+
use Magento\Catalog\Test\Fixture\CatalogProductSimple;
15+
use Magento\Checkout\Test\Page\CheckoutCart;
16+
17+
/**
18+
* Assert product MAP related data in Shopping Cart.
19+
*/
20+
class AssertMsrpInShoppingCart extends AbstractConstraint
21+
{
22+
/**
23+
* Assert product MAP related data in Shopping Cart.
24+
*
25+
* @param CmsIndex $cmsIndex
26+
* @param CatalogCategoryView $catalogCategoryView
27+
* @param CatalogProductView $catalogProductView
28+
* @param CheckoutCart $checkoutCart
29+
* @param InjectableFixture $product
30+
* @return void
31+
*/
32+
public function processAssert(
33+
CmsIndex $cmsIndex,
34+
CatalogCategoryView $catalogCategoryView,
35+
CatalogProductView $catalogProductView,
36+
CheckoutCart $checkoutCart,
37+
InjectableFixture $product
38+
) {
39+
/** @var CatalogProductSimple $product */
40+
$cmsIndex->open();
41+
$cmsIndex->getTopmenu()->selectCategoryByName($product->getCategoryIds()[0]);
42+
$catalogCategoryView->getListProductBlock()->getProductItem($product)->open();
43+
44+
if ($product->hasData('checkout_data')) {
45+
$catalogProductView->getViewBlock()->addToCart($product);
46+
} else {
47+
$catalogProductView->getViewBlock()->openMapBlockOnProductPage();
48+
$catalogProductView->getMapBlock()->addToCartFromMap();
49+
}
50+
$catalogProductView->getMessagesBlock()->waitSuccessMessage();
51+
52+
$checkoutCart->open();
53+
sleep(3);
54+
$productPrice = $product->hasData('checkout_data')
55+
? $product->getCheckoutData()['cartItem']['price']
56+
: $product->getPrice();
57+
$unitPrice = $checkoutCart->getCartBlock()->getCartItem($product)->getPrice();
58+
\PHPUnit_Framework_Assert::assertEquals($productPrice, $unitPrice, 'Incorrect unit price is displayed in Cart');
59+
}
60+
61+
/**
62+
* Return string representation of object.
63+
*
64+
* @return string
65+
* @return string
66+
*/
67+
public function toString()
68+
{
69+
return "Displayed Product MAP data in Shopping Cart is correct.";
70+
}
71+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Msrp\Test\Constraint;
8+
9+
use Magento\Catalog\Test\Fixture\CatalogProductSimple;
10+
use Magento\Cms\Test\Page\CmsIndex;
11+
use Magento\Mtf\Constraint\AbstractConstraint;
12+
use Magento\Mtf\Fixture\InjectableFixture;
13+
use Magento\Catalog\Test\Page\Category\CatalogCategoryView;
14+
15+
/**
16+
* Assert product MAP related data on category page.
17+
*/
18+
class AssertMsrpOnCategoryPage extends AbstractConstraint
19+
{
20+
/**
21+
* Assert product MAP related data on category page.
22+
*
23+
* @param CmsIndex $cmsIndex
24+
* @param CatalogCategoryView $catalogCategoryView
25+
* @param InjectableFixture $product
26+
* @return void
27+
*/
28+
public function processAssert(
29+
CmsIndex $cmsIndex,
30+
CatalogCategoryView $catalogCategoryView,
31+
InjectableFixture $product
32+
) {
33+
/** @var CatalogProductSimple $product */
34+
$cmsIndex->open();
35+
$cmsIndex->getTopmenu()->selectCategoryByName($product->getCategoryIds()[0]);
36+
37+
$productBlock = $catalogCategoryView->getListProductBlock()->getProductItem($product);
38+
\PHPUnit_Framework_Assert::assertTrue(
39+
$productBlock->isVisible(),
40+
'Product is invisible on Category page'
41+
);
42+
43+
$priceBlock = $productBlock->getPriceBlock();
44+
\PHPUnit_Framework_Assert::assertEquals(
45+
$product->getMsrp(),
46+
$priceBlock->getOldPrice(),
47+
'Displayed on Category page MAP is incorrect'
48+
);
49+
\PHPUnit_Framework_Assert::assertFalse(
50+
$priceBlock->isRegularPriceVisible(),
51+
'Regular price on Category page is visible and not expected.'
52+
);
53+
54+
$catalogCategoryView->getListProductBlock()->openMapBlockOnCategoryPage($product->getName());
55+
$mapBlock = $catalogCategoryView->getMapBlock();
56+
\PHPUnit_Framework_Assert::assertContains(
57+
$product->getMsrp(),
58+
$mapBlock->getMapOldPrice(),
59+
'Displayed on Category page MAP is incorrect'
60+
);
61+
\PHPUnit_Framework_Assert::assertEquals(
62+
$product->getPrice(),
63+
$mapBlock->getActualPrice(),
64+
'Displayed on Category page price is incorrect'
65+
);
66+
}
67+
68+
/**
69+
* Return string representation of object.
70+
*
71+
* @return string
72+
*/
73+
public function toString()
74+
{
75+
return "Displayed Product MAP data on category page is correct.";
76+
}
77+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Msrp\Test\Constraint;
8+
9+
use Magento\Cms\Test\Page\CmsIndex;
10+
use Magento\Catalog\Test\Page\Category\CatalogCategoryView;
11+
use Magento\Mtf\Constraint\AbstractConstraint;
12+
use Magento\Mtf\Fixture\InjectableFixture;
13+
use Magento\Catalog\Test\Fixture\CatalogProductSimple;
14+
use Magento\Catalog\Test\Page\Product\CatalogProductView;
15+
16+
/**
17+
* Assert product MAP related data on product view page.
18+
*/
19+
class AssertMsrpOnProductView extends AbstractConstraint
20+
{
21+
/**
22+
* Assert product MAP related data on product view page.
23+
*
24+
* @param CmsIndex $cmsIndex
25+
* @param CatalogCategoryView $catalogCategoryView
26+
* @param CatalogProductView $catalogProductView
27+
* @param InjectableFixture $product
28+
* @return void
29+
*/
30+
public function processAssert(
31+
CmsIndex $cmsIndex,
32+
CatalogCategoryView $catalogCategoryView,
33+
CatalogProductView $catalogProductView,
34+
InjectableFixture $product
35+
) {
36+
/** @var CatalogProductSimple $product */
37+
$cmsIndex->open();
38+
$cmsIndex->getTopmenu()->selectCategoryByName($product->getCategoryIds()[0]);
39+
$catalogCategoryView->getListProductBlock()->getProductItem($product)->open();
40+
41+
$priceBlock = $catalogProductView->getViewBlock()->getPriceBlock();
42+
\PHPUnit_Framework_Assert::assertEquals(
43+
$product->getMsrp(),
44+
$priceBlock->getOldPrice(),
45+
'Displayed on Product view page MAP is incorrect'
46+
);
47+
\PHPUnit_Framework_Assert::assertFalse(
48+
$priceBlock->isRegularPriceVisible(),
49+
'Regular price on Product view page is visible and not expected.'
50+
);
51+
52+
$catalogProductView->getViewBlock()->openMapBlockOnProductPage();
53+
$mapBlock = $catalogProductView->getMapBlock();
54+
\PHPUnit_Framework_Assert::assertContains(
55+
$product->getMsrp(),
56+
$mapBlock->getMapOldPrice(),
57+
'Displayed on Product view page MAP is incorrect'
58+
);
59+
\PHPUnit_Framework_Assert::assertEquals(
60+
$product->getPrice(),
61+
$mapBlock->getActualPrice(),
62+
'Displayed on Product view page price is incorrect'
63+
);
64+
}
65+
66+
/**
67+
* Return string representation of object.
68+
*
69+
* @return string
70+
*/
71+
public function toString()
72+
{
73+
return "Displayed Product MAP data on product view page is correct.";
74+
}
75+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?xml version="1.0" ?>
2+
<!--
3+
/**
4+
* Copyright © 2015 Magento. 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/Magento/Mtf/Repository/etc/repository.xsd">
9+
<repository class="Magento\Catalog\Test\Repository\CatalogProductSimple">
10+
<dataset name="with_msrp">
11+
<field name="attribute_set_id" xsi:type="array">
12+
<item name="dataSet" xsi:type="string">default</item>
13+
</field>
14+
<field name="name" xsi:type="string">Simple Product with msrp %isolation%</field>
15+
<field name="sku" xsi:type="string">sku_simple_product_with_msrp_%isolation%</field>
16+
<field name="weight" xsi:type="string">1</field>
17+
<field name="quantity_and_stock_status" xsi:type="array">
18+
<item name="qty" xsi:type="string">25</item>
19+
<item name="is_in_stock" xsi:type="string">In Stock</item>
20+
</field>
21+
<field name="price" xsi:type="array">
22+
<item name="value" xsi:type="string">560</item>
23+
<item name="preset" xsi:type="string">-</item>
24+
</field>
25+
<field name="tax_class_id" xsi:type="array">
26+
<item name="dataSet" xsi:type="string">taxable_goods</item>
27+
</field>
28+
<field name="website_ids" xsi:type="array">
29+
<item name="0" xsi:type="string">Main Website</item>
30+
</field>
31+
<field name="visibility" xsi:type="string">Catalog, Search</field>
32+
<field name="checkout_data" xsi:type="array">
33+
<item name="preset" xsi:type="string">order_default</item>
34+
</field>
35+
<field name="msrp" xsi:type="string">600</field>
36+
<field name="msrp_display_actual_price_type" xsi:type="string">Before Order Confirmation</field>
37+
</dataset>
38+
39+
<dataset name="simple_with_map">
40+
<field name="name" xsi:type="string">Simple Product with msrp %isolation%</field>
41+
<field name="url_key" xsi:type="string">simple-product-with-msrp-%isolation%</field>
42+
<field name="sku" xsi:type="string">sku_simple_product_with_msrp_%isolation%</field>
43+
<field name="weight" xsi:type="string">1</field>
44+
<field name="quantity_and_stock_status" xsi:type="array">
45+
<item name="qty" xsi:type="string">1000</item>
46+
<item name="is_in_stock" xsi:type="string">In Stock</item>
47+
</field>
48+
<field name="price" xsi:type="array">
49+
<item name="value" xsi:type="string">10</item>
50+
<item name="preset" xsi:type="string">-</item>
51+
</field>
52+
<field name="category_ids" xsi:type="array">
53+
<item name="presets" xsi:type="string">default_subcategory</item>
54+
</field>
55+
<field name="tax_class_id" xsi:type="array">
56+
<item name="dataSet" xsi:type="string">taxable_goods</item>
57+
</field>
58+
<field name="website_ids" xsi:type="array">
59+
<item name="0" xsi:type="string">Main Website</item>
60+
</field>
61+
<field name="stock_data" xsi:type="array">
62+
<item name="manage_stock" xsi:type="string">No</item>
63+
</field>
64+
<field name="msrp" xsi:type="string">15</field>
65+
<field name="msrp_display_actual_price_type" xsi:type="string">On Gesture</field>
66+
</dataset>
67+
</repository>
68+
</config>

0 commit comments

Comments
 (0)