/** * test for method getValue with type Fixed and selectionPriceType is empty or zero */ public function testGetValueTypeFixedWithoutSelectionPriceType() { $this->bundleMock->expects($this->once())->method('getPriceType')->will($this->returnValue(\Magento\Bundle\Model\Product\Price::PRICE_TYPE_FIXED)); $this->productMock->expects($this->once())->method('getSelectionPriceType')->will($this->returnValue(false)); $this->productMock->expects($this->any())->method('getSelectionPriceValue')->will($this->returnValue(100)); $this->discountCalculatorMock->expects($this->once())->method('calculateDiscount')->with($this->equalTo($this->bundleMock), $this->equalTo(100))->will($this->returnValue(70)); $this->assertEquals(70, $this->selectionPrice->getValue()); }
public function testGetAmount() { $this->setupSelectionPrice(); $price = 10.0; $amount = 20.0; $this->priceInfoMock->expects($this->once())->method('getPrice')->with(\Magento\Bundle\Pricing\Price\FinalPrice::PRICE_CODE)->willReturn($this->finalPriceMock); $this->finalPriceMock->expects($this->once())->method('getValue')->willReturn($price); $this->discountCalculatorMock->expects($this->once())->method('calculateDiscount')->with($this->bundleMock, $price)->willReturn($price); $this->priceCurrencyMock->expects($this->once())->method('round')->with($price)->willReturn($price); $this->bundleMock->expects($this->any())->method('getPriceType')->willReturn(\Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC); $this->calculatorMock->expects($this->once())->method('getAmount')->with($price, $this->productMock, null)->willReturn($amount); $this->assertEquals($amount, $this->selectionPrice->getAmount()); }
/** * test for method getValue with type Fixed and selectionPriceType is empty or zero * * @param bool $useRegularPrice * @dataProvider useRegularPriceDataProvider */ public function testGetValueTypeFixedWithoutSelectionPriceType($useRegularPrice) { $this->setupSelectionPrice($useRegularPrice); $regularPrice = 100.125; $discountedPrice = 70.453; $convertedValue = 100.247; $actualPrice = $useRegularPrice ? $convertedValue : $discountedPrice; $expectedPrice = $useRegularPrice ? round($convertedValue, 2) : round($discountedPrice, 2); $this->bundleMock->expects($this->once())->method('getPriceType')->will($this->returnValue(\Magento\Bundle\Model\Product\Price::PRICE_TYPE_FIXED)); $this->productMock->expects($this->once())->method('getSelectionPriceType')->will($this->returnValue(false)); $this->productMock->expects($this->any())->method('getSelectionPriceValue')->will($this->returnValue($regularPrice)); $this->priceCurrencyMock->expects($this->once())->method('convert')->with($regularPrice)->will($this->returnValue($convertedValue)); if (!$useRegularPrice) { $this->discountCalculatorMock->expects($this->once())->method('calculateDiscount')->with($this->equalTo($this->bundleMock), $this->equalTo($convertedValue))->will($this->returnValue($discountedPrice)); } $this->priceCurrencyMock->expects($this->once())->method('round')->with($actualPrice)->will($this->returnValue($expectedPrice)); $this->assertEquals($expectedPrice, $this->selectionPrice->getValue()); }