Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TaxAdjustmentTest.php
Go to the documentation of this file.
1 <?php
8 
10 
11 class TaxAdjustmentTest extends \PHPUnit\Framework\TestCase
12 {
16  protected $adjustment;
17 
21  protected $weeeHelperMock;
22 
26  protected $taxHelperMock;
27 
31  protected $priceCurrencyMock;
32 
36  protected $sortOrder = 5;
37 
38  protected function setUp()
39  {
40  $this->weeeHelperMock = $this->createMock(\Magento\Weee\Helper\Data::class);
41  $this->taxHelperMock = $this->createMock(\Magento\Tax\Helper\Data::class);
42  $this->priceCurrencyMock = $this->createMock(\Magento\Framework\Pricing\PriceCurrencyInterface::class);
43  $this->priceCurrencyMock->expects($this->any())
44  ->method('convertAndRound')
45  ->will(
46  $this->returnCallback(
47  function ($arg) {
48  return round($arg * 0.5, 2);
49  }
50  )
51  );
52  $this->priceCurrencyMock->expects($this->any())
53  ->method('convert')
54  ->will(
55  $this->returnCallback(
56  function ($arg) {
57  return $arg * 0.5;
58  }
59  )
60  );
61 
62  $this->adjustment = new TaxAdjustment(
63  $this->weeeHelperMock,
64  $this->taxHelperMock,
65  $this->priceCurrencyMock,
66  $this->sortOrder
67  );
68  }
69 
70  public function testGetAdjustmentCode()
71  {
72  $this->assertEquals(TaxAdjustment::ADJUSTMENT_CODE, $this->adjustment->getAdjustmentCode());
73  }
74 
75  public function testIsIncludedInBasePrice()
76  {
77  $this->assertFalse($this->adjustment->isIncludedInBasePrice());
78  }
79 
88  $taxDisplayExclTax,
89  $isWeeeTaxable,
90  $weeeDisplayConfig,
91  $expectedResult
92  ) {
93  $this->weeeHelperMock->expects($this->any())
94  ->method('isEnabled')
95  ->willReturn(true);
96  $this->weeeHelperMock->expects($this->any())
97  ->method('isTaxable')
98  ->willReturn($isWeeeTaxable);
99  $this->taxHelperMock->expects($this->any())
100  ->method('displayPriceExcludingTax')
101  ->willReturn($taxDisplayExclTax);
102 
103  $displayTypes = [
105  ];
106  $this->weeeHelperMock->expects($this->any())
107  ->method('typeOfDisplay')
108  ->with($displayTypes)
109  ->will($this->returnValue($weeeDisplayConfig));
110 
111  $this->assertEquals($expectedResult, $this->adjustment->isIncludedInDisplayPrice());
112  }
113 
118  {
119  return [
120  'display_incl_tax' => [
121  'tax_display_excl_tax' => false,
122  'is_weee_taxable' => true,
123  'weee_display_config' => false,
124  'expected_result' => true,
125  ],
126  'display_incl_tax_excl_weee' => [
127  'tax_display_excl_tax' => false,
128  'is_weee_taxable' => true,
129  'weee_display_config' => true,
130  'expected_result' => false,
131  ],
132  'display_excl_tax' => [
133  'tax_display_excl_tax' => true,
134  'is_weee_taxable' => true,
135  'weee_display_config' => true,
136  'expected_result' => false,
137  ],
138  'display_excl_tax_incl_weee' => [
139  'tax_display_excl_tax' => true,
140  'is_weee_taxable' => true,
141  'weee_display_config' => false,
142  'expected_result' => false,
143  ],
144  ];
145  }
146 
153  public function testApplyAdjustment($amount, $weeeAttributes, $expectedResult)
154  {
155  $object = $this->getMockForAbstractClass(\Magento\Framework\Pricing\SaleableInterface::class);
156 
157  $this->weeeHelperMock->expects($this->any())
158  ->method('getProductWeeeAttributes')
159  ->will($this->returnValue($weeeAttributes));
160 
161  $this->assertEquals($expectedResult, $this->adjustment->applyAdjustment($amount, $object));
162  }
163 
167  public function applyAdjustmentDataProvider()
168  {
169  return [
170  [
171  'amount' => 10,
172  'weee_attributes' => [
173  new \Magento\Framework\DataObject(
174  [
175  'tax_amount' => 5,
176  ]
177  ),
178  new \Magento\Framework\DataObject(
179  [
180  'tax_amount' => 2.5,
181  ]
182  ),
183 
184  ],
185  'expected_result' => 13.75,
186  ],
187  ];
188  }
189 }
const DISPLAY_EXCL
Definition: Tax.php:40
testApplyAdjustment($amount, $weeeAttributes, $expectedResult)
$amount
Definition: order.php:14
testIsIncludedInDisplayPrice( $taxDisplayExclTax, $isWeeeTaxable, $weeeDisplayConfig, $expectedResult)