/vendor/magento/module-tax/Test/Unit/Model/ConfigTest.php

https://gitlab.com/yousafsyed/easternglamor · PHP · 371 lines · 311 code · 12 blank · 48 comment · 0 complexity · 1ede5446c65f5da097ab2377f32b3734 MD5 · raw file

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