TaxConfigProviderTest.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Tax\Test\Unit\Model;
  7. use \Magento\Tax\Model\Config;
  8. class TaxConfigProviderTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var \PHPUnit_Framework_MockObject_MockObject
  12. */
  13. protected $taxHelperMock;
  14. /**
  15. * @var \PHPUnit_Framework_MockObject_MockObject
  16. */
  17. protected $taxConfigMock;
  18. /**
  19. * @var \PHPUnit_Framework_MockObject_MockObject
  20. */
  21. protected $checkoutSessionMock;
  22. /**
  23. * @var \PHPUnit_Framework_MockObject_MockObject
  24. */
  25. protected $scopeConfigMock;
  26. /**
  27. * @var \PHPUnit_Framework_MockObject_MockObject
  28. */
  29. protected $quoteMock;
  30. /**
  31. * @var \Magento\Tax\Model\TaxConfigProvider
  32. */
  33. protected $model;
  34. protected function setUp()
  35. {
  36. $this->taxHelperMock = $this->createMock(\Magento\Tax\Helper\Data::class);
  37. $this->taxConfigMock = $this->createMock(\Magento\Tax\Model\Config::class);
  38. $this->checkoutSessionMock = $this->createMock(\Magento\Checkout\Model\Session::class);
  39. $this->scopeConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
  40. $this->quoteMock = $this->createMock(\Magento\Quote\Model\Quote::class);
  41. $this->checkoutSessionMock->expects($this->any())->method('getQuote')->willReturn($this->quoteMock);
  42. $this->model = new \Magento\Tax\Model\TaxConfigProvider(
  43. $this->taxHelperMock,
  44. $this->taxConfigMock,
  45. $this->checkoutSessionMock,
  46. $this->scopeConfigMock
  47. );
  48. }
  49. /**
  50. * @dataProvider getConfigDataProvider
  51. * @param array $expectedResult
  52. * @param int $cartShippingBoth
  53. * @param int $cartShippingExclTax
  54. * @param int $cartBothPrices
  55. * @param int $cartPriceExclTax
  56. * @param int $cartSubTotalBoth
  57. * @param int $cartSubTotalExclTax
  58. * @param string|null $calculationType
  59. * @param bool $isQuoteVirtual
  60. */
  61. public function testGetConfig(
  62. $expectedResult,
  63. $cartShippingBoth,
  64. $cartShippingExclTax,
  65. $cartBothPrices,
  66. $cartPriceExclTax,
  67. $cartSubTotalBoth,
  68. $cartSubTotalExclTax,
  69. $isQuoteVirtual,
  70. $config
  71. ) {
  72. $this->taxConfigMock->expects($this->any())->method('displayCartShippingBoth')
  73. ->will($this->returnValue($cartShippingBoth));
  74. $this->taxConfigMock->expects($this->any())->method('displayCartShippingExclTax')
  75. ->will($this->returnValue($cartShippingExclTax));
  76. $this->taxHelperMock->expects($this->any())->method('displayCartBothPrices')
  77. ->will($this->returnValue($cartBothPrices));
  78. $this->taxHelperMock->expects($this->any())->method('displayCartPriceExclTax')
  79. ->will($this->returnValue($cartPriceExclTax));
  80. $this->taxConfigMock->expects($this->any())->method('displayCartSubtotalBoth')
  81. ->will($this->returnValue($cartSubTotalBoth));
  82. $this->taxConfigMock->expects($this->any())->method('displayCartSubtotalExclTax')
  83. ->will($this->returnValue($cartSubTotalExclTax));
  84. $this->taxHelperMock->expects(($this->any()))->method('displayShippingPriceExcludingTax')
  85. ->will($this->returnValue(1));
  86. $this->taxHelperMock->expects(($this->any()))->method('displayShippingBothPrices')
  87. ->will($this->returnValue(1));
  88. $this->taxHelperMock->expects(($this->any()))->method('displayFullSummary')
  89. ->will($this->returnValue(1));
  90. $this->taxConfigMock->expects(($this->any()))->method('displayCartTaxWithGrandTotal')
  91. ->will($this->returnValue(1));
  92. $this->taxConfigMock->expects(($this->any()))->method('displayCartZeroTax')
  93. ->will($this->returnValue(1));
  94. $valueMap = [];
  95. foreach ($config as $key => $value) {
  96. $valueMap[] = [$key, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, null, $value];
  97. }
  98. $this->scopeConfigMock->expects($this->atLeastOnce())
  99. ->method('getValue')
  100. ->willReturnMap($valueMap);
  101. $this->quoteMock->expects($this->any())->method('isVirtual')->willReturn($isQuoteVirtual);
  102. $this->assertEquals($expectedResult, $this->model->getConfig());
  103. }
  104. /**
  105. * @return array
  106. * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  107. */
  108. public function getConfigDataProvider()
  109. {
  110. return [
  111. [
  112. 'expectedResult' => [
  113. 'isDisplayShippingPriceExclTax' => 1,
  114. 'isDisplayShippingBothPrices' => 1,
  115. 'reviewShippingDisplayMode' => 'both',
  116. 'reviewItemPriceDisplayMode' => 'both',
  117. 'reviewTotalsDisplayMode' => 'both',
  118. 'includeTaxInGrandTotal' => 1,
  119. 'isFullTaxSummaryDisplayed' => 1,
  120. 'isZeroTaxDisplayed' => 1,
  121. 'reloadOnBillingAddress' => false,
  122. 'defaultCountryId' => 'US',
  123. 'defaultRegionId' => 12,
  124. 'defaultPostcode' => '*',
  125. ],
  126. 'cartShippingBoth' => 1,
  127. 'cartShippingExclTax' => 1,
  128. 'cartBothPrices' => 1,
  129. 'cartPriceExclTax' => 1,
  130. 'cartSubTotalBoth' => 1,
  131. 'cartSubTotalExclTax' => 1,
  132. 'isQuoteVirtual' => false,
  133. 'config' => [
  134. Config::CONFIG_XML_PATH_BASED_ON => 'shipping',
  135. Config::CONFIG_XML_PATH_DEFAULT_COUNTRY => 'US',
  136. Config::CONFIG_XML_PATH_DEFAULT_REGION => 12,
  137. Config::CONFIG_XML_PATH_DEFAULT_POSTCODE => '*',
  138. ],
  139. ],
  140. [
  141. 'expectedResult' => [
  142. 'isDisplayShippingPriceExclTax' => 1,
  143. 'isDisplayShippingBothPrices' => 1,
  144. 'reviewShippingDisplayMode' => 'excluding',
  145. 'reviewItemPriceDisplayMode' => 'excluding',
  146. 'reviewTotalsDisplayMode' => 'excluding',
  147. 'includeTaxInGrandTotal' => 1,
  148. 'isFullTaxSummaryDisplayed' => 1,
  149. 'isZeroTaxDisplayed' => 1,
  150. 'reloadOnBillingAddress' => true,
  151. 'defaultCountryId' => 'US',
  152. 'defaultRegionId' => 12,
  153. 'defaultPostcode' => '*',
  154. ],
  155. 'cartShippingBoth' => 0,
  156. 'cartShippingExclTax' => 1,
  157. 'cartBothPrices' => 0,
  158. 'cartPriceExclTax' => 1,
  159. 'cartSubTotalBoth' => 0,
  160. 'cartSubTotalExclTax' => 1,
  161. 'isQuoteVirtual' => false,
  162. 'config' => [
  163. Config::CONFIG_XML_PATH_BASED_ON => 'billing',
  164. Config::CONFIG_XML_PATH_DEFAULT_COUNTRY => 'US',
  165. Config::CONFIG_XML_PATH_DEFAULT_REGION => 12,
  166. Config::CONFIG_XML_PATH_DEFAULT_POSTCODE => '*',
  167. ],
  168. ],
  169. [
  170. 'expectedResult' => [
  171. 'isDisplayShippingPriceExclTax' => 1,
  172. 'isDisplayShippingBothPrices' => 1,
  173. 'reviewShippingDisplayMode' => 'including',
  174. 'reviewItemPriceDisplayMode' => 'including',
  175. 'reviewTotalsDisplayMode' => 'including',
  176. 'includeTaxInGrandTotal' => 1,
  177. 'isFullTaxSummaryDisplayed' => 1,
  178. 'isZeroTaxDisplayed' => 1,
  179. 'reloadOnBillingAddress' => true,
  180. 'defaultCountryId' => 'US',
  181. 'defaultRegionId' => 12,
  182. 'defaultPostcode' => '*',
  183. ],
  184. 'cartShippingBoth' => 0,
  185. 'cartShippingExclTax' => 0,
  186. 'cartBothPrices' => 0,
  187. 'cartPriceExclTax' => 0,
  188. 'cartSubTotalBoth' => 0,
  189. 'cartSubTotalExclTax' => 0,
  190. 'isQuoteVirtual' => true,
  191. 'config' => [
  192. Config::CONFIG_XML_PATH_BASED_ON => 'shipping',
  193. Config::CONFIG_XML_PATH_DEFAULT_COUNTRY => 'US',
  194. Config::CONFIG_XML_PATH_DEFAULT_REGION => 12,
  195. Config::CONFIG_XML_PATH_DEFAULT_POSTCODE => '*',
  196. ],
  197. ],
  198. [
  199. 'expectedResult' => [
  200. 'isDisplayShippingPriceExclTax' => 1,
  201. 'isDisplayShippingBothPrices' => 1,
  202. 'reviewShippingDisplayMode' => 'including',
  203. 'reviewItemPriceDisplayMode' => 'including',
  204. 'reviewTotalsDisplayMode' => 'including',
  205. 'includeTaxInGrandTotal' => 1,
  206. 'isFullTaxSummaryDisplayed' => 1,
  207. 'isZeroTaxDisplayed' => 1,
  208. 'reloadOnBillingAddress' => true,
  209. 'defaultCountryId' => 'US',
  210. 'defaultRegionId' => 12,
  211. 'defaultPostcode' => '*',
  212. ],
  213. 'cartShippingBoth' => 0,
  214. 'cartShippingExclTax' => 0,
  215. 'cartBothPrices' => 0,
  216. 'cartPriceExclTax' => 0,
  217. 'cartSubTotalBoth' => 0,
  218. 'cartSubTotalExclTax' => 0,
  219. 'isQuoteVirtual' => true,
  220. 'config' => [
  221. Config::CONFIG_XML_PATH_BASED_ON => 'billing',
  222. Config::CONFIG_XML_PATH_DEFAULT_COUNTRY => 'US',
  223. Config::CONFIG_XML_PATH_DEFAULT_REGION => 12,
  224. Config::CONFIG_XML_PATH_DEFAULT_POSTCODE => '*',
  225. ],
  226. ],
  227. [
  228. 'expectedResult' => [
  229. 'isDisplayShippingPriceExclTax' => 1,
  230. 'isDisplayShippingBothPrices' => 1,
  231. 'reviewShippingDisplayMode' => 'both',
  232. 'reviewItemPriceDisplayMode' => 'both',
  233. 'reviewTotalsDisplayMode' => 'both',
  234. 'includeTaxInGrandTotal' => 1,
  235. 'isFullTaxSummaryDisplayed' => 1,
  236. 'isZeroTaxDisplayed' => 1,
  237. 'reloadOnBillingAddress' => false,
  238. 'defaultCountryId' => 'US',
  239. 'defaultRegionId' => 12,
  240. 'defaultPostcode' => '*',
  241. ],
  242. 'cartShippingBoth' => 1,
  243. 'cartShippingExclTax' => 0,
  244. 'cartBothPrices' => 1,
  245. 'cartPriceExclTax' => 0,
  246. 'cartSubTotalBoth' => 1,
  247. 'cartSubTotalExclTax' => 0,
  248. 'isQuoteVirtual' => false,
  249. 'config' => [
  250. Config::CONFIG_XML_PATH_BASED_ON => 'shipping',
  251. Config::CONFIG_XML_PATH_DEFAULT_COUNTRY => 'US',
  252. Config::CONFIG_XML_PATH_DEFAULT_REGION => 12,
  253. Config::CONFIG_XML_PATH_DEFAULT_POSTCODE => '*',
  254. ],
  255. ],
  256. [
  257. 'expectedResult' => [
  258. 'isDisplayShippingPriceExclTax' => 1,
  259. 'isDisplayShippingBothPrices' => 1,
  260. 'reviewShippingDisplayMode' => 'excluding',
  261. 'reviewItemPriceDisplayMode' => 'including',
  262. 'reviewTotalsDisplayMode' => 'both',
  263. 'includeTaxInGrandTotal' => 1,
  264. 'isFullTaxSummaryDisplayed' => 1,
  265. 'isZeroTaxDisplayed' => 1,
  266. 'reloadOnBillingAddress' => false,
  267. 'defaultCountryId' => 'US',
  268. 'defaultRegionId' => 12,
  269. 'defaultPostcode' => '*',
  270. ],
  271. 'cartShippingBoth' => 0,
  272. 'cartShippingExclTax' => 1,
  273. 'cartBothPrices' => 0,
  274. 'cartPriceExclTax' => 0,
  275. 'cartSubTotalBoth' => 1,
  276. 'cartSubTotalExclTax' => 0,
  277. 'isQuoteVirtual' => false,
  278. 'config' => [
  279. Config::CONFIG_XML_PATH_BASED_ON => 'shipping',
  280. Config::CONFIG_XML_PATH_DEFAULT_COUNTRY => 'US',
  281. Config::CONFIG_XML_PATH_DEFAULT_REGION => 12,
  282. Config::CONFIG_XML_PATH_DEFAULT_POSTCODE => '*',
  283. ],
  284. ],
  285. 'zeroRegionToNull' => [
  286. 'expectedResult' => [
  287. 'isDisplayShippingPriceExclTax' => 1,
  288. 'isDisplayShippingBothPrices' => 1,
  289. 'reviewShippingDisplayMode' => 'excluding',
  290. 'reviewItemPriceDisplayMode' => 'including',
  291. 'reviewTotalsDisplayMode' => 'both',
  292. 'includeTaxInGrandTotal' => 1,
  293. 'isFullTaxSummaryDisplayed' => 1,
  294. 'isZeroTaxDisplayed' => 1,
  295. 'reloadOnBillingAddress' => false,
  296. 'defaultCountryId' => 'US',
  297. 'defaultRegionId' => null,
  298. 'defaultPostcode' => '*',
  299. ],
  300. 'cartShippingBoth' => 0,
  301. 'cartShippingExclTax' => 1,
  302. 'cartBothPrices' => 0,
  303. 'cartPriceExclTax' => 0,
  304. 'cartSubTotalBoth' => 1,
  305. 'cartSubTotalExclTax' => 0,
  306. 'isQuoteVirtual' => false,
  307. 'config' => [
  308. Config::CONFIG_XML_PATH_BASED_ON => 'shipping',
  309. Config::CONFIG_XML_PATH_DEFAULT_COUNTRY => 'US',
  310. Config::CONFIG_XML_PATH_DEFAULT_REGION => 0,
  311. Config::CONFIG_XML_PATH_DEFAULT_POSTCODE => '*',
  312. ],
  313. ],
  314. ];
  315. }
  316. }