Skip to content

Commit

Permalink
magento#108: Clear Shopping Cart - Added integration test for isClear…
Browse files Browse the repository at this point in the history
…ShoppingCartEnabled method, added timeout for MFTF emptyCartButton element
  • Loading branch information
John Carlo Octabio committed Jul 21, 2020
1 parent adfea2a commit b65a287
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<element name="checkoutCartProductPrice" type="text" selector="//td[@class='col price']//span[@class='price']"/>
<element name="checkoutCartSubtotal" type="text" selector="//td[@class='col subtotal']//span[@class='price']"/>
<element name="emptyCart" selector=".cart-empty" type="text"/>
<element name="emptyCartButton" selector="#empty_cart_button" type="button"/>
<element name="emptyCartButton" type="button" selector="#empty_cart_button" timeout="30"/>
<element name="modalMessage" type="text" selector=".modal-popup.confirm._show .modal-content" timeout="30"/>
<element name="modalConfirmButton" type="button" selector=".modal-popup.confirm._show .action-accept" timeout="30"/>
<!-- Required attention section -->
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Checkout/ViewModel/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Cart implements ArgumentInterface
/**
* Config settings path to enable clear shopping cart button
*/
private const XPATH_CONFIG_ENABLE_CLEAR_SHOPPING_CART = 'checkout/cart/enable_clear_shopping_cart';
public const XPATH_CONFIG_ENABLE_CLEAR_SHOPPING_CART = 'checkout/cart/enable_clear_shopping_cart';

/**
* @var ScopeConfigInterface
Expand All @@ -41,7 +41,7 @@ public function __construct(
*/
public function isClearShoppingCartEnabled()
{
return (bool) $this->_scopeConfig->getValue(
return (bool)$this->_scopeConfig->getValue(
self::XPATH_CONFIG_ENABLE_CLEAR_SHOPPING_CART,
ScopeInterface::SCOPE_WEBSITE
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Checkout\ViewModel;

use Magento\Framework\App\Config\MutableScopeConfigInterface;
use Magento\Framework\ObjectManagerInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;

/**
* Test for clear shopping cart config
*
* @package Magento\Checkout\ViewModel
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class CartTest extends TestCase
{
/**
* @var ObjectManagerInterface
*/
private $objectManager;

/**
* @var Cart
*/
private $cart;

/**
* @var MutableScopeConfigInterface
*/
private $mutableScopeConfig;

/**
* @var StoreManagerInterface
*/
private $storeManager;

/**
* @inheritDoc
*/
protected function setUp(): void
{
$objectManager = $this->objectManager = Bootstrap::getObjectManager();
$this->cart = $objectManager->get(Cart::class);
$this->mutableScopeConfig = $objectManager->get(MutableScopeConfigInterface::class);
$this->storeManager = $objectManager->get(StoreManagerInterface::class);
}

/**
* @magentoAppArea frontend
* @magentoDataFixture Magento/Store/_files/second_website_with_two_stores.php
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testConfigClearShoppingCartEnabledWithWebsiteScopes()
{
// Assert not active by default
$this->assertFalse($this->cart->isClearShoppingCartEnabled());

// Enable Clear Shopping Cart in default website scope
$this->setClearShoppingCartEnabled(
true,
ScopeInterface::SCOPE_WEBSITE
);

// Assert now active in default website scope
$this->assertTrue($this->cart->isClearShoppingCartEnabled());

$defaultStore = $this->storeManager->getStore();
$defaultWebsite = $defaultStore->getWebsite();
$defaultWebsiteCode = $defaultWebsite->getCode();

$secondStore = $this->storeManager->getStore('fixture_second_store');
$secondWebsite = $secondStore->getWebsite();
$secondWebsiteCode = $secondWebsite->getCode();

// Change current store context to that of second website
$this->storeManager->setCurrentStore($secondStore);

// Assert not active by default in second website
$this->assertFalse($this->cart->isClearShoppingCartEnabled());

// Enable Clear Shopping Cart in second website scope
$this->setClearShoppingCartEnabled(
true,
ScopeInterface::SCOPE_WEBSITE,
$secondWebsiteCode
);

// Assert now active in second website scope
$this->assertTrue($this->cart->isClearShoppingCartEnabled());

// Disable Clear Shopping Cart in default website scope
$this->setClearShoppingCartEnabled(
false,
ScopeInterface::SCOPE_WEBSITE,
$defaultWebsiteCode
);

// Assert still active in second website
$this->assertTrue($this->cart->isClearShoppingCartEnabled());
}

/**
* Set purchase order enabled status.
*
* @param bool $isActive
* @param string $scope
* @param string|null $scopeCode
*/
private function setClearShoppingCartEnabled(bool $isActive, string $scope, $scopeCode = null)
{
$this->mutableScopeConfig->setValue(
'checkout/cart/enable_clear_shopping_cart',
$isActive ? '1' : '0',
$scope,
$scopeCode
);
}
}

0 comments on commit b65a287

Please sign in to comment.