From f266c3c3fb7971ddb1149f6c4fa6f86b8d70438b Mon Sep 17 00:00:00 2001 From: Venkata Uppalapati Date: Thu, 13 Apr 2017 14:46:42 -0500 Subject: [PATCH 1/3] MAGETWO-63116: [GitHub] Quotes in product name causes JSON error on product page MAP What's This Popup #8059 - Escape strings inside JavaScript context. - Added functional test variation to cover the bug. --- .../base/templates/product/price/msrp.phtml | 2 +- .../Constraint/AssertMapOnCategoryPage.php | 63 +++++++++++++++++ .../Constraint/AssertMapOnProductView.php | 67 +++++++++++++++++++ .../Constraint/AssertMsrpInShoppingCart.php | 2 +- .../Constraint/AssertMsrpOnCategoryPage.php | 23 ++----- .../Constraint/AssertMsrpOnProductView.php | 23 ++----- .../Test/Repository/CatalogProductSimple.xml | 32 +++++++++ .../Msrp/Test/TestCase/ApplyMapTest.xml | 10 +++ 8 files changed, 182 insertions(+), 40 deletions(-) create mode 100644 dev/tests/functional/tests/app/Magento/Msrp/Test/Constraint/AssertMapOnCategoryPage.php create mode 100644 dev/tests/functional/tests/app/Magento/Msrp/Test/Constraint/AssertMapOnProductView.php diff --git a/app/code/Magento/Msrp/view/base/templates/product/price/msrp.phtml b/app/code/Magento/Msrp/view/base/templates/product/price/msrp.phtml index 3c27b6ca71b87..1e2642d85b09e 100644 --- a/app/code/Magento/Msrp/view/base/templates/product/price/msrp.phtml +++ b/app/code/Magento/Msrp/view/base/templates/product/price/msrp.phtml @@ -95,7 +95,7 @@ if ($product->isSaleable()) { class="action map-show-info" data-mage-init='{"addToCart":{"origin": "info", "helpLinkId": "#", - "productName": "getName() ?>", + "productName": "escapeJs($block->escapeHtml($product->getName())) ?>", "closeButtonId": "#map-popup-close"}}'> diff --git a/dev/tests/functional/tests/app/Magento/Msrp/Test/Constraint/AssertMapOnCategoryPage.php b/dev/tests/functional/tests/app/Magento/Msrp/Test/Constraint/AssertMapOnCategoryPage.php new file mode 100644 index 0000000000000..734c06b003d3e --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Msrp/Test/Constraint/AssertMapOnCategoryPage.php @@ -0,0 +1,63 @@ +open(); + $cmsIndex->getTopmenu()->selectCategoryByName($product->getCategoryIds()[0]); + + $productBlock = $catalogCategoryView->getMsrpListProductBlock()->getProductItem($product); + $productBlock->openMapBlock(); + $mapBlock = $productBlock->getMapBlock(); + \PHPUnit_Framework_Assert::assertEquals( + $product->getMsrp(), + $mapBlock->getOldPrice(), + 'Displayed on Category page MAP is incorrect.' + ); + $priceData = $product->getDataFieldConfig('price')['source']->getPriceData(); + $price = isset($priceData['category_price']) ? $priceData['category_price'] : $product->getPrice(); + \PHPUnit_Framework_Assert::assertEquals( + $price, + $mapBlock->getActualPrice(), + 'Displayed on Category page price is incorrect.' + ); + } + + /** + * Return string representation of object. + * + * @return string + */ + public function toString() + { + return "Displayed Product MAP data on category page is correct."; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Msrp/Test/Constraint/AssertMapOnProductView.php b/dev/tests/functional/tests/app/Magento/Msrp/Test/Constraint/AssertMapOnProductView.php new file mode 100644 index 0000000000000..c3699ea7bc2f5 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Msrp/Test/Constraint/AssertMapOnProductView.php @@ -0,0 +1,67 @@ +open(); + $cmsIndex->getTopmenu()->selectCategoryByName($product->getCategoryIds()[0]); + $catalogCategoryView->getListProductBlock()->getProductItem($product)->open(); + + $viewBlock = $catalogProductView->getMsrpViewBlock(); + $viewBlock->openMapBlock(); + $mapBlock = $viewBlock->getMapBlock(); + \PHPUnit_Framework_Assert::assertContains( + $product->getMsrp(), + $mapBlock->getOldPrice(), + 'Displayed on Product view page MAP is incorrect.' + ); + $priceData = $product->getDataFieldConfig('price')['source']->getPriceData(); + $price = isset($priceData['category_price']) ? $priceData['category_price'] : $product->getPrice(); + \PHPUnit_Framework_Assert::assertEquals( + $price, + $mapBlock->getActualPrice(), + 'Displayed on Product view page price is incorrect.' + ); + } + + /** + * Return string representation of object. + * + * @return string + */ + public function toString() + { + return "Displayed Product MAP data on product view page is correct."; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Msrp/Test/Constraint/AssertMsrpInShoppingCart.php b/dev/tests/functional/tests/app/Magento/Msrp/Test/Constraint/AssertMsrpInShoppingCart.php index fc093d4f53f28..d491309100d3e 100644 --- a/dev/tests/functional/tests/app/Magento/Msrp/Test/Constraint/AssertMsrpInShoppingCart.php +++ b/dev/tests/functional/tests/app/Magento/Msrp/Test/Constraint/AssertMsrpInShoppingCart.php @@ -41,7 +41,7 @@ public function processAssert( $cmsIndex->getTopmenu()->selectCategoryByName($product->getCategoryIds()[0]); $catalogCategoryView->getListProductBlock()->getProductItem($product)->open(); - if ($product->hasData('checkout_data')) { + if ($product->hasData('checkout_data') || $product->getMsrpDisplayActualPriceType() === 'In Cart') { $catalogProductView->getViewBlock()->addToCart($product); } else { $catalogProductView->getMsrpViewBlock()->openMapBlock(); diff --git a/dev/tests/functional/tests/app/Magento/Msrp/Test/Constraint/AssertMsrpOnCategoryPage.php b/dev/tests/functional/tests/app/Magento/Msrp/Test/Constraint/AssertMsrpOnCategoryPage.php index 0f27f368c8f40..7ef9e44bacad8 100644 --- a/dev/tests/functional/tests/app/Magento/Msrp/Test/Constraint/AssertMsrpOnCategoryPage.php +++ b/dev/tests/functional/tests/app/Magento/Msrp/Test/Constraint/AssertMsrpOnCategoryPage.php @@ -13,12 +13,12 @@ use Magento\Catalog\Test\Page\Category\CatalogCategoryView; /** - * Assert product MAP related data on category page. + * Assert product MSRP related data on category page. */ class AssertMsrpOnCategoryPage extends AbstractConstraint { /** - * Assert product MAP related data on category page. + * Assert product MSRP related data on category page. * * @param CmsIndex $cmsIndex * @param CatalogCategoryView $catalogCategoryView @@ -44,27 +44,12 @@ public function processAssert( \PHPUnit_Framework_Assert::assertEquals( $product->getMsrp(), $priceBlock->getOldPrice(), - 'Displayed on Category page MAP is incorrect.' + 'Displayed on Category page MSRP is incorrect.' ); \PHPUnit_Framework_Assert::assertFalse( $priceBlock->isRegularPriceVisible(), 'Regular price on Category page is visible and not expected.' ); - - $productBlock->openMapBlock(); - $mapBlock = $productBlock->getMapBlock(); - \PHPUnit_Framework_Assert::assertEquals( - $product->getMsrp(), - $mapBlock->getOldPrice(), - 'Displayed on Category page MAP is incorrect.' - ); - $priceData = $product->getDataFieldConfig('price')['source']->getPriceData(); - $price = isset($priceData['category_price']) ? $priceData['category_price'] : $product->getPrice(); - \PHPUnit_Framework_Assert::assertEquals( - $price, - $mapBlock->getActualPrice(), - 'Displayed on Category page price is incorrect.' - ); } /** @@ -74,6 +59,6 @@ public function processAssert( */ public function toString() { - return "Displayed Product MAP data on category page is correct."; + return "Displayed Product MSRP data on category page is correct."; } } diff --git a/dev/tests/functional/tests/app/Magento/Msrp/Test/Constraint/AssertMsrpOnProductView.php b/dev/tests/functional/tests/app/Magento/Msrp/Test/Constraint/AssertMsrpOnProductView.php index 72d1356d2e62e..fb0d9803dbae3 100644 --- a/dev/tests/functional/tests/app/Magento/Msrp/Test/Constraint/AssertMsrpOnProductView.php +++ b/dev/tests/functional/tests/app/Magento/Msrp/Test/Constraint/AssertMsrpOnProductView.php @@ -14,12 +14,12 @@ use Magento\Catalog\Test\Page\Product\CatalogProductView; /** - * Assert product MAP related data on product view page. + * Assert product MSRP related data on product view page. */ class AssertMsrpOnProductView extends AbstractConstraint { /** - * Assert product MAP related data on product view page. + * Assert product MSRP related data on product view page. * * @param CmsIndex $cmsIndex * @param CatalogCategoryView $catalogCategoryView @@ -43,27 +43,12 @@ public function processAssert( \PHPUnit_Framework_Assert::assertEquals( $product->getMsrp(), $priceBlock->getOldPrice(), - 'Displayed on Product view page MAP is incorrect' + 'Displayed on Product view page MSRP is incorrect' ); \PHPUnit_Framework_Assert::assertFalse( $priceBlock->isRegularPriceVisible(), 'Regular price on Product view page is visible and not expected.' ); - - $viewBlock->openMapBlock(); - $mapBlock = $viewBlock->getMapBlock(); - \PHPUnit_Framework_Assert::assertContains( - $product->getMsrp(), - $mapBlock->getOldPrice(), - 'Displayed on Product view page MAP is incorrect.' - ); - $priceData = $product->getDataFieldConfig('price')['source']->getPriceData(); - $price = isset($priceData['category_price']) ? $priceData['category_price'] : $product->getPrice(); - \PHPUnit_Framework_Assert::assertEquals( - $price, - $mapBlock->getActualPrice(), - 'Displayed on Product view page price is incorrect.' - ); } /** @@ -73,6 +58,6 @@ public function processAssert( */ public function toString() { - return "Displayed Product MAP data on product view page is correct."; + return "Displayed Product MSRP data on product view page is correct."; } } diff --git a/dev/tests/functional/tests/app/Magento/Msrp/Test/Repository/CatalogProductSimple.xml b/dev/tests/functional/tests/app/Magento/Msrp/Test/Repository/CatalogProductSimple.xml index 838f786b5ab2e..4edacdd3daeeb 100644 --- a/dev/tests/functional/tests/app/Magento/Msrp/Test/Repository/CatalogProductSimple.xml +++ b/dev/tests/functional/tests/app/Magento/Msrp/Test/Repository/CatalogProductSimple.xml @@ -70,5 +70,37 @@ 15 On Gesture + + + \'Simple Product with\' msrp %isolation% + simple-product-with-msrp-%isolation% + sku_simple_product_with_msrp_%isolation% + 1 + This item has weight + + 1000 + In Stock + + + 10 + - + + + default_subcategory + + + taxable_goods + + + + default + + + + No + + 15 + In Cart + diff --git a/dev/tests/functional/tests/app/Magento/Msrp/Test/TestCase/ApplyMapTest.xml b/dev/tests/functional/tests/app/Magento/Msrp/Test/TestCase/ApplyMapTest.xml index 3febc498cc440..4f5bf897221a2 100644 --- a/dev/tests/functional/tests/app/Magento/Msrp/Test/TestCase/ApplyMapTest.xml +++ b/dev/tests/functional/tests/app/Magento/Msrp/Test/TestCase/ApplyMapTest.xml @@ -10,13 +10,23 @@ catalogProductSimple::msrp_on_gesture + + configurableProduct::msrp_on_gesture_one_variation test_type:acceptance_test, test_type:extended_acceptance_test + + + + + + + catalogProductSimple::msrp_display_actual_price_in_cart_with_quotes_in_product_name + From 0a887420ccf85a294944768231570e87859cafc8 Mon Sep 17 00:00:00 2001 From: Venkata Uppalapati Date: Fri, 14 Apr 2017 11:59:05 -0500 Subject: [PATCH 2/3] MAGETWO-63116: [GitHub] Quotes in product name causes JSON error on product page MAP What's This Popup #8059 - Modified the ticket ID for the newly created variation. --- .../tests/app/Magento/Msrp/Test/TestCase/ApplyMapTest.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/functional/tests/app/Magento/Msrp/Test/TestCase/ApplyMapTest.xml b/dev/tests/functional/tests/app/Magento/Msrp/Test/TestCase/ApplyMapTest.xml index 4f5bf897221a2..c5f2cfeadf60f 100644 --- a/dev/tests/functional/tests/app/Magento/Msrp/Test/TestCase/ApplyMapTest.xml +++ b/dev/tests/functional/tests/app/Magento/Msrp/Test/TestCase/ApplyMapTest.xml @@ -24,7 +24,7 @@ - + catalogProductSimple::msrp_display_actual_price_in_cart_with_quotes_in_product_name From c52cb22f9f26bb99ae86a2c7712578572c9aa800 Mon Sep 17 00:00:00 2001 From: Cristian Partica Date: Mon, 17 Apr 2017 15:32:25 -0500 Subject: [PATCH 3/3] MAGETWO-63116: [GitHub] Quotes in product name causes JSON error on product page MAP What's This Popup #8059 - remove annotation --- .../Magento/Msrp/view/base/templates/product/price/msrp.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Msrp/view/base/templates/product/price/msrp.phtml b/app/code/Magento/Msrp/view/base/templates/product/price/msrp.phtml index 1e2642d85b09e..691677d6bcafb 100644 --- a/app/code/Magento/Msrp/view/base/templates/product/price/msrp.phtml +++ b/app/code/Magento/Msrp/view/base/templates/product/price/msrp.phtml @@ -95,7 +95,7 @@ if ($product->isSaleable()) { class="action map-show-info" data-mage-init='{"addToCart":{"origin": "info", "helpLinkId": "#", - "productName": "escapeJs($block->escapeHtml($product->getName())) ?>", + "productName": "escapeJs($block->escapeHtml($product->getName())) ?>", "closeButtonId": "#map-popup-close"}}'>