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