123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Weee\Test\Unit\Pricing;
- use Magento\Weee\Pricing\TaxAdjustment;
- class TaxAdjustmentTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var TaxAdjustment
- */
- protected $adjustment;
- /**
- * @var \Magento\Weee\Helper\Data | \PHPUnit_Framework_MockObject_MockObject
- */
- protected $weeeHelperMock;
- /**
- * @var \Magento\Tax\Helper\Data | \PHPUnit_Framework_MockObject_MockObject
- */
- protected $taxHelperMock;
- /**
- * @var \Magento\Framework\Pricing\PriceCurrencyInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $priceCurrencyMock;
- /**
- * @var int
- */
- protected $sortOrder = 5;
- protected function setUp()
- {
- $this->weeeHelperMock = $this->createMock(\Magento\Weee\Helper\Data::class);
- $this->taxHelperMock = $this->createMock(\Magento\Tax\Helper\Data::class);
- $this->priceCurrencyMock = $this->createMock(\Magento\Framework\Pricing\PriceCurrencyInterface::class);
- $this->priceCurrencyMock->expects($this->any())
- ->method('convertAndRound')
- ->will(
- $this->returnCallback(
- function ($arg) {
- return round($arg * 0.5, 2);
- }
- )
- );
- $this->priceCurrencyMock->expects($this->any())
- ->method('convert')
- ->will(
- $this->returnCallback(
- function ($arg) {
- return $arg * 0.5;
- }
- )
- );
- $this->adjustment = new TaxAdjustment(
- $this->weeeHelperMock,
- $this->taxHelperMock,
- $this->priceCurrencyMock,
- $this->sortOrder
- );
- }
- public function testGetAdjustmentCode()
- {
- $this->assertEquals(TaxAdjustment::ADJUSTMENT_CODE, $this->adjustment->getAdjustmentCode());
- }
- public function testIsIncludedInBasePrice()
- {
- $this->assertFalse($this->adjustment->isIncludedInBasePrice());
- }
- /**
- * @param bool $taxDisplayExclTax
- * @param bool $isWeeeTaxable
- * @param bool $weeeDisplayConfig
- * @param bool $expectedResult
- * @dataProvider isIncludedInDisplayPriceDataProvider
- */
- public function testIsIncludedInDisplayPrice(
- $taxDisplayExclTax,
- $isWeeeTaxable,
- $weeeDisplayConfig,
- $expectedResult
- ) {
- $this->weeeHelperMock->expects($this->any())
- ->method('isEnabled')
- ->willReturn(true);
- $this->weeeHelperMock->expects($this->any())
- ->method('isTaxable')
- ->willReturn($isWeeeTaxable);
- $this->taxHelperMock->expects($this->any())
- ->method('displayPriceExcludingTax')
- ->willReturn($taxDisplayExclTax);
- $displayTypes = [
- \Magento\Weee\Model\Tax::DISPLAY_EXCL,
- ];
- $this->weeeHelperMock->expects($this->any())
- ->method('typeOfDisplay')
- ->with($displayTypes)
- ->will($this->returnValue($weeeDisplayConfig));
- $this->assertEquals($expectedResult, $this->adjustment->isIncludedInDisplayPrice());
- }
- /**
- * @return array
- */
- public function isIncludedInDisplayPriceDataProvider()
- {
- return [
- 'display_incl_tax' => [
- 'tax_display_excl_tax' => false,
- 'is_weee_taxable' => true,
- 'weee_display_config' => false,
- 'expected_result' => true,
- ],
- 'display_incl_tax_excl_weee' => [
- 'tax_display_excl_tax' => false,
- 'is_weee_taxable' => true,
- 'weee_display_config' => true,
- 'expected_result' => false,
- ],
- 'display_excl_tax' => [
- 'tax_display_excl_tax' => true,
- 'is_weee_taxable' => true,
- 'weee_display_config' => true,
- 'expected_result' => false,
- ],
- 'display_excl_tax_incl_weee' => [
- 'tax_display_excl_tax' => true,
- 'is_weee_taxable' => true,
- 'weee_display_config' => false,
- 'expected_result' => false,
- ],
- ];
- }
- /**
- * @param float $amount
- * @param \Magento\Framework\DataObject[] $weeeAttributes
- * @param float $expectedResult
- * @dataProvider applyAdjustmentDataProvider
- */
- public function testApplyAdjustment($amount, $weeeAttributes, $expectedResult)
- {
- $object = $this->getMockForAbstractClass(\Magento\Framework\Pricing\SaleableInterface::class);
- $this->weeeHelperMock->expects($this->any())
- ->method('getProductWeeeAttributes')
- ->will($this->returnValue($weeeAttributes));
- $this->assertEquals($expectedResult, $this->adjustment->applyAdjustment($amount, $object));
- }
- /**
- * @return array
- */
- public function applyAdjustmentDataProvider()
- {
- return [
- [
- 'amount' => 10,
- 'weee_attributes' => [
- new \Magento\Framework\DataObject(
- [
- 'tax_amount' => 5,
- ]
- ),
- new \Magento\Framework\DataObject(
- [
- 'tax_amount' => 2.5,
- ]
- ),
- ],
- 'expected_result' => 13.75,
- ],
- ];
- }
- }
|