protected function setUp() { $this->saleableItem = $this->getMock('Magento\\Catalog\\Model\\Product', ['getPriceInfo', '__wakeup'], [], '', false); $this->priceInfo = $this->getMock('Magento\\Framework\\Pricing\\PriceInfo\\Base', [], [], '', false); $this->price = $this->getMock('Magento\\Catalog\\Pricing\\Price\\BasePrice', [], [], '', false); $this->priceInfo->expects($this->any())->method('getAdjustments')->will($this->returnValue([])); $this->saleableItem->expects($this->any())->method('getPriceInfo')->will($this->returnValue($this->priceInfo)); $this->priceInfo->expects($this->any())->method('getPrice')->with($this->equalTo('base_price'))->will($this->returnValue($this->price)); $this->calculator = $this->getMockBuilder('Magento\\Framework\\Pricing\\Adjustment\\Calculator')->disableOriginalConstructor()->getMock(); $this->helper = $this->getMock('Magento\\Catalog\\Helper\\Data', ['isShowPriceOnGesture', 'getMsrpPriceMessage', 'isMsrpEnabled', 'canApplyMsrp'], [], '', false); $this->object = new MsrpPrice($this->saleableItem, PriceInfoInterface::PRODUCT_QUANTITY_DEFAULT, $this->calculator, $this->helper); }
/** * test for method afterPrepareAdjustmentConfig */ public function testAfterPrepareAdjustmentConfig() { $this->productMock->expects($this->once())->method('getTaxClassId')->will($this->returnValue('tax-class-id')); $this->calculationMock->expects($this->exactly(2))->method('getRateRequest')->will($this->returnValue($this->rateRequestMock)); $this->calculationMock->expects($this->exactly(2))->method('getRate')->with($this->equalTo($this->rateRequestMock))->will($this->returnValue(99.09999999999999)); $this->productMock->expects($this->once())->method('getPriceInfo')->will($this->returnValue($this->priceInfoMock)); $this->priceInfoMock->expects($this->once())->method('getAdjustment')->with($this->equalTo(\Magento\Tax\Pricing\Adjustment::ADJUSTMENT_CODE))->will($this->returnValue($this->adjustmentMock)); $this->adjustmentMock->expects($this->once())->method('isIncludedInBasePrice')->will($this->returnValue(true)); $this->taxHelperMock->expects($this->once())->method('displayPriceIncludingTax')->will($this->returnValue(true)); $this->taxHelperMock->expects($this->once())->method('displayBothPrices')->will($this->returnValue(true)); $expected = ['product' => $this->productMock, 'defaultTax' => 99.09999999999999, 'currentTax' => 99.09999999999999, 'customerId' => 1, 'includeTax' => true, 'showIncludeTax' => true, 'showBothPrices' => true]; $this->assertEquals($expected, $this->plugin->afterPrepareAdjustmentConfig($this->attributePriceMock, ['product' => $this->productMock, 'defaultTax' => 0, 'currentTax' => 0, 'customerId' => 1])); }
public function testGetValue() { $this->priceInfoMock->expects($this->once())->method('getPrice')->with($this->equalTo('regular_price'))->will($this->returnValue($this->regularPrice)); $this->regularPrice->expects($this->once())->method('getValue')->will($this->returnValue(100)); $this->productMock->expects($this->once())->method('getCustomerGroupId')->will($this->returnValue(null)); $this->customerSessionMock->expects($this->once())->method('getCustomerGroupId')->will($this->returnValue(3)); $this->productMock->expects($this->once())->method('getResource')->will($this->returnValue($this->productResourceMock)); $this->productResourceMock->expects($this->once())->method('getAttribute')->with($this->equalTo('group_price'))->will($this->returnValue($this->attributeMock)); $this->attributeMock->expects($this->once())->method('getBackend')->will($this->returnValue($this->backendMock)); $this->backendMock->expects($this->once())->method('afterLoad')->with($this->equalTo($this->productMock))->will($this->returnValue($this->backendMock)); $this->priceCurrencyMock->expects($this->never())->method('convertAndRound'); $this->productMock->expects($this->once())->method('getData')->with($this->equalTo('group_price'), $this->equalTo(null))->will($this->returnValue([['cust_group' => 3, 'website_price' => 80]])); $this->assertEquals(20, $this->groupPrice->getValue()); $this->assertEquals(20, $this->groupPrice->getValue()); }
public function testGetJsonConfig() { $regularPrice = 11.0; $finalPrice = 10.0; $price = 5.0; $oldPrice = 4.0; $linkPrice = 3.0; $linkIncludeTaxPrice = 4.0; $linkExcludeTaxPrice = 3.0; $linkId = 42; $config = ['price' => $price, 'oldPrice' => $oldPrice, 'links' => [$linkId => ['price' => $linkPrice, 'oldPrice' => $linkPrice, 'inclTaxPrice' => $linkIncludeTaxPrice, 'exclTaxPrice' => $linkExcludeTaxPrice]]]; $linkAmountMock = $this->getMock('Magento\\Framework\\Pricing\\Amount\\Base', [], [], '', false); $linkAmountMock->expects($this->once())->method('getValue')->will($this->returnValue($linkIncludeTaxPrice)); $linkAmountMock->expects($this->once())->method('getBaseAmount')->will($this->returnValue($linkExcludeTaxPrice)); $amountMock = $this->getMock('Magento\\Framework\\Pricing\\Amount\\Base', [], [], '', false); $amountMock->expects($this->once())->method('getValue')->will($this->returnValue($finalPrice)); $typeInstanceMock = $this->getMock('Magento\\Catalog\\Model\\Product\\Type\\Simple', ['getLinks'], [], '', false); $typeInstanceMock->expects($this->once())->method('getLinks')->will($this->returnValue([$this->getLinkMock($linkPrice, $linkId)])); $this->productMock->expects($this->once())->method('getTypeInstance')->will($this->returnValue($typeInstanceMock)); $regularPriceMock = $this->getMock('Magento\\Catalog\\Pricing\\Price\\RegularPrice', [], [], '', false); $regularPriceMock->expects($this->once())->method('getValue')->will($this->returnValue($regularPrice)); $finalPriceMock = $this->getMock('Magento\\Catalog\\Pricing\\Price\\FinalPrice', [], [], '', false); $finalPriceMock->expects($this->at(0))->method('getAmount')->will($this->returnValue($amountMock)); $finalPriceMock->expects($this->at(1))->method('getCustomAmount')->with($linkPrice)->will($this->returnValue($linkAmountMock)); $this->coreHelper->expects($this->at(0))->method('currency')->with($finalPrice, false, false)->will($this->returnValue($price)); $this->coreHelper->expects($this->at(1))->method('currency')->with($regularPrice, false, false)->will($this->returnValue($oldPrice)); $this->coreHelper->expects($this->at(2))->method('currency')->with($linkPrice, false, false)->will($this->returnValue($linkPrice)); $this->coreHelper->expects($this->at(3))->method('currency')->with($linkIncludeTaxPrice, false, false)->will($this->returnValue($linkIncludeTaxPrice)); $this->coreHelper->expects($this->at(4))->method('currency')->with($linkExcludeTaxPrice, false, false)->will($this->returnValue($linkExcludeTaxPrice)); $this->priceInfoMock->expects($this->at(0))->method('getPrice')->with(FinalPrice::PRICE_CODE)->will($this->returnValue($finalPriceMock)); $this->priceInfoMock->expects($this->at(1))->method('getPrice')->with(RegularPrice::PRICE_CODE)->will($this->returnValue($regularPriceMock)); $this->priceInfoMock->expects($this->at(2))->method('getPrice')->with(FinalPrice::PRICE_CODE)->will($this->returnValue($finalPriceMock)); $this->assertEquals(json_encode($config), $this->linksBlock->getJsonConfig()); }
public function testGetJsonConfig() { $linkPrice = 3.0; $linkId = 42; $config = ['links' => [$linkId => ['finalPrice' => $linkPrice]]]; $linkAmountMock = $this->getMock('Magento\\Framework\\Pricing\\Amount\\AmountInterface', [], [], '', false); $linkAmountMock->expects($this->once())->method('getValue')->will($this->returnValue($linkPrice)); $typeInstanceMock = $this->getMock('Magento\\Catalog\\Model\\Product\\Type\\Simple', ['getLinks'], [], '', false); $typeInstanceMock->expects($this->once())->method('getLinks')->will($this->returnValue([$this->getLinkMock($linkPrice, $linkId)])); $this->productMock->expects($this->once())->method('getTypeInstance')->will($this->returnValue($typeInstanceMock)); $finalPriceMock = $this->getMock('Magento\\Catalog\\Pricing\\Price\\FinalPrice', [], [], '', false); $finalPriceMock->expects($this->once())->method('getCustomAmount')->with($linkPrice)->will($this->returnValue($linkAmountMock)); $this->priceInfoMock->expects($this->once())->method('getPrice')->with(FinalPrice::PRICE_CODE)->will($this->returnValue($finalPriceMock)); $json = json_encode($config); $this->jsonEncoder->expects($this->once())->method('encode')->with($config)->will($this->returnValue($json)); $encodedJsonConfig = $this->linksBlock->getJsonConfig(); $this->assertEquals(json_encode($config), $encodedJsonConfig); }
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 not null */ public function testGetValueTypeFixedWithSelectionPriceType() { $this->bundleMock->expects($this->once())->method('getPriceType')->will($this->returnValue(\Magento\Bundle\Model\Product\Price::PRICE_TYPE_FIXED)); $this->bundleMock->expects($this->atLeastOnce())->method('getPriceInfo')->will($this->returnValue($this->priceInfoMock)); $this->priceInfoMock->expects($this->once())->method('getPrice')->with($this->equalTo(RegularPrice::PRICE_CODE))->will($this->returnValue($this->regularPriceMock)); $this->regularPriceMock->expects($this->once())->method('getValue')->will($this->returnValue(100)); $this->bundleMock->expects($this->once())->method('setFinalPrice')->will($this->returnSelf()); $this->eventManagerMock->expects($this->once())->method('dispatch'); $this->bundleMock->expects($this->exactly(2))->method('getData')->will($this->returnValueMap([['qty', null, 1], ['final_price', null, 100]])); $this->productMock->expects($this->once())->method('getSelectionPriceType')->will($this->returnValue(true)); $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()); }
/** * test for method getValue with type Fixed and selectionPriceType not null * * @param bool $useRegularPrice * @dataProvider useRegularPriceDataProvider */ public function testGetValueTypeFixedWithSelectionPriceType($useRegularPrice) { $this->setupSelectionPrice($useRegularPrice); $regularPrice = 100.125; $discountedPrice = 70.453; $actualPrice = $useRegularPrice ? $regularPrice : $discountedPrice; $expectedPrice = $useRegularPrice ? round($regularPrice, 2) : round($discountedPrice, 2); $this->bundleMock->expects($this->once())->method('getPriceType')->will($this->returnValue(\Magento\Bundle\Model\Product\Price::PRICE_TYPE_FIXED)); $this->bundleMock->expects($this->atLeastOnce())->method('getPriceInfo')->will($this->returnValue($this->priceInfoMock)); $this->priceInfoMock->expects($this->once())->method('getPrice')->with($this->equalTo(RegularPrice::PRICE_CODE))->will($this->returnValue($this->regularPriceMock)); $this->regularPriceMock->expects($this->once())->method('getValue')->will($this->returnValue($actualPrice)); $this->bundleMock->expects($this->once())->method('setFinalPrice')->will($this->returnSelf()); $this->eventManagerMock->expects($this->once())->method('dispatch'); $this->bundleMock->expects($this->exactly(2))->method('getData')->will($this->returnValueMap([['qty', null, 1], ['final_price', null, 100]])); $this->productMock->expects($this->once())->method('getSelectionPriceType')->will($this->returnValue(true)); $this->productMock->expects($this->any())->method('getSelectionPriceValue')->will($this->returnValue($actualPrice)); if (!$useRegularPrice) { $this->discountCalculatorMock->expects($this->once())->method('calculateDiscount')->with($this->equalTo($this->bundleMock), $this->equalTo($actualPrice))->will($this->returnValue($discountedPrice)); } $this->priceCurrencyMock->expects($this->once())->method('round')->with($actualPrice)->will($this->returnValue($expectedPrice)); $this->assertEquals($expectedPrice, $this->selectionPrice->getValue()); }