Skip to content

Commit 1a45542

Browse files
authored
Merge pull request #1035 from magento-fearless-kiwis/MAGETWO-63116_JSON_ERROR
MAGETWO-63116: [GitHub] Quotes in product name causes JSON error on product page MAP What's This Popup #8059
2 parents f86fa3f + 110c0a4 commit 1a45542

File tree

8 files changed

+182
-40
lines changed

8 files changed

+182
-40
lines changed

app/code/Magento/Msrp/view/base/templates/product/price/msrp.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ if ($product->isSaleable()) {
9595
class="action map-show-info"
9696
data-mage-init='{"addToCart":{"origin": "info",
9797
"helpLinkId": "#<?php /* @escapeNotVerified */ echo $helpLinkId;?>",
98-
"productName": "<?php /* @escapeNotVerified */ echo $product->getName() ?>",
98+
"productName": "<?php echo $block->escapeJs($block->escapeHtml($product->getName())) ?>",
9999
"closeButtonId": "#map-popup-close"}}'><span><?php /* @escapeNotVerified */ echo __("What's this?"); ?></span>
100100
</a>
101101
<?php endif; ?>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. 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 AssertMapOnCategoryPage 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->getMsrpListProductBlock()->getProductItem($product);
38+
$productBlock->openMapBlock();
39+
$mapBlock = $productBlock->getMapBlock();
40+
\PHPUnit_Framework_Assert::assertEquals(
41+
$product->getMsrp(),
42+
$mapBlock->getOldPrice(),
43+
'Displayed on Category page MAP is incorrect.'
44+
);
45+
$priceData = $product->getDataFieldConfig('price')['source']->getPriceData();
46+
$price = isset($priceData['category_price']) ? $priceData['category_price'] : $product->getPrice();
47+
\PHPUnit_Framework_Assert::assertEquals(
48+
$price,
49+
$mapBlock->getActualPrice(),
50+
'Displayed on Category page price is incorrect.'
51+
);
52+
}
53+
54+
/**
55+
* Return string representation of object.
56+
*
57+
* @return string
58+
*/
59+
public function toString()
60+
{
61+
return "Displayed Product MAP data on category page is correct.";
62+
}
63+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. 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 AssertMapOnProductView 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+
$viewBlock = $catalogProductView->getMsrpViewBlock();
42+
$viewBlock->openMapBlock();
43+
$mapBlock = $viewBlock->getMapBlock();
44+
\PHPUnit_Framework_Assert::assertContains(
45+
$product->getMsrp(),
46+
$mapBlock->getOldPrice(),
47+
'Displayed on Product view page MAP is incorrect.'
48+
);
49+
$priceData = $product->getDataFieldConfig('price')['source']->getPriceData();
50+
$price = isset($priceData['category_price']) ? $priceData['category_price'] : $product->getPrice();
51+
\PHPUnit_Framework_Assert::assertEquals(
52+
$price,
53+
$mapBlock->getActualPrice(),
54+
'Displayed on Product view page price is incorrect.'
55+
);
56+
}
57+
58+
/**
59+
* Return string representation of object.
60+
*
61+
* @return string
62+
*/
63+
public function toString()
64+
{
65+
return "Displayed Product MAP data on product view page is correct.";
66+
}
67+
}

dev/tests/functional/tests/app/Magento/Msrp/Test/Constraint/AssertMsrpInShoppingCart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function processAssert(
4141
$cmsIndex->getTopmenu()->selectCategoryByName($product->getCategoryIds()[0]);
4242
$catalogCategoryView->getListProductBlock()->getProductItem($product)->open();
4343

44-
if ($product->hasData('checkout_data')) {
44+
if ($product->hasData('checkout_data') || $product->getMsrpDisplayActualPriceType() === 'In Cart') {
4545
$catalogProductView->getViewBlock()->addToCart($product);
4646
} else {
4747
$catalogProductView->getMsrpViewBlock()->openMapBlock();

dev/tests/functional/tests/app/Magento/Msrp/Test/Constraint/AssertMsrpOnCategoryPage.php

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
use Magento\Catalog\Test\Page\Category\CatalogCategoryView;
1414

1515
/**
16-
* Assert product MAP related data on category page.
16+
* Assert product MSRP related data on category page.
1717
*/
1818
class AssertMsrpOnCategoryPage extends AbstractConstraint
1919
{
2020
/**
21-
* Assert product MAP related data on category page.
21+
* Assert product MSRP related data on category page.
2222
*
2323
* @param CmsIndex $cmsIndex
2424
* @param CatalogCategoryView $catalogCategoryView
@@ -44,27 +44,12 @@ public function processAssert(
4444
\PHPUnit_Framework_Assert::assertEquals(
4545
$product->getMsrp(),
4646
$priceBlock->getOldPrice(),
47-
'Displayed on Category page MAP is incorrect.'
47+
'Displayed on Category page MSRP is incorrect.'
4848
);
4949
\PHPUnit_Framework_Assert::assertFalse(
5050
$priceBlock->isRegularPriceVisible(),
5151
'Regular price on Category page is visible and not expected.'
5252
);
53-
54-
$productBlock->openMapBlock();
55-
$mapBlock = $productBlock->getMapBlock();
56-
\PHPUnit_Framework_Assert::assertEquals(
57-
$product->getMsrp(),
58-
$mapBlock->getOldPrice(),
59-
'Displayed on Category page MAP is incorrect.'
60-
);
61-
$priceData = $product->getDataFieldConfig('price')['source']->getPriceData();
62-
$price = isset($priceData['category_price']) ? $priceData['category_price'] : $product->getPrice();
63-
\PHPUnit_Framework_Assert::assertEquals(
64-
$price,
65-
$mapBlock->getActualPrice(),
66-
'Displayed on Category page price is incorrect.'
67-
);
6853
}
6954

7055
/**
@@ -74,6 +59,6 @@ public function processAssert(
7459
*/
7560
public function toString()
7661
{
77-
return "Displayed Product MAP data on category page is correct.";
62+
return "Displayed Product MSRP data on category page is correct.";
7863
}
7964
}

dev/tests/functional/tests/app/Magento/Msrp/Test/Constraint/AssertMsrpOnProductView.php

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
use Magento\Catalog\Test\Page\Product\CatalogProductView;
1515

1616
/**
17-
* Assert product MAP related data on product view page.
17+
* Assert product MSRP related data on product view page.
1818
*/
1919
class AssertMsrpOnProductView extends AbstractConstraint
2020
{
2121
/**
22-
* Assert product MAP related data on product view page.
22+
* Assert product MSRP related data on product view page.
2323
*
2424
* @param CmsIndex $cmsIndex
2525
* @param CatalogCategoryView $catalogCategoryView
@@ -43,27 +43,12 @@ public function processAssert(
4343
\PHPUnit_Framework_Assert::assertEquals(
4444
$product->getMsrp(),
4545
$priceBlock->getOldPrice(),
46-
'Displayed on Product view page MAP is incorrect'
46+
'Displayed on Product view page MSRP is incorrect'
4747
);
4848
\PHPUnit_Framework_Assert::assertFalse(
4949
$priceBlock->isRegularPriceVisible(),
5050
'Regular price on Product view page is visible and not expected.'
5151
);
52-
53-
$viewBlock->openMapBlock();
54-
$mapBlock = $viewBlock->getMapBlock();
55-
\PHPUnit_Framework_Assert::assertContains(
56-
$product->getMsrp(),
57-
$mapBlock->getOldPrice(),
58-
'Displayed on Product view page MAP is incorrect.'
59-
);
60-
$priceData = $product->getDataFieldConfig('price')['source']->getPriceData();
61-
$price = isset($priceData['category_price']) ? $priceData['category_price'] : $product->getPrice();
62-
\PHPUnit_Framework_Assert::assertEquals(
63-
$price,
64-
$mapBlock->getActualPrice(),
65-
'Displayed on Product view page price is incorrect.'
66-
);
6752
}
6853

6954
/**
@@ -73,6 +58,6 @@ public function processAssert(
7358
*/
7459
public function toString()
7560
{
76-
return "Displayed Product MAP data on product view page is correct.";
61+
return "Displayed Product MSRP data on product view page is correct.";
7762
}
7863
}

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,37 @@
7070
<field name="msrp" xsi:type="string">15</field>
7171
<field name="msrp_display_actual_price_type" xsi:type="string">On Gesture</field>
7272
</dataset>
73+
74+
<dataset name="msrp_display_actual_price_in_cart_with_quotes_in_product_name">
75+
<field name="name" xsi:type="string">\'Simple Product with\' msrp %isolation%</field>
76+
<field name="url_key" xsi:type="string">simple-product-with-msrp-%isolation%</field>
77+
<field name="sku" xsi:type="string">sku_simple_product_with_msrp_%isolation%</field>
78+
<field name="weight" xsi:type="string">1</field>
79+
<field name="product_has_weight" xsi:type="string">This item has weight</field>
80+
<field name="quantity_and_stock_status" xsi:type="array">
81+
<item name="qty" xsi:type="string">1000</item>
82+
<item name="is_in_stock" xsi:type="string">In Stock</item>
83+
</field>
84+
<field name="price" xsi:type="array">
85+
<item name="value" xsi:type="string">10</item>
86+
<item name="dataset" xsi:type="string">-</item>
87+
</field>
88+
<field name="category_ids" xsi:type="array">
89+
<item name="dataset" xsi:type="string">default_subcategory</item>
90+
</field>
91+
<field name="tax_class_id" xsi:type="array">
92+
<item name="dataset" xsi:type="string">taxable_goods</item>
93+
</field>
94+
<field name="website_ids" xsi:type="array">
95+
<item name="0" xsi:type="array">
96+
<item name="dataset" xsi:type="string">default</item>
97+
</item>
98+
</field>
99+
<field name="stock_data" xsi:type="array">
100+
<item name="manage_stock" xsi:type="string">No</item>
101+
</field>
102+
<field name="msrp" xsi:type="string">15</field>
103+
<field name="msrp_display_actual_price_type" xsi:type="string">In Cart</field>
104+
</dataset>
73105
</repository>
74106
</config>

dev/tests/functional/tests/app/Magento/Msrp/Test/TestCase/ApplyMapTest.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,23 @@
1010
<variation name="ApplyMapTestVariation1" summary="Apply Minimum Advertised Price Setting to Simple Product" ticketId="MAGETWO-12430">
1111
<data name="product" xsi:type="string">catalogProductSimple::msrp_on_gesture</data>
1212
<constraint name="Magento\Msrp\Test\Constraint\AssertMsrpOnCategoryPage" />
13+
<constraint name="Magento\Msrp\Test\Constraint\AssertMapOnCategoryPage" />
1314
<constraint name="Magento\Msrp\Test\Constraint\AssertMsrpOnProductView" />
15+
<constraint name="Magento\Msrp\Test\Constraint\AssertMapOnProductView" />
1416
<constraint name="Magento\Msrp\Test\Constraint\AssertMsrpInShoppingCart" />
1517
</variation>
1618
<variation name="ApplyMapTestVariation2" summary="Apply Minimum Advertised Price to the Configurable Product" ticketId="MAGETWO-12847">
1719
<data name="product" xsi:type="string">configurableProduct::msrp_on_gesture_one_variation</data>
1820
<data name="tag" xsi:type="string">test_type:acceptance_test, test_type:extended_acceptance_test</data>
1921
<constraint name="Magento\Msrp\Test\Constraint\AssertMsrpOnCategoryPage" />
22+
<constraint name="Magento\Msrp\Test\Constraint\AssertMapOnCategoryPage" />
23+
<constraint name="Magento\Msrp\Test\Constraint\AssertMsrpOnProductView" />
24+
<constraint name="Magento\Msrp\Test\Constraint\AssertMapOnProductView" />
25+
<constraint name="Magento\Msrp\Test\Constraint\AssertMsrpInShoppingCart" />
26+
</variation>
27+
<variation name="ApplyMapTestVariation3" summary="Apply Minimum Advertised Price to Simple Product with Quotes in product name" ticketId="MAGETWO-67491">
28+
<data name="product" xsi:type="string">catalogProductSimple::msrp_display_actual_price_in_cart_with_quotes_in_product_name</data>
29+
<constraint name="Magento\Msrp\Test\Constraint\AssertMsrpOnCategoryPage" />
2030
<constraint name="Magento\Msrp\Test\Constraint\AssertMsrpOnProductView" />
2131
<constraint name="Magento\Msrp\Test\Constraint\AssertMsrpInShoppingCart" />
2232
</variation>

0 commit comments

Comments
 (0)