|
| 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