AdjustmentTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Tax\Pricing;
  7. class AdjustmentTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @param $isShippingPriceExcludeTax
  11. * @param $expectedResult
  12. */
  13. protected function isIncludedInBasePricePrice($isShippingPriceExcludeTax, $expectedResult)
  14. {
  15. $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
  16. /** @var \Magento\Tax\Model\Config $config */
  17. $config = $objectManager->get(\Magento\Tax\Model\Config::class);
  18. /** @var \Magento\Tax\Pricing\Adjustment $model */
  19. $model = $objectManager->create(\Magento\Tax\Pricing\Adjustment::class);
  20. $config->setNeedUseShippingExcludeTax($isShippingPriceExcludeTax);
  21. // Run tested method
  22. $result = $model->isIncludedInBasePrice();
  23. // Check expectations
  24. $this->assertInternalType('bool', $result);
  25. $this->assertEquals($expectedResult, $result);
  26. }
  27. /**
  28. * @param bool $isShippingPriceExcludeTax
  29. * @param bool $expectedResult
  30. * @magentoConfigFixture current_store tax/calculation/price_includes_tax 1
  31. * @dataProvider isIncludedInBasePricePriceIncludeTaxEnabledDataProvider
  32. */
  33. public function testIsIncludedInBasePricePriceIncludeTacEnabled($isShippingPriceExcludeTax, $expectedResult)
  34. {
  35. $this->isIncludedInBasePricePrice($isShippingPriceExcludeTax, $expectedResult);
  36. }
  37. /**
  38. * @param bool $isShippingPriceExcludeTax
  39. * @param bool $expectedResult
  40. * @magentoConfigFixture current_store tax/calculation/price_includes_tax 0
  41. * @dataProvider isIncludedInBasePricePriceIncludeTaxDisabledDataProvider
  42. */
  43. public function testIsIncludedInBasePricePriceIncludeTacDisabled($isShippingPriceExcludeTax, $expectedResult)
  44. {
  45. $this->isIncludedInBasePricePrice($isShippingPriceExcludeTax, $expectedResult);
  46. }
  47. /**
  48. * @return array
  49. */
  50. public function isIncludedInBasePricePriceIncludeTaxEnabledDataProvider()
  51. {
  52. return [
  53. [0, true],
  54. [1, true],
  55. ];
  56. }
  57. /**
  58. * @return array
  59. */
  60. public function isIncludedInBasePricePriceIncludeTaxDisabledDataProvider()
  61. {
  62. return [
  63. [0, false],
  64. [1, true],
  65. ];
  66. }
  67. /**
  68. * test template for isIncludedInDisplayPrice
  69. *
  70. * @param $expectedResult
  71. */
  72. protected function isIncludedInDisplayPrice($expectedResult)
  73. {
  74. // Instantiate objects
  75. $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
  76. /** @var \Magento\Tax\Pricing\Adjustment $model */
  77. $model = $objectManager->create(\Magento\Tax\Pricing\Adjustment::class);
  78. // Run tested method
  79. $result = $model->isIncludedInDisplayPrice();
  80. // Check expectations
  81. $this->assertInternalType('bool', $result);
  82. $this->assertEquals($expectedResult, $result);
  83. }
  84. /**
  85. * @magentoAppIsolation enabled
  86. * @magentoConfigFixture current_store tax/display/type 1
  87. */
  88. public function testIsIncludedInDisplayPriceExcludingTax()
  89. {
  90. $this->isIncludedInDisplayPrice(false);
  91. }
  92. /**
  93. * @magentoAppIsolation enabled
  94. * @magentoConfigFixture current_store tax/display/type 2
  95. */
  96. public function testIsIncludedInDisplayPriceIncludingTax()
  97. {
  98. $this->isIncludedInDisplayPrice(true);
  99. }
  100. /**
  101. * @magentoAppIsolation enabled
  102. * @magentoConfigFixture current_store tax/display/type 3
  103. */
  104. public function testIsIncludedInDisplayPriceBoth()
  105. {
  106. $this->isIncludedInDisplayPrice(true);
  107. }
  108. /**
  109. * @magentoAppIsolation enabled
  110. * @magentoConfigFixture current_store tax/display/type 100500
  111. */
  112. public function testIsIncludedInDisplayPriceWrongValue()
  113. {
  114. $this->isIncludedInDisplayPrice(false);
  115. }
  116. }