ConfigTest.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Test class for \Magento\Tax\Model\Config
  8. */
  9. namespace Magento\Tax\Test\Unit\Model;
  10. use \Magento\Tax\Model\Config;
  11. class ConfigTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * Tests the setter/getter methods that bypass the ScopeConfigInterface object
  15. *
  16. * @param string $setterMethod
  17. * @param string $getterMethod
  18. * @param bool $value
  19. * @dataProvider dataProviderDirectSettersGettersMethods
  20. */
  21. public function testDirectSettersGettersMethods($setterMethod, $getterMethod, $value)
  22. {
  23. // Need a mocked object with only dummy methods. It is just needed for construction.
  24. // The setter/getter methods do not use this object (for this set of tests).
  25. $scopeConfigMock = $this->getMockForAbstractClass(\Magento\Framework\App\Config\ScopeConfigInterface::class);
  26. /** @var \Magento\Tax\Model\Config */
  27. $model = new Config($scopeConfigMock);
  28. $model->{$setterMethod}($value);
  29. $this->assertEquals($value, $model->{$getterMethod}());
  30. }
  31. /**
  32. * @return array
  33. */
  34. public function dataProviderDirectSettersGettersMethods()
  35. {
  36. return [
  37. ['setShippingPriceIncludeTax', 'shippingPriceIncludesTax', true],
  38. ['setShippingPriceIncludeTax', 'shippingPriceIncludesTax', false],
  39. ['setNeedUseShippingExcludeTax', 'getNeedUseShippingExcludeTax', true],
  40. ['setNeedUseShippingExcludeTax', 'getNeedUseShippingExcludeTax', false],
  41. ['setPriceIncludesTax', 'priceIncludesTax', true],
  42. ['setPriceIncludesTax', 'priceIncludesTax', false],
  43. ['setPriceIncludesTax', 'priceIncludesTax', null]
  44. ];
  45. }
  46. /**
  47. * Tests the getCalculationSequence method
  48. *
  49. * @param bool $applyTaxAfterDiscount
  50. * @param bool $discountTaxIncl
  51. * @param string $expectedValue
  52. * @dataProvider dataProviderGetCalculationSequence
  53. */
  54. public function testGetCalculationSequence($applyTaxAfterDiscount, $discountTaxIncl, $expectedValue)
  55. {
  56. $scopeConfigMock = $this->getMockForAbstractClass(\Magento\Framework\App\Config\ScopeConfigInterface::class);
  57. $scopeConfigMock->expects($this->at(0))
  58. ->method('getValue')
  59. ->will($this->returnValue($applyTaxAfterDiscount));
  60. $scopeConfigMock->expects($this->at(1))
  61. ->method('getValue')
  62. ->will($this->returnValue($discountTaxIncl));
  63. /** @var \Magento\Tax\Model\Config */
  64. $model = new Config($scopeConfigMock);
  65. $this->assertEquals($expectedValue, $model->getCalculationSequence());
  66. }
  67. /**
  68. * @return array
  69. */
  70. public function dataProviderGetCalculationSequence()
  71. {
  72. return [
  73. [true, true, \Magento\Tax\Model\Calculation::CALC_TAX_AFTER_DISCOUNT_ON_INCL],
  74. [true, false, \Magento\Tax\Model\Calculation::CALC_TAX_AFTER_DISCOUNT_ON_EXCL],
  75. [false, true, \Magento\Tax\Model\Calculation::CALC_TAX_BEFORE_DISCOUNT_ON_INCL],
  76. [false, false, \Magento\Tax\Model\Calculation::CALC_TAX_BEFORE_DISCOUNT_ON_EXCL]
  77. ];
  78. }
  79. /**
  80. * Tests the methods that rely on the ScopeConfigInterface object to provide their return values
  81. *
  82. * @param string $method
  83. * @param string $path
  84. * @param bool|int $configValue
  85. * @param bool $expectedValue
  86. * @dataProvider dataProviderScopeConfigMethods
  87. */
  88. public function testScopeConfigMethods($method, $path, $configValue, $expectedValue)
  89. {
  90. $scopeConfigMock = $this->getMockForAbstractClass(\Magento\Framework\App\Config\ScopeConfigInterface::class);
  91. $scopeConfigMock->expects($this->once())
  92. ->method('getValue')
  93. ->with($path, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, null)
  94. ->will($this->returnValue($configValue));
  95. /** @var \Magento\Tax\Model\Config */
  96. $model = new Config($scopeConfigMock);
  97. $this->assertEquals($expectedValue, $model->{$method}());
  98. }
  99. /**
  100. * @return array
  101. * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  102. */
  103. public function dataProviderScopeConfigMethods()
  104. {
  105. return [
  106. [
  107. 'priceIncludesTax',
  108. Config::CONFIG_XML_PATH_PRICE_INCLUDES_TAX,
  109. true,
  110. true,
  111. ],
  112. [
  113. 'applyTaxAfterDiscount',
  114. Config::CONFIG_XML_PATH_APPLY_AFTER_DISCOUNT,
  115. true,
  116. true
  117. ],
  118. [
  119. 'getPriceDisplayType',
  120. Config::CONFIG_XML_PATH_PRICE_DISPLAY_TYPE,
  121. true,
  122. true
  123. ],
  124. [
  125. 'discountTax',
  126. Config::CONFIG_XML_PATH_DISCOUNT_TAX,
  127. 1,
  128. true
  129. ],
  130. [
  131. 'getAlgorithm',
  132. Config::XML_PATH_ALGORITHM,
  133. true,
  134. true
  135. ],
  136. [
  137. 'getShippingTaxClass',
  138. Config::CONFIG_XML_PATH_SHIPPING_TAX_CLASS,
  139. true,
  140. true
  141. ],
  142. [
  143. 'getShippingPriceDisplayType',
  144. Config::CONFIG_XML_PATH_DISPLAY_SHIPPING,
  145. true,
  146. true
  147. ],
  148. [
  149. 'shippingPriceIncludesTax',
  150. Config::CONFIG_XML_PATH_SHIPPING_INCLUDES_TAX,
  151. true,
  152. true
  153. ],
  154. [
  155. 'displayCartPricesInclTax',
  156. Config::XML_PATH_DISPLAY_CART_PRICE,
  157. Config::DISPLAY_TYPE_INCLUDING_TAX,
  158. true
  159. ],
  160. [
  161. 'displayCartPricesExclTax',
  162. Config::XML_PATH_DISPLAY_CART_PRICE,
  163. Config::DISPLAY_TYPE_EXCLUDING_TAX,
  164. true
  165. ],
  166. [
  167. 'displayCartPricesBoth',
  168. Config::XML_PATH_DISPLAY_CART_PRICE,
  169. Config::DISPLAY_TYPE_BOTH,
  170. true
  171. ],
  172. [
  173. 'displayCartSubtotalInclTax',
  174. Config::XML_PATH_DISPLAY_CART_SUBTOTAL,
  175. Config::DISPLAY_TYPE_INCLUDING_TAX,
  176. true
  177. ],
  178. [
  179. 'displayCartSubtotalExclTax',
  180. Config::XML_PATH_DISPLAY_CART_SUBTOTAL,
  181. Config::DISPLAY_TYPE_EXCLUDING_TAX,
  182. true
  183. ],
  184. [
  185. 'displayCartSubtotalBoth',
  186. Config::XML_PATH_DISPLAY_CART_SUBTOTAL,
  187. Config::DISPLAY_TYPE_BOTH,
  188. true
  189. ],
  190. [
  191. 'displayCartShippingInclTax',
  192. Config::XML_PATH_DISPLAY_CART_SHIPPING,
  193. Config::DISPLAY_TYPE_INCLUDING_TAX,
  194. true
  195. ],
  196. [
  197. 'displayCartShippingExclTax',
  198. Config::XML_PATH_DISPLAY_CART_SHIPPING,
  199. Config::DISPLAY_TYPE_EXCLUDING_TAX,
  200. true
  201. ],
  202. [
  203. 'displayCartShippingBoth',
  204. Config::XML_PATH_DISPLAY_CART_SHIPPING,
  205. Config::DISPLAY_TYPE_BOTH,
  206. true
  207. ],
  208. [
  209. 'displayCartDiscountInclTax',
  210. Config::XML_PATH_DISPLAY_CART_DISCOUNT,
  211. Config::DISPLAY_TYPE_INCLUDING_TAX,
  212. true
  213. ],
  214. [
  215. 'displayCartDiscountExclTax',
  216. Config::XML_PATH_DISPLAY_CART_DISCOUNT,
  217. Config::DISPLAY_TYPE_EXCLUDING_TAX,
  218. true
  219. ],
  220. [
  221. 'displayCartDiscountBoth',
  222. Config::XML_PATH_DISPLAY_CART_DISCOUNT,
  223. Config::DISPLAY_TYPE_BOTH,
  224. true
  225. ],
  226. [
  227. 'displayCartTaxWithGrandTotal',
  228. Config::XML_PATH_DISPLAY_CART_GRANDTOTAL,
  229. true,
  230. true
  231. ],
  232. [
  233. 'displayCartFullSummary',
  234. Config::XML_PATH_DISPLAY_CART_FULL_SUMMARY,
  235. true,
  236. true
  237. ],
  238. [
  239. 'displayCartZeroTax',
  240. Config::XML_PATH_DISPLAY_CART_ZERO_TAX,
  241. true,
  242. true
  243. ],
  244. [
  245. 'displaySalesPricesInclTax',
  246. Config::XML_PATH_DISPLAY_SALES_PRICE,
  247. Config::DISPLAY_TYPE_INCLUDING_TAX,
  248. true
  249. ],
  250. [
  251. 'displaySalesPricesExclTax',
  252. Config::XML_PATH_DISPLAY_SALES_PRICE,
  253. Config::DISPLAY_TYPE_EXCLUDING_TAX,
  254. true
  255. ],
  256. [
  257. 'displaySalesPricesBoth',
  258. Config::XML_PATH_DISPLAY_SALES_PRICE,
  259. Config::DISPLAY_TYPE_BOTH,
  260. true
  261. ],
  262. [
  263. 'displaySalesSubtotalInclTax',
  264. Config::XML_PATH_DISPLAY_SALES_SUBTOTAL,
  265. Config::DISPLAY_TYPE_INCLUDING_TAX,
  266. true
  267. ],
  268. [
  269. 'displaySalesSubtotalExclTax',
  270. Config::XML_PATH_DISPLAY_SALES_SUBTOTAL,
  271. Config::DISPLAY_TYPE_EXCLUDING_TAX,
  272. true
  273. ],
  274. [
  275. 'displaySalesSubtotalBoth',
  276. Config::XML_PATH_DISPLAY_SALES_SUBTOTAL,
  277. Config::DISPLAY_TYPE_BOTH,
  278. true
  279. ],
  280. [
  281. 'displaySalesShippingInclTax',
  282. Config::XML_PATH_DISPLAY_SALES_SHIPPING,
  283. Config::DISPLAY_TYPE_INCLUDING_TAX,
  284. true
  285. ],
  286. [
  287. 'displaySalesShippingExclTax',
  288. Config::XML_PATH_DISPLAY_SALES_SHIPPING,
  289. Config::DISPLAY_TYPE_EXCLUDING_TAX,
  290. true
  291. ],
  292. [
  293. 'displaySalesShippingBoth',
  294. Config::XML_PATH_DISPLAY_SALES_SHIPPING,
  295. Config::DISPLAY_TYPE_BOTH,
  296. true
  297. ],
  298. [
  299. 'displaySalesDiscountInclTax',
  300. Config::XML_PATH_DISPLAY_SALES_DISCOUNT,
  301. Config::DISPLAY_TYPE_INCLUDING_TAX,
  302. true
  303. ],
  304. [
  305. 'displaySalesDiscountExclTax',
  306. Config::XML_PATH_DISPLAY_SALES_DISCOUNT,
  307. Config::DISPLAY_TYPE_EXCLUDING_TAX,
  308. true
  309. ],
  310. [
  311. 'displaySalesDiscountBoth',
  312. Config::XML_PATH_DISPLAY_SALES_DISCOUNT,
  313. Config::DISPLAY_TYPE_BOTH,
  314. true
  315. ],
  316. [
  317. 'displaySalesTaxWithGrandTotal',
  318. Config::XML_PATH_DISPLAY_SALES_GRANDTOTAL,
  319. true,
  320. true
  321. ],
  322. [
  323. 'displaySalesFullSummary',
  324. Config::XML_PATH_DISPLAY_SALES_FULL_SUMMARY,
  325. true,
  326. true
  327. ],
  328. [
  329. 'displaySalesZeroTax',
  330. Config::XML_PATH_DISPLAY_SALES_ZERO_TAX,
  331. true,
  332. true
  333. ],
  334. [
  335. 'crossBorderTradeEnabled',
  336. Config::CONFIG_XML_PATH_CROSS_BORDER_TRADE_ENABLED,
  337. true,
  338. true
  339. ],
  340. [
  341. 'isWrongDisplaySettingsIgnored',
  342. Config::XML_PATH_TAX_NOTIFICATION_IGNORE_PRICE_DISPLAY,
  343. true,
  344. true
  345. ],
  346. [
  347. 'isWrongDiscountSettingsIgnored',
  348. Config::XML_PATH_TAX_NOTIFICATION_IGNORE_DISCOUNT,
  349. true,
  350. true
  351. ],
  352. [
  353. 'isWrongApplyDiscountSettingIgnored',
  354. Config::XML_PATH_TAX_NOTIFICATION_IGNORE_APPLY_DISCOUNT,
  355. true,
  356. true
  357. ],
  358. [
  359. 'getInfoUrl',
  360. Config::XML_PATH_TAX_NOTIFICATION_INFO_URL,
  361. 'http:\\kiwis.rule.com',
  362. 'http:\\kiwis.rule.com'
  363. ]
  364. ];
  365. }
  366. }