Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AdjustmentTest.php
Go to the documentation of this file.
1 <?php
8 
9 use \Magento\Tax\Pricing\Adjustment;
10 
12 
13 class AdjustmentTest extends \PHPUnit\Framework\TestCase
14 {
18  protected $adjustment;
19 
23  protected $taxHelper;
24 
28  protected $catalogHelper;
29 
33  protected $sortOrder = 5;
34 
35  protected function setUp()
36  {
37  $this->taxHelper = $this->createMock(\Magento\Tax\Helper\Data::class);
38  $this->catalogHelper = $this->createMock(\Magento\Catalog\Helper\Data::class);
39  $this->adjustment = new Adjustment($this->taxHelper, $this->catalogHelper, $this->sortOrder);
40  }
41 
42  public function testGetAdjustmentCode()
43  {
44  $this->assertEquals(Adjustment::ADJUSTMENT_CODE, $this->adjustment->getAdjustmentCode());
45  }
46 
51  public function testIsIncludedInBasePrice($expectedResult)
52  {
53  $this->taxHelper->expects($this->once())
54  ->method('priceIncludesTax')
55  ->will($this->returnValue($expectedResult));
56  $this->assertEquals($expectedResult, $this->adjustment->isIncludedInBasePrice());
57  }
58 
63  {
64  return [[true], [false]];
65  }
66 
70  public function testIsIncludedInDisplayPrice($displayPriceIncludingTax, $displayBothPrices, $expectedResult)
71  {
72  $this->taxHelper->expects($this->once())
73  ->method('displayPriceIncludingTax')
74  ->will($this->returnValue($displayPriceIncludingTax));
75  if (!$displayPriceIncludingTax) {
76  $this->taxHelper->expects($this->once())
77  ->method('displayBothPrices')
78  ->will($this->returnValue($displayBothPrices));
79  }
80 
81  $this->assertEquals($expectedResult, $this->adjustment->isIncludedInDisplayPrice());
82  }
83 
88  {
89  return [
90  [false, false, false],
91  [false, true, true],
92  [true, false, true],
93  [true, true, true],
94  ];
95  }
96 
104  public function testExtractAdjustment($isPriceIncludesTax, $amount, $price, $expectedResult)
105  {
106  $object = $this->getMockForAbstractClass(\Magento\Framework\Pricing\SaleableInterface::class);
107 
108  $this->taxHelper->expects($this->any())
109  ->method('priceIncludesTax')
110  ->will($this->returnValue($isPriceIncludesTax));
111  $this->catalogHelper->expects($this->any())
112  ->method('getTaxPrice')
113  ->with($object, $amount)
114  ->will($this->returnValue($price));
115 
116  $this->assertEquals($expectedResult, $this->adjustment->extractAdjustment($amount, $object));
117  }
118 
123  {
124  return [
125  [false, 'not_important', 'not_important', 0.00],
126  [true, 10.1, 0.2, 9.9],
127  [true, 10.1, 20.3, -10.2],
128  [true, 0.0, 0.0, 0],
129  ];
130  }
131 
139  public function testApplyAdjustment($amount, $price, $expectedResult)
140  {
141  $object = $this->getMockBuilder(\Magento\Framework\Pricing\SaleableInterface::class)->getMock();
142 
143  $this->catalogHelper->expects($this->any())
144  ->method('getTaxPrice')
145  ->with($object, $amount, true)
146  ->will($this->returnValue($price));
147 
148  $this->assertEquals($expectedResult, $this->adjustment->applyAdjustment($amount, $object));
149  }
150 
154  public function applyAdjustmentDataProvider()
155  {
156  return [
157  [1.1, 2.2, 2.2],
158  [0.0, 2.2, 2.2],
159  [1.1, 0.0, 0.0],
160  ];
161  }
162 
168  public function testIsExcludedWith($adjustmentCode, $expectedResult)
169  {
170  $this->assertEquals($expectedResult, $this->adjustment->isExcludedWith($adjustmentCode));
171  }
172 
176  public function isExcludedWithDataProvider()
177  {
178  return [
180  ['not_tax', false]
181  ];
182  }
183 
184  public function testGetSortOrder()
185  {
186  $this->assertEquals($this->sortOrder, $this->adjustment->getSortOrder());
187  }
188 }
$price
testExtractAdjustment($isPriceIncludesTax, $amount, $price, $expectedResult)
$amount
Definition: order.php:14
testApplyAdjustment($amount, $price, $expectedResult)
testIsIncludedInDisplayPrice($displayPriceIncludingTax, $displayBothPrices, $expectedResult)
$displayBothPrices
Definition: overview.phtml:101
testIsExcludedWith($adjustmentCode, $expectedResult)