/** * test method getValue * * @dataProvider getValueDataProvider */ public function testGetValue($specialPriceValue, $expectedResult) { $this->priceInfoMock->expects($this->once())->method('getPrices')->will($this->returnValue($this->prices)); $this->regularPriceMock->expects($this->exactly(3))->method('getValue')->will($this->returnValue(100)); $this->tearPriceMock->expects($this->exactly(2))->method('getValue')->will($this->returnValue(99)); $this->specialPriceMock->expects($this->any())->method('getValue')->will($this->returnValue($specialPriceValue)); $this->assertSame($expectedResult, $this->basePrice->getValue()); }
/** * @return void */ protected function prepareMock() { $this->saleableInterfaceMock = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false); $this->bundleCalculatorMock = $this->getMock('Magento\\Bundle\\Pricing\\Adjustment\\BundleCalculatorInterface'); $this->basePriceMock = $this->getMock('Magento\\Catalog\\Pricing\\Price\\BasePrice', [], [], '', false); $this->basePriceMock->expects($this->any())->method('getValue')->will($this->returnValue($this->baseAmount)); $this->bundleOptionMock = $this->getMockBuilder('Magento\\Bundle\\Pricing\\Price\\BundleOptionPrice')->disableOriginalConstructor()->getMock(); $this->priceInfoMock = $this->getMock('Magento\\Framework\\Pricing\\PriceInfo\\Base', [], [], '', false); $this->priceInfoMock->expects($this->atLeastOnce())->method('getPrice')->will($this->returnValueMap([[\Magento\Catalog\Pricing\Price\BasePrice::PRICE_CODE, $this->basePriceMock], [BundleOptionPrice::PRICE_CODE, $this->bundleOptionMock]])); $this->saleableInterfaceMock->expects($this->once())->method('getPriceInfo')->will($this->returnValue($this->priceInfoMock)); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->finalPrice = new \Magento\Bundle\Pricing\Price\FinalPrice($this->saleableInterfaceMock, $this->quantity, $this->bundleCalculatorMock); }
public function testGetAmount() { $amount = 20.0; $priceMock = $this->getMockBuilder('Magento\\Framework\\Pricing\\Price\\PriceInterface')->getMockForAbstractClass(); $this->priceInfoMock->expects($this->once())->method('getPrices')->willReturn([$priceMock]); $this->calculatorMock->expects($this->once())->method('getAmount')->with(false, $this->saleableItemMock)->willReturn($amount); $this->assertEquals($amount, $this->basePrice->getAmount()); }
/** * Test getMaximalPrice() */ public function testGetMaximalPrice() { $basePrice = 10; $minimalPrice = 5; $this->basePriceMock->expects($this->once())->method('getValue')->will($this->returnValue($basePrice)); $this->calculatorMock->expects($this->once())->method('getAmount')->with($this->equalTo($basePrice))->will($this->returnValue($minimalPrice)); $result = $this->model->getMaximalPrice(); $this->assertEquals($minimalPrice, $result); }
/** * @return void */ protected function prepareMock() { $this->saleableInterfaceMock = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['getPriceType', 'getPriceInfo'])->getMock(); $this->bundleCalculatorMock = $this->getMock('Magento\\Bundle\\Pricing\\Adjustment\\BundleCalculatorInterface'); $this->basePriceMock = $this->getMock('Magento\\Catalog\\Pricing\\Price\\BasePrice', [], [], '', false); $this->basePriceMock->expects($this->any())->method('getValue')->will($this->returnValue($this->baseAmount)); $this->bundleOptionMock = $this->getMockBuilder('Magento\\Bundle\\Pricing\\Price\\BundleOptionPrice')->disableOriginalConstructor()->getMock(); $this->customOptionPriceMock = $this->getMockBuilder('\\Magento\\Catalog\\Pricing\\Price\\CustomOptionPrice')->disableOriginalConstructor()->getMock(); $this->priceInfoMock = $this->getMock('Magento\\Framework\\Pricing\\PriceInfo\\Base', [], [], '', false); $this->priceInfoMock->expects($this->atLeastOnce())->method('getPrice')->will($this->returnValueMap([[\Magento\Catalog\Pricing\Price\BasePrice::PRICE_CODE, $this->basePriceMock], [BundleOptionPrice::PRICE_CODE, $this->bundleOptionMock], [CustomOptionPrice::PRICE_CODE, $this->customOptionPriceMock]])); $this->saleableInterfaceMock->expects($this->once())->method('getPriceInfo')->will($this->returnValue($this->priceInfoMock)); $this->priceCurrencyMock = $this->getMock('\\Magento\\Framework\\Pricing\\PriceCurrencyInterface'); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->finalPrice = new \Magento\Bundle\Pricing\Price\FinalPrice($this->saleableInterfaceMock, $this->quantity, $this->bundleCalculatorMock, $this->priceCurrencyMock); $this->productOptionRepositoryMock = $this->getMockForAbstractClass(ProductCustomOptionRepositoryInterface::class); $reflection = new \ReflectionClass(get_class($this->finalPrice)); $reflectionProperty = $reflection->getProperty('productOptionRepository'); $reflectionProperty->setAccessible(true); $reflectionProperty->setValue($this->finalPrice, $this->productOptionRepositoryMock); }
/** * {@inheritdoc} */ public function getValue() { $selectedConfigurableOption = $this->product->getSelectedConfigurableOption(); $productId = $selectedConfigurableOption ? $selectedConfigurableOption->getId() : $this->product->getId(); if (!isset($this->values[$productId])) { $this->value = null; if (!$selectedConfigurableOption) { $this->values[$productId] = parent::getValue(); } else { if (false !== $this->getMinimumAdditionalPrice()) { $this->values[$productId] = $this->getMinimumAdditionalPrice(); } else { $this->values[$productId] = parent::getValue(); } } } return $this->values[$productId]; }
/** * Get Value * * @return float|bool */ public function getValue() { return max(0, $this->basePrice->getValue()); }