Skip to content

Commit b65a287

Browse files
author
John Carlo Octabio
committed
#108: Clear Shopping Cart - Added integration test for isClearShoppingCartEnabled method, added timeout for MFTF emptyCartButton element
1 parent adfea2a commit b65a287

File tree

3 files changed

+129
-3
lines changed

3 files changed

+129
-3
lines changed

app/code/Magento/Checkout/Test/Mftf/Section/CheckoutCartProductSection.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<element name="checkoutCartProductPrice" type="text" selector="//td[@class='col price']//span[@class='price']"/>
4949
<element name="checkoutCartSubtotal" type="text" selector="//td[@class='col subtotal']//span[@class='price']"/>
5050
<element name="emptyCart" selector=".cart-empty" type="text"/>
51-
<element name="emptyCartButton" selector="#empty_cart_button" type="button"/>
51+
<element name="emptyCartButton" type="button" selector="#empty_cart_button" timeout="30"/>
5252
<element name="modalMessage" type="text" selector=".modal-popup.confirm._show .modal-content" timeout="30"/>
5353
<element name="modalConfirmButton" type="button" selector=".modal-popup.confirm._show .action-accept" timeout="30"/>
5454
<!-- Required attention section -->

app/code/Magento/Checkout/ViewModel/Cart.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Cart implements ArgumentInterface
1616
/**
1717
* Config settings path to enable clear shopping cart button
1818
*/
19-
private const XPATH_CONFIG_ENABLE_CLEAR_SHOPPING_CART = 'checkout/cart/enable_clear_shopping_cart';
19+
public const XPATH_CONFIG_ENABLE_CLEAR_SHOPPING_CART = 'checkout/cart/enable_clear_shopping_cart';
2020

2121
/**
2222
* @var ScopeConfigInterface
@@ -41,7 +41,7 @@ public function __construct(
4141
*/
4242
public function isClearShoppingCartEnabled()
4343
{
44-
return (bool) $this->_scopeConfig->getValue(
44+
return (bool)$this->_scopeConfig->getValue(
4545
self::XPATH_CONFIG_ENABLE_CLEAR_SHOPPING_CART,
4646
ScopeInterface::SCOPE_WEBSITE
4747
);
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Checkout\ViewModel;
9+
10+
use Magento\Framework\App\Config\MutableScopeConfigInterface;
11+
use Magento\Framework\ObjectManagerInterface;
12+
use Magento\Store\Model\ScopeInterface;
13+
use Magento\Store\Model\StoreManagerInterface;
14+
use Magento\TestFramework\Helper\Bootstrap;
15+
use PHPUnit\Framework\TestCase;
16+
17+
/**
18+
* Test for clear shopping cart config
19+
*
20+
* @package Magento\Checkout\ViewModel
21+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
22+
*/
23+
class CartTest extends TestCase
24+
{
25+
/**
26+
* @var ObjectManagerInterface
27+
*/
28+
private $objectManager;
29+
30+
/**
31+
* @var Cart
32+
*/
33+
private $cart;
34+
35+
/**
36+
* @var MutableScopeConfigInterface
37+
*/
38+
private $mutableScopeConfig;
39+
40+
/**
41+
* @var StoreManagerInterface
42+
*/
43+
private $storeManager;
44+
45+
/**
46+
* @inheritDoc
47+
*/
48+
protected function setUp(): void
49+
{
50+
$objectManager = $this->objectManager = Bootstrap::getObjectManager();
51+
$this->cart = $objectManager->get(Cart::class);
52+
$this->mutableScopeConfig = $objectManager->get(MutableScopeConfigInterface::class);
53+
$this->storeManager = $objectManager->get(StoreManagerInterface::class);
54+
}
55+
56+
/**
57+
* @magentoAppArea frontend
58+
* @magentoDataFixture Magento/Store/_files/second_website_with_two_stores.php
59+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
60+
*/
61+
public function testConfigClearShoppingCartEnabledWithWebsiteScopes()
62+
{
63+
// Assert not active by default
64+
$this->assertFalse($this->cart->isClearShoppingCartEnabled());
65+
66+
// Enable Clear Shopping Cart in default website scope
67+
$this->setClearShoppingCartEnabled(
68+
true,
69+
ScopeInterface::SCOPE_WEBSITE
70+
);
71+
72+
// Assert now active in default website scope
73+
$this->assertTrue($this->cart->isClearShoppingCartEnabled());
74+
75+
$defaultStore = $this->storeManager->getStore();
76+
$defaultWebsite = $defaultStore->getWebsite();
77+
$defaultWebsiteCode = $defaultWebsite->getCode();
78+
79+
$secondStore = $this->storeManager->getStore('fixture_second_store');
80+
$secondWebsite = $secondStore->getWebsite();
81+
$secondWebsiteCode = $secondWebsite->getCode();
82+
83+
// Change current store context to that of second website
84+
$this->storeManager->setCurrentStore($secondStore);
85+
86+
// Assert not active by default in second website
87+
$this->assertFalse($this->cart->isClearShoppingCartEnabled());
88+
89+
// Enable Clear Shopping Cart in second website scope
90+
$this->setClearShoppingCartEnabled(
91+
true,
92+
ScopeInterface::SCOPE_WEBSITE,
93+
$secondWebsiteCode
94+
);
95+
96+
// Assert now active in second website scope
97+
$this->assertTrue($this->cart->isClearShoppingCartEnabled());
98+
99+
// Disable Clear Shopping Cart in default website scope
100+
$this->setClearShoppingCartEnabled(
101+
false,
102+
ScopeInterface::SCOPE_WEBSITE,
103+
$defaultWebsiteCode
104+
);
105+
106+
// Assert still active in second website
107+
$this->assertTrue($this->cart->isClearShoppingCartEnabled());
108+
}
109+
110+
/**
111+
* Set purchase order enabled status.
112+
*
113+
* @param bool $isActive
114+
* @param string $scope
115+
* @param string|null $scopeCode
116+
*/
117+
private function setClearShoppingCartEnabled(bool $isActive, string $scope, $scopeCode = null)
118+
{
119+
$this->mutableScopeConfig->setValue(
120+
'checkout/cart/enable_clear_shopping_cart',
121+
$isActive ? '1' : '0',
122+
$scope,
123+
$scopeCode
124+
);
125+
}
126+
}

0 commit comments

Comments
 (0)