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\Weee\Pricing\Adjustment;
10 
12 use Magento\Weee\Helper\Data as WeeeHelper;
13 
14 class AdjustmentTest extends \PHPUnit\Framework\TestCase
15 {
19  protected $adjustment;
20 
24  protected $weeeHelper;
25 
29  protected $priceCurrencyMock;
30 
34  protected $sortOrder = 5;
35 
36  protected function setUp()
37  {
38  $this->weeeHelper = $this->createMock(\Magento\Weee\Helper\Data::class);
39  $this->priceCurrencyMock = $this->createMock(\Magento\Framework\Pricing\PriceCurrencyInterface::class);
40  $this->priceCurrencyMock->expects($this->any())
41  ->method('convertAndRound')
42  ->will(
43  $this->returnCallback(
44  function ($arg) {
45  return round($arg * 0.5, 2);
46  }
47  )
48  );
49  $this->priceCurrencyMock->expects($this->any())
50  ->method('convert')
51  ->will(
52  $this->returnCallback(
53  function ($arg) {
54  return $arg * 0.5;
55  }
56  )
57  );
58 
59  $this->adjustment = new Adjustment($this->weeeHelper, $this->priceCurrencyMock, $this->sortOrder);
60  }
61 
62  public function testGetAdjustmentCode()
63  {
64  $this->assertEquals(Adjustment::ADJUSTMENT_CODE, $this->adjustment->getAdjustmentCode());
65  }
66 
67  public function testIsIncludedInBasePrice()
68  {
69  $this->assertFalse($this->adjustment->isIncludedInBasePrice());
70  }
71 
75  public function testIsIncludedInDisplayPrice($expectedResult)
76  {
77  $displayTypes = [
81  ];
82  $this->weeeHelper->expects($this->any())
83  ->method('typeOfDisplay')
84  ->with($displayTypes)
85  ->will($this->returnValue($expectedResult));
86 
87  $this->assertEquals($expectedResult, $this->adjustment->isIncludedInDisplayPrice());
88  }
89 
94  {
95  return [[false], [true]];
96  }
97 
104  public function testApplyAdjustment($amount, $amountOld, $expectedResult)
105  {
106  $object = $this->getMockForAbstractClass(\Magento\Framework\Pricing\SaleableInterface::class);
107 
108  $this->weeeHelper->expects($this->any())
109  ->method('getAmountExclTax')
110  ->will($this->returnValue($amountOld));
111 
112  $this->assertEquals($expectedResult, $this->adjustment->applyAdjustment($amount, $object));
113  }
114 
118  public function applyAdjustmentDataProvider()
119  {
120  return [
121  [1.1, 2.4, 2.3],
122  [0.0, 2.2, 1.1],
123  [1.1, 0.0, 1.1],
124  ];
125  }
126 
132  public function testIsExcludedWith($adjustmentCode, $expectedResult)
133  {
134  $this->assertEquals($expectedResult, $this->adjustment->isExcludedWith($adjustmentCode));
135  }
136 
140  public function isExcludedWithDataProvider()
141  {
142  return [
143  ['weee', true],
144  ['tax', true],
145  ['not_tax_and_not_weee', false]
146  ];
147  }
148 
154  public function testGetSortOrder($isTaxable, $expectedResult)
155  {
156  $this->weeeHelper->expects($this->any())
157  ->method('isTaxable')
158  ->will($this->returnValue($isTaxable));
159 
160  $this->assertEquals($expectedResult, $this->adjustment->getSortOrder());
161  }
162 
166  public function getSortOrderProvider()
167  {
168  return [
169  [true, $this->sortOrder],
170  [false, $this->sortOrder]
171  ];
172  }
173 }
const DISPLAY_INCL_DESCR
Definition: Tax.php:30
$amount
Definition: order.php:14
testApplyAdjustment($amount, $amountOld, $expectedResult)
const DISPLAY_INCL
Definition: Tax.php:25
const DISPLAY_EXCL_DESCR_INCL
Definition: Tax.php:35
testGetSortOrder($isTaxable, $expectedResult)
testIsExcludedWith($adjustmentCode, $expectedResult)