TaxAdjustmentTest.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Weee\Test\Unit\Pricing;
  7. use Magento\Weee\Pricing\TaxAdjustment;
  8. class TaxAdjustmentTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var TaxAdjustment
  12. */
  13. protected $adjustment;
  14. /**
  15. * @var \Magento\Weee\Helper\Data | \PHPUnit_Framework_MockObject_MockObject
  16. */
  17. protected $weeeHelperMock;
  18. /**
  19. * @var \Magento\Tax\Helper\Data | \PHPUnit_Framework_MockObject_MockObject
  20. */
  21. protected $taxHelperMock;
  22. /**
  23. * @var \Magento\Framework\Pricing\PriceCurrencyInterface|\PHPUnit_Framework_MockObject_MockObject
  24. */
  25. protected $priceCurrencyMock;
  26. /**
  27. * @var int
  28. */
  29. protected $sortOrder = 5;
  30. protected function setUp()
  31. {
  32. $this->weeeHelperMock = $this->createMock(\Magento\Weee\Helper\Data::class);
  33. $this->taxHelperMock = $this->createMock(\Magento\Tax\Helper\Data::class);
  34. $this->priceCurrencyMock = $this->createMock(\Magento\Framework\Pricing\PriceCurrencyInterface::class);
  35. $this->priceCurrencyMock->expects($this->any())
  36. ->method('convertAndRound')
  37. ->will(
  38. $this->returnCallback(
  39. function ($arg) {
  40. return round($arg * 0.5, 2);
  41. }
  42. )
  43. );
  44. $this->priceCurrencyMock->expects($this->any())
  45. ->method('convert')
  46. ->will(
  47. $this->returnCallback(
  48. function ($arg) {
  49. return $arg * 0.5;
  50. }
  51. )
  52. );
  53. $this->adjustment = new TaxAdjustment(
  54. $this->weeeHelperMock,
  55. $this->taxHelperMock,
  56. $this->priceCurrencyMock,
  57. $this->sortOrder
  58. );
  59. }
  60. public function testGetAdjustmentCode()
  61. {
  62. $this->assertEquals(TaxAdjustment::ADJUSTMENT_CODE, $this->adjustment->getAdjustmentCode());
  63. }
  64. public function testIsIncludedInBasePrice()
  65. {
  66. $this->assertFalse($this->adjustment->isIncludedInBasePrice());
  67. }
  68. /**
  69. * @param bool $taxDisplayExclTax
  70. * @param bool $isWeeeTaxable
  71. * @param bool $weeeDisplayConfig
  72. * @param bool $expectedResult
  73. * @dataProvider isIncludedInDisplayPriceDataProvider
  74. */
  75. public function testIsIncludedInDisplayPrice(
  76. $taxDisplayExclTax,
  77. $isWeeeTaxable,
  78. $weeeDisplayConfig,
  79. $expectedResult
  80. ) {
  81. $this->weeeHelperMock->expects($this->any())
  82. ->method('isEnabled')
  83. ->willReturn(true);
  84. $this->weeeHelperMock->expects($this->any())
  85. ->method('isTaxable')
  86. ->willReturn($isWeeeTaxable);
  87. $this->taxHelperMock->expects($this->any())
  88. ->method('displayPriceExcludingTax')
  89. ->willReturn($taxDisplayExclTax);
  90. $displayTypes = [
  91. \Magento\Weee\Model\Tax::DISPLAY_EXCL,
  92. ];
  93. $this->weeeHelperMock->expects($this->any())
  94. ->method('typeOfDisplay')
  95. ->with($displayTypes)
  96. ->will($this->returnValue($weeeDisplayConfig));
  97. $this->assertEquals($expectedResult, $this->adjustment->isIncludedInDisplayPrice());
  98. }
  99. /**
  100. * @return array
  101. */
  102. public function isIncludedInDisplayPriceDataProvider()
  103. {
  104. return [
  105. 'display_incl_tax' => [
  106. 'tax_display_excl_tax' => false,
  107. 'is_weee_taxable' => true,
  108. 'weee_display_config' => false,
  109. 'expected_result' => true,
  110. ],
  111. 'display_incl_tax_excl_weee' => [
  112. 'tax_display_excl_tax' => false,
  113. 'is_weee_taxable' => true,
  114. 'weee_display_config' => true,
  115. 'expected_result' => false,
  116. ],
  117. 'display_excl_tax' => [
  118. 'tax_display_excl_tax' => true,
  119. 'is_weee_taxable' => true,
  120. 'weee_display_config' => true,
  121. 'expected_result' => false,
  122. ],
  123. 'display_excl_tax_incl_weee' => [
  124. 'tax_display_excl_tax' => true,
  125. 'is_weee_taxable' => true,
  126. 'weee_display_config' => false,
  127. 'expected_result' => false,
  128. ],
  129. ];
  130. }
  131. /**
  132. * @param float $amount
  133. * @param \Magento\Framework\DataObject[] $weeeAttributes
  134. * @param float $expectedResult
  135. * @dataProvider applyAdjustmentDataProvider
  136. */
  137. public function testApplyAdjustment($amount, $weeeAttributes, $expectedResult)
  138. {
  139. $object = $this->getMockForAbstractClass(\Magento\Framework\Pricing\SaleableInterface::class);
  140. $this->weeeHelperMock->expects($this->any())
  141. ->method('getProductWeeeAttributes')
  142. ->will($this->returnValue($weeeAttributes));
  143. $this->assertEquals($expectedResult, $this->adjustment->applyAdjustment($amount, $object));
  144. }
  145. /**
  146. * @return array
  147. */
  148. public function applyAdjustmentDataProvider()
  149. {
  150. return [
  151. [
  152. 'amount' => 10,
  153. 'weee_attributes' => [
  154. new \Magento\Framework\DataObject(
  155. [
  156. 'tax_amount' => 5,
  157. ]
  158. ),
  159. new \Magento\Framework\DataObject(
  160. [
  161. 'tax_amount' => 2.5,
  162. ]
  163. ),
  164. ],
  165. 'expected_result' => 13.75,
  166. ],
  167. ];
  168. }
  169. }