You need to sign in or sign up before continuing.
TaxConfigProviderTest.php 13.7 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\Tax\Test\Unit\Model;

use \Magento\Tax\Model\Config;

class TaxConfigProviderTest extends \PHPUnit\Framework\TestCase
{
    /**
     * @var \PHPUnit_Framework_MockObject_MockObject
     */
    protected $taxHelperMock;

    /**
     * @var \PHPUnit_Framework_MockObject_MockObject
     */
    protected $taxConfigMock;

    /**
     * @var \PHPUnit_Framework_MockObject_MockObject
     */
    protected $checkoutSessionMock;

    /**
     * @var \PHPUnit_Framework_MockObject_MockObject
     */
    protected $scopeConfigMock;

    /**
     * @var \PHPUnit_Framework_MockObject_MockObject
     */
    protected $quoteMock;

    /**
     * @var \Magento\Tax\Model\TaxConfigProvider
     */
    protected $model;

    protected function setUp()
    {
        $this->taxHelperMock = $this->createMock(\Magento\Tax\Helper\Data::class);
        $this->taxConfigMock = $this->createMock(\Magento\Tax\Model\Config::class);
        $this->checkoutSessionMock = $this->createMock(\Magento\Checkout\Model\Session::class);
        $this->scopeConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
        $this->quoteMock = $this->createMock(\Magento\Quote\Model\Quote::class);
        $this->checkoutSessionMock->expects($this->any())->method('getQuote')->willReturn($this->quoteMock);
        $this->model = new \Magento\Tax\Model\TaxConfigProvider(
            $this->taxHelperMock,
            $this->taxConfigMock,
            $this->checkoutSessionMock,
            $this->scopeConfigMock
        );
    }

    /**
     * @dataProvider getConfigDataProvider
     * @param array $expectedResult
     * @param int $cartShippingBoth
     * @param int $cartShippingExclTax
     * @param int $cartBothPrices
     * @param int $cartPriceExclTax
     * @param int $cartSubTotalBoth
     * @param int $cartSubTotalExclTax
     * @param string|null $calculationType
     * @param bool $isQuoteVirtual
     */
    public function testGetConfig(
        $expectedResult,
        $cartShippingBoth,
        $cartShippingExclTax,
        $cartBothPrices,
        $cartPriceExclTax,
        $cartSubTotalBoth,
        $cartSubTotalExclTax,
        $isQuoteVirtual,
        $config
    ) {
        $this->taxConfigMock->expects($this->any())->method('displayCartShippingBoth')
            ->will($this->returnValue($cartShippingBoth));
        $this->taxConfigMock->expects($this->any())->method('displayCartShippingExclTax')
            ->will($this->returnValue($cartShippingExclTax));

        $this->taxHelperMock->expects($this->any())->method('displayCartBothPrices')
            ->will($this->returnValue($cartBothPrices));
        $this->taxHelperMock->expects($this->any())->method('displayCartPriceExclTax')
            ->will($this->returnValue($cartPriceExclTax));

        $this->taxConfigMock->expects($this->any())->method('displayCartSubtotalBoth')
            ->will($this->returnValue($cartSubTotalBoth));
        $this->taxConfigMock->expects($this->any())->method('displayCartSubtotalExclTax')
            ->will($this->returnValue($cartSubTotalExclTax));

        $this->taxHelperMock->expects(($this->any()))->method('displayShippingPriceExcludingTax')
            ->will($this->returnValue(1));
        $this->taxHelperMock->expects(($this->any()))->method('displayShippingBothPrices')
            ->will($this->returnValue(1));
        $this->taxHelperMock->expects(($this->any()))->method('displayFullSummary')
            ->will($this->returnValue(1));
        $this->taxConfigMock->expects(($this->any()))->method('displayCartTaxWithGrandTotal')
            ->will($this->returnValue(1));
        $this->taxConfigMock->expects(($this->any()))->method('displayCartZeroTax')
            ->will($this->returnValue(1));

        $valueMap = [];
        foreach ($config as $key => $value) {
            $valueMap[] = [$key, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, null, $value];
        }
        $this->scopeConfigMock->expects($this->atLeastOnce())
            ->method('getValue')
            ->willReturnMap($valueMap);
        $this->quoteMock->expects($this->any())->method('isVirtual')->willReturn($isQuoteVirtual);
        $this->assertEquals($expectedResult, $this->model->getConfig());
    }

    /**
     * @return array
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
     */
    public function getConfigDataProvider()
    {
        return [
            [
                'expectedResult' => [
                    'isDisplayShippingPriceExclTax' => 1,
                    'isDisplayShippingBothPrices' => 1,
                    'reviewShippingDisplayMode' => 'both',
                    'reviewItemPriceDisplayMode' => 'both',
                    'reviewTotalsDisplayMode' => 'both',
                    'includeTaxInGrandTotal' => 1,
                    'isFullTaxSummaryDisplayed' => 1,
                    'isZeroTaxDisplayed' => 1,
                    'reloadOnBillingAddress' => false,
                    'defaultCountryId' => 'US',
                    'defaultRegionId' => 12,
                    'defaultPostcode' => '*',
                ],
                'cartShippingBoth' => 1,
                'cartShippingExclTax' => 1,
                'cartBothPrices' => 1,
                'cartPriceExclTax' => 1,
                'cartSubTotalBoth' => 1,
                'cartSubTotalExclTax' => 1,
                'isQuoteVirtual' => false,
                'config' => [
                    Config::CONFIG_XML_PATH_BASED_ON => 'shipping',
                    Config::CONFIG_XML_PATH_DEFAULT_COUNTRY => 'US',
                    Config::CONFIG_XML_PATH_DEFAULT_REGION => 12,
                    Config::CONFIG_XML_PATH_DEFAULT_POSTCODE => '*',
                ],
            ],
            [
                'expectedResult' => [
                    'isDisplayShippingPriceExclTax' => 1,
                    'isDisplayShippingBothPrices' => 1,
                    'reviewShippingDisplayMode' => 'excluding',
                    'reviewItemPriceDisplayMode' => 'excluding',
                    'reviewTotalsDisplayMode' => 'excluding',
                    'includeTaxInGrandTotal' => 1,
                    'isFullTaxSummaryDisplayed' => 1,
                    'isZeroTaxDisplayed' => 1,
                    'reloadOnBillingAddress' => true,
                    'defaultCountryId' => 'US',
                    'defaultRegionId' => 12,
                    'defaultPostcode' => '*',
                ],
                'cartShippingBoth' => 0,
                'cartShippingExclTax' => 1,
                'cartBothPrices' => 0,
                'cartPriceExclTax' => 1,
                'cartSubTotalBoth' => 0,
                'cartSubTotalExclTax' => 1,
                'isQuoteVirtual' => false,
                'config' => [
                    Config::CONFIG_XML_PATH_BASED_ON => 'billing',
                    Config::CONFIG_XML_PATH_DEFAULT_COUNTRY => 'US',
                    Config::CONFIG_XML_PATH_DEFAULT_REGION => 12,
                    Config::CONFIG_XML_PATH_DEFAULT_POSTCODE => '*',
                ],
            ],
            [
                'expectedResult' => [
                    'isDisplayShippingPriceExclTax' => 1,
                    'isDisplayShippingBothPrices' => 1,
                    'reviewShippingDisplayMode' => 'including',
                    'reviewItemPriceDisplayMode' => 'including',
                    'reviewTotalsDisplayMode' => 'including',
                    'includeTaxInGrandTotal' => 1,
                    'isFullTaxSummaryDisplayed' => 1,
                    'isZeroTaxDisplayed' => 1,
                    'reloadOnBillingAddress' => true,
                    'defaultCountryId' => 'US',
                    'defaultRegionId' => 12,
                    'defaultPostcode' => '*',
                ],
                'cartShippingBoth' => 0,
                'cartShippingExclTax' => 0,
                'cartBothPrices' => 0,
                'cartPriceExclTax' => 0,
                'cartSubTotalBoth' => 0,
                'cartSubTotalExclTax' => 0,
                'isQuoteVirtual' => true,
                'config' => [
                    Config::CONFIG_XML_PATH_BASED_ON => 'shipping',
                    Config::CONFIG_XML_PATH_DEFAULT_COUNTRY => 'US',
                    Config::CONFIG_XML_PATH_DEFAULT_REGION => 12,
                    Config::CONFIG_XML_PATH_DEFAULT_POSTCODE => '*',
                ],
            ],
            [
                'expectedResult' => [
                    'isDisplayShippingPriceExclTax' => 1,
                    'isDisplayShippingBothPrices' => 1,
                    'reviewShippingDisplayMode' => 'including',
                    'reviewItemPriceDisplayMode' => 'including',
                    'reviewTotalsDisplayMode' => 'including',
                    'includeTaxInGrandTotal' => 1,
                    'isFullTaxSummaryDisplayed' => 1,
                    'isZeroTaxDisplayed' => 1,
                    'reloadOnBillingAddress' => true,
                    'defaultCountryId' => 'US',
                    'defaultRegionId' => 12,
                    'defaultPostcode' => '*',
                ],
                'cartShippingBoth' => 0,
                'cartShippingExclTax' => 0,
                'cartBothPrices' => 0,
                'cartPriceExclTax' => 0,
                'cartSubTotalBoth' => 0,
                'cartSubTotalExclTax' => 0,
                'isQuoteVirtual' => true,
                'config' => [
                    Config::CONFIG_XML_PATH_BASED_ON => 'billing',
                    Config::CONFIG_XML_PATH_DEFAULT_COUNTRY => 'US',
                    Config::CONFIG_XML_PATH_DEFAULT_REGION => 12,
                    Config::CONFIG_XML_PATH_DEFAULT_POSTCODE => '*',
                ],
            ],
            [
                'expectedResult' => [
                    'isDisplayShippingPriceExclTax' => 1,
                    'isDisplayShippingBothPrices' => 1,
                    'reviewShippingDisplayMode' => 'both',
                    'reviewItemPriceDisplayMode' => 'both',
                    'reviewTotalsDisplayMode' => 'both',
                    'includeTaxInGrandTotal' => 1,
                    'isFullTaxSummaryDisplayed' => 1,
                    'isZeroTaxDisplayed' => 1,
                    'reloadOnBillingAddress' => false,
                    'defaultCountryId' => 'US',
                    'defaultRegionId' => 12,
                    'defaultPostcode' => '*',
                ],
                'cartShippingBoth' => 1,
                'cartShippingExclTax' => 0,
                'cartBothPrices' => 1,
                'cartPriceExclTax' => 0,
                'cartSubTotalBoth' => 1,
                'cartSubTotalExclTax' => 0,
                'isQuoteVirtual' => false,
                'config' => [
                    Config::CONFIG_XML_PATH_BASED_ON => 'shipping',
                    Config::CONFIG_XML_PATH_DEFAULT_COUNTRY => 'US',
                    Config::CONFIG_XML_PATH_DEFAULT_REGION => 12,
                    Config::CONFIG_XML_PATH_DEFAULT_POSTCODE => '*',
                ],
            ],
            [
                'expectedResult' => [
                    'isDisplayShippingPriceExclTax' => 1,
                    'isDisplayShippingBothPrices' => 1,
                    'reviewShippingDisplayMode' => 'excluding',
                    'reviewItemPriceDisplayMode' => 'including',
                    'reviewTotalsDisplayMode' => 'both',
                    'includeTaxInGrandTotal' => 1,
                    'isFullTaxSummaryDisplayed' => 1,
                    'isZeroTaxDisplayed' => 1,
                    'reloadOnBillingAddress' => false,
                    'defaultCountryId' => 'US',
                    'defaultRegionId' => 12,
                    'defaultPostcode' => '*',
                ],
                'cartShippingBoth' => 0,
                'cartShippingExclTax' => 1,
                'cartBothPrices' => 0,
                'cartPriceExclTax' => 0,
                'cartSubTotalBoth' => 1,
                'cartSubTotalExclTax' => 0,
                'isQuoteVirtual' => false,
                'config' => [
                    Config::CONFIG_XML_PATH_BASED_ON => 'shipping',
                    Config::CONFIG_XML_PATH_DEFAULT_COUNTRY => 'US',
                    Config::CONFIG_XML_PATH_DEFAULT_REGION => 12,
                    Config::CONFIG_XML_PATH_DEFAULT_POSTCODE => '*',
                ],
            ],
            'zeroRegionToNull' => [
                'expectedResult' => [
                    'isDisplayShippingPriceExclTax' => 1,
                    'isDisplayShippingBothPrices' => 1,
                    'reviewShippingDisplayMode' => 'excluding',
                    'reviewItemPriceDisplayMode' => 'including',
                    'reviewTotalsDisplayMode' => 'both',
                    'includeTaxInGrandTotal' => 1,
                    'isFullTaxSummaryDisplayed' => 1,
                    'isZeroTaxDisplayed' => 1,
                    'reloadOnBillingAddress' => false,
                    'defaultCountryId' => 'US',
                    'defaultRegionId' => null,
                    'defaultPostcode' => '*',
                ],
                'cartShippingBoth' => 0,
                'cartShippingExclTax' => 1,
                'cartBothPrices' => 0,
                'cartPriceExclTax' => 0,
                'cartSubTotalBoth' => 1,
                'cartSubTotalExclTax' => 0,
                'isQuoteVirtual' => false,
                'config' => [
                    Config::CONFIG_XML_PATH_BASED_ON => 'shipping',
                    Config::CONFIG_XML_PATH_DEFAULT_COUNTRY => 'US',
                    Config::CONFIG_XML_PATH_DEFAULT_REGION => 0,
                    Config::CONFIG_XML_PATH_DEFAULT_POSTCODE => '*',
                ],
            ],
        ];
    }
}