Skip to content

Commit 91b5bf0

Browse files
Merge pull request #33 from magento-epam/MAGETWO-66666
Magetwo 66666
2 parents 50503f2 + 601b2f6 commit 91b5bf0

File tree

7 files changed

+292
-0
lines changed

7 files changed

+292
-0
lines changed

app/code/Magento/Catalog/view/frontend/web/js/catalog-add-to-cart.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,13 @@ define([
159159
.html(res.product.statusText);
160160
}
161161
self.enableAddToCartButton(form);
162+
},
163+
164+
/** @inheritdoc */
165+
complete: function (res) {
166+
if (res.state() == 'rejected') {
167+
location.reload();
168+
}
162169
}
163170
});
164171
},

app/code/Magento/Checkout/Controller/Cart/Add.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ protected function _initProduct()
8080
public function execute()
8181
{
8282
if (!$this->_formKeyValidator->validate($this->getRequest())) {
83+
$this->messageManager->addErrorMessage(
84+
__('Your session has expired')
85+
);
8386
return $this->resultRedirectFactory->create()->setPath('*/*/');
8487
}
8588

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Checkout\Test\Unit\Controller\Cart;
7+
8+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
9+
10+
class AddTest extends \PHPUnit\Framework\TestCase
11+
{
12+
/**
13+
* @var ObjectManagerHelper
14+
*/
15+
private $objectManagerHelper;
16+
17+
/**
18+
* @var \Magento\Framework\Data\Form\FormKey\Validator|\PHPUnit_Framework_MockObject_MockObject
19+
*/
20+
private $formKeyValidator;
21+
22+
/**
23+
* @var \Magento\Framework\Controller\Result\RedirectFactory|\PHPUnit_Framework_MockObject_MockObject
24+
*/
25+
private $resultRedirectFactory;
26+
27+
/**
28+
* @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject
29+
*/
30+
private $request;
31+
32+
/**
33+
* @var \Magento\Framework\Message\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject
34+
*/
35+
private $messageManager;
36+
37+
public function setUp()
38+
{
39+
$this->formKeyValidator = $this->getMockBuilder(\Magento\Framework\Data\Form\FormKey\Validator::class)
40+
->disableOriginalConstructor()->getMock();
41+
$this->resultRedirectFactory =
42+
$this->getMockBuilder(\Magento\Framework\Controller\Result\RedirectFactory::class)
43+
->disableOriginalConstructor()->getMock();
44+
$this->request = $this->getMockBuilder(\Magento\Framework\App\RequestInterface::class)
45+
->disableOriginalConstructor()->getmock();
46+
$this->messageManager = $this->getMockBuilder(\Magento\Framework\Message\ManagerInterface::class)
47+
->disableOriginalConstructor()->getMock();
48+
49+
$this->objectManagerHelper = new ObjectManagerHelper($this);
50+
$this->add = $this->objectManagerHelper->getObject(
51+
\Magento\Checkout\Controller\Cart\Add::class,
52+
[
53+
'_formKeyValidator' => $this->formKeyValidator,
54+
'resultRedirectFactory' => $this->resultRedirectFactory,
55+
'_request' => $this->request,
56+
'messageManager' => $this->messageManager
57+
]
58+
);
59+
}
60+
61+
/**
62+
* Test for method execute.
63+
*
64+
* @return void
65+
*/
66+
public function testExecute()
67+
{
68+
$redirect = $this->getMockBuilder(\Magento\Framework\Controller\Result\Redirect::class)
69+
->disableOriginalConstructor()
70+
->getMock();
71+
$path = '*/*/';
72+
73+
$this->formKeyValidator->expects($this->once())->method('validate')->with($this->request)->willReturn(false);
74+
$this->messageManager->expects($this->once())->method('addErrorMessage');
75+
$this->resultRedirectFactory->expects($this->once())->method('create')->willReturn($redirect);
76+
$redirect->expects($this->once())->method('setPath')->with($path)->willReturnSelf();
77+
$this->assertEquals($redirect, $this->add->execute());
78+
}
79+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Test/etc/actionGroupSchema.xsd">
10+
11+
<!--Go To Products page-->
12+
<actionGroup name="GoToProductPage">
13+
<click selector="{{GoToProductPageSection.catalog}}" stepKey="clickOnCatalog" />
14+
<waitForPageLoad stepKey="waitForPage"/>
15+
<click selector="{{GoToProductPageSection.product}}" stepKey="clickToSelectProductsItem" />
16+
<waitForPageLoad stepKey="waitForPageProducts"/>
17+
</actionGroup>
18+
19+
<!--Create Simple product-->
20+
<actionGroup name="AdminCreateSimpleProduct">
21+
<click selector="{{GoToProductPageSection.add}}" stepKey="clickToAddProduct"/>
22+
<waitForPageLoad stepKey="WaitForProductPageIsLoaded"/>
23+
<fillField selector="{{AdminProductFormSection.productName}}" userInput="{{SimpleProductOne.name}}" stepKey="setNameForProduct"/>
24+
<fillField selector="{{AdminProductFormSection.productSku}}" userInput="{{SimpleProductOne.sku}}" stepKey="setSKUForProduct"/>
25+
<fillField selector="{{AdminProductFormSection.productPrice}}" userInput="{{SimpleProductOne.price}}" stepKey="setPriceForProduct"/>
26+
<fillField selector="{{AdminProductFormSection.productQuantity}}" userInput="{{SimpleProductOne.quantity}}" stepKey="setQuantityForProduct"/>
27+
<click selector="{{AdminProductFormSection.searchOptimization}}" stepKey="clickOnSearchEngineOptimization"/>
28+
<fillField selector="{{AdminProductFormSection.urlKey}}" userInput="{{SimpleProductOne.urlKey}}" stepKey="setSearchUrlForProduct"/>
29+
<click selector="{{AdminProductFormSection.saveButton}}" stepKey="clickSaveProduct"/>
30+
<waitForPageLoad stepKey="WaitForProductSave"/>
31+
<see userInput="You saved the product." stepKey="seeSaveConfirmation"/>
32+
</actionGroup>
33+
34+
<actionGroup name="FindAndAddProductToCardActionGroup">
35+
<click selector="{{StorefrontAddProductToCartSection.addToCartBtn}}" stepKey="addToCart"/>
36+
<waitForElementVisible selector="{{StorefrontProductPageSection.successMsg}}" time="30" stepKey="waitForProductAdded"/>
37+
<click selector="{{StorefrontAddProductToCartSection.showCard}}" stepKey="clickToOpenCard"/>
38+
<waitForPageLoad stepKey="WaitForFormOpened" time="3"/>
39+
<click selector="{{StorefrontAddProductToCartSection.proceed}}" stepKey="clickToProceedToCheckout"/>
40+
<waitForPageLoad time="5" stepKey="waitForTheFormIsOpened"/>
41+
<see userInput="Shipping Address" stepKey="seeShippingAddress"/>
42+
</actionGroup>
43+
44+
<actionGroup name="DeleteCreatedProduct">
45+
<fillField stepKey="searchToKeyword" selector="{{DeleteCreatedProduct.searchToKeyword}}" userInput="{{SimpleProductOne.name}}"/>
46+
<click stepKey="clickSearchButton" selector="{{DeleteCreatedProduct.searchButton}}"/>
47+
<wait stepKey="waitForFiltering" time="2"/>
48+
<click selector="{{DeleteCreatedProduct.createdProductID}}" stepKey="selectCreatedProduct"/>
49+
<wait stepKey="waitSelectCreatedProduct" time="2"/>
50+
<waitForElementVisible selector="{{DeleteCreatedProduct.actionSelectBox}}" stepKey="waitToSelectActionVisible" time="50"/>
51+
<click stepKey="clickToSelectAction" selector="{{DeleteCreatedProduct.actionSelectBox}}"/>
52+
<waitForElementVisible selector="{{DeleteCreatedProduct.deleteButton}}" stepKey="waitForDeleteButtonAppeared" time="2"/>
53+
<click selector="{{DeleteCreatedProduct.deleteButton}}" stepKey="clickToDeleteProduct"/>
54+
<waitForElementVisible selector="{{DeleteCreatedProduct.okButton}}" stepKey="waitForOkButtonAppeared" time="2"/>
55+
<click selector="{{DeleteCreatedProduct.okButton}}" stepKey="clickToConfirm"/>
56+
<wait stepKey="waitForRecordIsDeleted" time="2"/>
57+
<see userInput="A total of 1 record(s) have been deleted." stepKey="productDeletedSuccessfully"/>
58+
<click stepKey="clickClearAllFilterButton" selector="{{DeleteCreatedProduct.clearAll}}"/>
59+
<!-- We need this wait to make sure that Active filters is clear (waitForElementNotVisible tag doesn't wait until clearing filters)-->
60+
<wait stepKey="waitToClearAllFilters" time="2"/>
61+
</actionGroup>
62+
63+
</actionGroups>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/DataGenerator/etc/dataProfileSchema.xsd">
11+
<entity name="SimpleProductOne" type="product">
12+
<data key="name" unique="suffix">testProduct</data>
13+
<data key="sku" unique="suffix">testSku</data>
14+
<data key="price">200</data>
15+
<data key="quantity">100</data>
16+
<data key="urlKey" unique="suffix">testProduct</data>
17+
</entity>
18+
</entities>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Page/etc/SectionObject.xsd">
11+
<section name="StorefrontAddProductToCartSection">
12+
<element name="addToCartBtn" type="button" selector="button.action.tocart.primary"/>
13+
<element name="successMsg" type="button" selector="div.message-success"/>
14+
<element name="showCard" type="button" selector=".action.showcart"/>
15+
<element name="proceed" type="button" selector="#top-cart-btn-checkout"/>
16+
</section>
17+
18+
<section name="GoToProductPageSection">
19+
<!--Go to Catalog/Products-->
20+
<element name="catalog" type="button" selector="#menu-magento-catalog-catalog"/>
21+
<element name="product" type="button" selector="//span[contains(text(), 'Products')]"/>
22+
<element name="add" type="button" selector="#add_new_product-button"/>
23+
</section>
24+
25+
<section name="AdminProductFormSection">
26+
<element name="attributeSet" type="select" selector="div[data-index='attribute_set_id'] .admin__field-control"/>
27+
<element name="attributeSetFilter" type="input" selector="div[data-index='attribute_set_id'] .admin__field-control input" timeout="30"/>
28+
<element name="attributeSetFilterResult" type="input" selector="div[data-index='attribute_set_id'] .action-menu-item._last" timeout="30"/>
29+
<element name="productName" type="input" selector=".admin__field[data-index=name] input"/>
30+
<element name="productSku" type="input" selector=".admin__field[data-index=sku] input"/>
31+
<element name="productStatus" type="checkbox" selector="input[name='product[status]']"/>
32+
<element name="enableProductLabel" type="checkbox" selector="input[name='product[status]']+label"/>
33+
<element name="productStatusUseDefault" type="checkbox" selector="input[name='use_default[status]']"/>
34+
<element name="productNameUseDefault" type="checkbox" selector="input[name='use_default[name]']"/>
35+
<element name="productPrice" type="input" selector=".admin__field[data-index=price] input"/>
36+
<element name="productTaxClassUseDefault" type="checkbox" selector="input[name='use_default[tax_class_id]']"/>
37+
<element name="advancedPricingLink" type="button" selector="button[data-index='advanced_pricing_button']"/>
38+
<element name="categoriesDropdown" type="multiselect" selector="div[data-index='category_ids']"/>
39+
<element name="productQuantity" type="input" selector=".admin__field[data-index=qty] input"/>
40+
<element name="productStockStatus" type="select" selector="select[name='product[quantity_and_stock_status][is_in_stock]']"/>
41+
<element name="productWeight" type="input" selector=".admin__field[data-index=weight] input"/>
42+
<element name="productWeightSelect" type="select" selector="select[name='product[product_has_weight]']"/>
43+
<element name="contentTab" type="button" selector="//strong[contains(@class, 'admin__collapsible-title')]/span[text()='Content']"/>
44+
<element name="fieldError" type="text" selector="//input[@name='product[{{fieldName}}]']/following-sibling::label[@class='admin__field-error']" parameterized="true"/>
45+
<element name="priceFieldError" type="text" selector="//input[@name='product[price]']/parent::div/parent::div/label[@class='admin__field-error']"/>
46+
<element name="addAttributeBtn" type="button" selector="#addAttribute"/>
47+
<element name="createNewAttributeBtn" type="button" selector="button[data-index='add_new_attribute_button']"/>
48+
<element name="save" type="button" selector="#save"/>
49+
<element name="attributeTab" type="button" selector="//strong[contains(@class, 'admin__collapsible-title')]/span[text()='Attributes']"/>
50+
<element name="attributeLabel" type="input" selector="//input[@name='frontend_label[0]']"/>
51+
<element name="frontendInput" type="select" selector="select[name = 'frontend_input']"/>
52+
<element name="productFormTab" type="button" selector="//strong[@class='admin__collapsible-title']/span[contains(text(), '{{tabName}}')]" parameterized="true"/>
53+
<element name="productFormTabState" type="text" selector="//strong[@class='admin__collapsible-title']/span[contains(text(), '{{tabName}}')]/parent::*/parent::*[@data-state-collapsible='{{state}}']" parameterized="true"/>
54+
<element name="visibility" type="select" selector="//select[@name='product[visibility]']"/>
55+
<element name="visibilityUseDefault" type="checkbox" selector="//input[@name='use_default[visibility]']"/>
56+
<element name="divByDataIndex" type="input" selector="div[data-index='{{var}}']" parameterized="true"/>
57+
<element name="attributeLabelByText" type="text" selector="//*[@class='admin__field']//span[text()='{{attributeLabel}}']" parameterized="true"/>
58+
<element name="searchOptimization" type="button" selector="//*[contains(text(),'Search Engine Optimization')]"/>
59+
<element name="urlKey" type="input" selector="//input[contains(@name,'url_key')]"/>
60+
<element name="saveButton" type="button" selector="#save-button"/>
61+
</section>
62+
63+
<section name="DeleteCreatedProduct">
64+
<element name="searchToKeyword" type="input" selector="//*[@class='admin__data-grid-outer-wrap']/*[@class='admin__data-grid-header']//*[@class='data-grid-search-control-wrap']/input"/>
65+
<element name="searchButton" type="button" selector="//*[@class='admin__data-grid-outer-wrap']/*[@class='admin__data-grid-header']//*[@class='data-grid-search-control-wrap']/button"/>
66+
<element name="createdProductID" type="select" selector="//*[@class='data-grid-checkbox-cell-inner']/input"/>
67+
<element name="actionSelectBox" type="button" selector="//*[@class='col-xs-2']//span[text()='Actions']"/>
68+
<element name="deleteButton" type="button" selector="//div[@class='col-xs-2']//*[text()='Delete']"/>
69+
<element name="okButton" type="button" selector=".action-primary.action-accept"/>
70+
<element name="clearAll" type="button" selector="//*[@class='admin__data-grid-outer-wrap']/*[@class='admin__data-grid-header']//*[contains(text(), 'Clear all')]"/>
71+
</section>
72+
73+
</sections>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd">
11+
<test name="AddingProductWithExpiredSessionTest">
12+
<annotations>
13+
<title value="Adding a product to cart from category page with an expired session"/>
14+
<features value="Module/ Catalog"/>
15+
<severity value="MAJOR"/>
16+
<testCaseId value="MAGETWO-93289"/>
17+
<stories value="MAGETWO-66666: Adding a product to cart from category page with an expired session does not allow product to be added"/>
18+
<group value="customer"/>
19+
</annotations>
20+
21+
<before>
22+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin1"/>
23+
<actionGroup ref="GoToProductPage" stepKey="goToProductPage"/>
24+
<actionGroup ref="AdminCreateSimpleProduct" stepKey="adminCreateSimpleProduct"/>
25+
</before>
26+
27+
<!--Navigate to a category page -->
28+
<amOnPage url="/{{SimpleProductOne.name}}.html" stepKey="GoToProductPage"/>
29+
30+
<waitForPageLoad stepKey="waitForPageLoad"/>
31+
32+
<!-- Remove PHPSESSID and form_key to replicate an expired session-->
33+
<executeJS function="var delete_cookie = function(name) {
34+
document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:01 UTC; path=/;';};
35+
delete_cookie('PHPSESSID');
36+
delete_cookie('form_key');" stepKey="removeCookies" after="waitForPageLoad"/>
37+
38+
<!-- "Add to Cart" any product-->
39+
<actionGroup ref="FindAndAddProductToCardActionGroup" stepKey="addProductToCard"/>
40+
41+
<after>
42+
<!--Delete created product-->
43+
<amOnPage url="/admin" stepKey="GoToDashboard"/>
44+
<actionGroup ref="GoToProductPage" stepKey="againGoToProductPage"/>
45+
<actionGroup ref="DeleteCreatedProduct" stepKey="deleteCreatedProduct"/>
46+
</after>
47+
48+
</test>
49+
</tests>

0 commit comments

Comments
 (0)