123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330 |
- <?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 => '*',
- ],
- ],
- ];
- }
- }
|