/** * @covers \Magento\SalesRule\Model\Rule\Action\Discount\CartFixed::calculate */ public function testCalculate() { $this->rule->setData(['id' => 1, 'discount_amount' => 10.0]); $this->address->expects($this->any())->method('getCartFixedRules')->will($this->returnValue([])); $store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false); $this->priceCurrency->expects($this->atLeastOnce())->method('convert')->will($this->returnArgument(0)); $this->priceCurrency->expects($this->atLeastOnce())->method('round')->will($this->returnArgument(0)); $this->quote->expects($this->any())->method('getStore')->will($this->returnValue($store)); /** validators data */ $this->validator->expects($this->once())->method('getItemPrice')->with($this->item)->will($this->returnValue(100)); $this->validator->expects($this->once())->method('getItemBasePrice')->with($this->item)->will($this->returnValue(100)); $this->validator->expects($this->once())->method('getItemOriginalPrice')->with($this->item)->will($this->returnValue(100)); $this->validator->expects($this->once())->method('getItemBaseOriginalPrice')->with($this->item)->will($this->returnValue(100)); $this->address->expects($this->once())->method('setCartFixedRules')->with([1 => 0.0]); $this->model->calculate($this->rule, $this->item, 1); $this->assertEquals($this->data->getAmount(), 10); $this->assertEquals($this->data->getBaseAmount(), 10); $this->assertEquals($this->data->getOriginalAmount(), 10); $this->assertEquals($this->data->getBaseOriginalAmount(), 100); }
/** * Initialize required data */ protected function setUp() { $orderCreateMock = $this->getMock('Magento\\Sales\\Model\\AdminOrder\\Create', ['__wakeup'], [], '', false); $taxData = $this->getMockBuilder('Magento\\Tax\\Helper\\Data')->disableOriginalConstructor()->getMock(); $this->priceCurrency = $this->getMockBuilder('\\Magento\\Framework\\Pricing\\PriceCurrencyInterface')->getMock(); $coreData = $this->getMockBuilder('Magento\\Core\\Helper\\Data')->disableOriginalConstructor()->getMock(); $sessionMock = $this->getMockBuilder('Magento\\Backend\\Model\\Session\\Quote')->disableOriginalConstructor()->setMethods(['getQuote', '__wakeup'])->getMock(); $quoteMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->setMethods(['getStore', '__wakeup'])->getMock(); $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->setMethods(['__wakeup'])->getMock(); $this->priceCurrency->expects($this->any())->method('convertAndFormat')->will($this->returnArgument(0)); $quoteMock->expects($this->any())->method('getStore')->will($this->returnValue($storeMock)); $sessionMock->expects($this->any())->method('getQuote')->will($this->returnValue($quoteMock)); $wishlistFactoryMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\WishlistFactory')->disableOriginalConstructor()->setMethods(['methods', '__wakeup'])->getMock(); $giftMessageSave = $this->getMockBuilder('Magento\\Giftmessage\\Model\\Save')->setMethods(['__wakeup'])->disableOriginalConstructor()->getMock(); $taxConfig = $this->getMockBuilder('Magento\\Tax\\Model\\Config')->disableOriginalConstructor()->getMock(); $this->stockRegistry = $this->getMockBuilder('Magento\\CatalogInventory\\Model\\StockRegistry')->disableOriginalConstructor()->setMethods(['getStockItem', '__wakeup'])->getMock(); $this->stockItemMock = $this->getMock('Magento\\CatalogInventory\\Model\\Stock\\Item', ['getIsInStock', '__wakeup'], [], '', false); $this->stockState = $this->getMock('Magento\\CatalogInventory\\Model\\StockState', ['checkQuoteItemQty', '__wakeup'], [], '', false); $this->stockRegistry->expects($this->any())->method('getStockItem')->will($this->returnValue($this->stockItemMock)); $this->objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); $this->block = $this->objectManager->getObject('Magento\\Sales\\Block\\Adminhtml\\Order\\Create\\Items\\Grid', ['wishlistFactory' => $wishlistFactoryMock, 'giftMessageSave' => $giftMessageSave, 'taxConfig' => $taxConfig, 'taxData' => $taxData, 'sessionQuote' => $sessionMock, 'orderCreate' => $orderCreateMock, 'priceCurrency' => $this->priceCurrency, 'coreData' => $coreData, 'stockRegistry' => $this->stockRegistry, 'stockState' => $this->stockState]); $this->priceRenderBlock = $this->getMockBuilder('\\Magento\\Backend\\Block\\Template')->disableOriginalConstructor()->setMethods(['setItem', 'toHtml'])->getMock(); $this->layoutMock = $this->getMockBuilder('\\Magento\\Framework\\View\\Layout')->disableOriginalConstructor()->setMethods(['getBlock'])->getMock(); $this->itemMock = $this->getMockBuilder('\\Magento\\Quote\\Model\\Quote\\Item')->disableOriginalConstructor()->setMethods(['__wakeup'])->getMock(); }
public function testFormatPrice() { $amount = '120'; $includeContainer = false; $result = '10grn.'; $this->priceCurrencyMock->expects($this->once())->method('format')->with($amount, $includeContainer)->will($this->returnValue($result)); $helper = $this->getHelper(['priceCurrency' => $this->priceCurrencyMock]); $this->assertEquals($result, $helper->formatPrice($amount, $includeContainer)); }
public function testFormatCurrency() { $amount = '100'; $includeContainer = true; $precision = \Magento\Framework\Pricing\PriceCurrencyInterface::DEFAULT_PRECISION; $result = '100.0 grn'; $this->priceCurrency->expects($this->once())->method('format')->with($amount, $includeContainer, $precision)->will($this->returnValue($result)); $this->assertEquals($result, $this->model->formatCurrency($amount, $includeContainer, $precision)); }
public function setUp() { $this->weeeHelper = $this->getMock('Magento\\Weee\\Helper\\Data', [], [], '', false); $this->priceCurrencyMock = $this->getMock('\\Magento\\Framework\\Pricing\\PriceCurrencyInterface'); $this->priceCurrencyMock->expects($this->any())->method('convertAndRound')->will($this->returnCallback(function ($arg) { return round($arg * 0.5, 2); })); $this->adjustment = new Adjustment($this->weeeHelper, $this->priceCurrencyMock, $this->sortOrder); }
public function testGetShippingPrice() { $shippingPrice = 5; $convertedPrice = "\$5"; $shippingRateMock = $this->getMockBuilder('\\Magento\\Quote\\Model\\Quote\\Address\\Rate')->disableOriginalConstructor()->setMethods(['getPrice', '__wakeup'])->getMock(); $shippingRateMock->expects($this->once())->method('getPrice')->will($this->returnValue($shippingPrice)); $this->priceCurrency->expects($this->once())->method('convertAndFormat')->with($shippingPrice, true, true)->willReturn($convertedPrice); $this->priceObj->setShippingRate($shippingRateMock); $this->assertEquals($convertedPrice, $this->priceObj->getShippingPrice()); }
public function testGetCustomAmount() { $exclude = false; $amount = 21.0; $convertedValue = 30.25; $customAmount = 42.0; $this->priceCurrencyMock->expects($this->any())->method('convertAndRound')->with($amount)->will($this->returnValue($convertedValue)); $this->calculatorMock->expects($this->once())->method('getAmount')->with($convertedValue, $this->saleableItemMock, $exclude)->will($this->returnValue($customAmount)); $this->assertEquals($customAmount, $this->price->getCustomAmount($amount, $exclude)); }
/** * @covers Magento\GroupedProduct\Block\Product\Grouped\AssociatedProducts\ListAssociatedProducts * ::getAssociatedProducts */ public function testGetAssociatedProducts() { $this->priceCurrency->expects($this->any())->method('format')->with('1.00', false)->will($this->returnValue('1')); $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($this->storeMock)); $this->productMock->expects($this->once())->method('getTypeInstance')->will($this->returnValue($this->typeInstanceMock)); $this->registryMock->expects($this->once())->method('registry')->with('current_product')->will($this->returnValue($this->productMock)); $this->typeInstanceMock->expects($this->once())->method('getAssociatedProducts')->with($this->productMock)->will($this->returnValue([$this->generateAssociatedProduct(1), $this->generateAssociatedProduct(2)])); $expectedResult = ['0' => ['id' => 'id1', 'sku' => 'sku1', 'name' => 'name1', 'qty' => 1, 'position' => 1, 'price' => '1'], '1' => ['id' => 'id2', 'sku' => 'sku2', 'name' => 'name2', 'qty' => 2, 'position' => 2, 'price' => '1']]; $this->assertEquals($expectedResult, $this->block->getAssociatedProducts()); }
/** * Test method testGetDisplayValue */ public function testGetAmount() { $priceValue = 77; $convertedPrice = 56.32; $amountValue = 88; $this->saleableItemMock->expects($this->once())->method('getPrice')->will($this->returnValue($priceValue)); $this->priceCurrencyMock->expects($this->any())->method('convertAndRound')->with($priceValue)->will($this->returnValue($convertedPrice)); $this->calculatorMock->expects($this->once())->method('getAmount')->with($this->equalTo($convertedPrice))->will($this->returnValue($amountValue)); $this->assertEquals($amountValue, $this->regularPrice->getAmount()); }
/** * @param string $amount * @param string $store * @param bool $format * @param bool $includeContainer * @param string $result * @dataProvider currencyByStoreDataProvider */ public function testCurrencyByStore($amount, $store, $format, $includeContainer, $result) { if ($format) { $this->priceCurrencyMock->expects($this->once())->method('convertAndFormat')->with($amount, $includeContainer, PriceCurrencyInterface::DEFAULT_PRECISION, $store)->will($this->returnValue($result)); } else { $this->priceCurrencyMock->expects($this->once())->method('convert')->with($amount, $store)->will($this->returnValue($result)); } $helper = $this->getHelper(['priceCurrency' => $this->priceCurrencyMock]); $this->assertEquals($result, $helper->currencyByStore($amount, $store, $format, $includeContainer)); }
public function testGetShippingPriceInclTax() { $shippingPrice = 5; $shippingPriceInclTax = 5.5; $convertedPrice = "\$5.50"; $shippingRateMock = $this->setupShippingRate($shippingPrice); $this->taxHelper->expects($this->once())->method('getShippingPrice')->will($this->returnValue($shippingPriceInclTax)); $this->priceCurrency->expects($this->once())->method('convertAndFormat')->with($this->logicalOr($shippingPriceInclTax, true, $this->store))->will($this->returnValue($convertedPrice)); $this->priceObj->setShippingRate($shippingRateMock); $this->assertEquals($convertedPrice, $this->priceObj->getShippingPriceExclTax()); }
public function testGetLinkAmount() { $amount = 100; $convertedAmount = 50; $this->linkMock->expects($this->once())->method('getPrice')->will($this->returnValue($amount)); $this->linkMock->expects($this->once())->method('getProduct')->will($this->returnValue($this->saleableItemMock)); $this->priceCurrencyMock->expects($this->once())->method('convertAndRound')->with($amount)->will($this->returnValue($convertedAmount)); $this->calculatorMock->expects($this->once())->method('getAmount')->with($convertedAmount, $this->equalTo($this->saleableItemMock))->will($this->returnValue($convertedAmount)); $result = $this->linkPrice->getLinkAmount($this->linkMock); $this->assertEquals($convertedAmount, $result); }
/** * @param bool $isValidInterval * @param float $specialPrice * @param float|bool $specialPriceValue * * @dataProvider specialPriceDataProvider */ public function testGetValue($isValidInterval, $specialPrice, $specialPriceValue) { $expected = 56.34; $specialPriceModel = $this->objectManager->getObject('Magento\\Catalog\\Pricing\\Price\\SpecialPrice', ['saleableItem' => $this->prepareSaleableItem($specialPrice), 'localeDate' => $this->prepareLocaleDate($isValidInterval), 'priceCurrency' => $this->priceCurrencyMock]); if ($isValidInterval) { $this->priceCurrencyMock->expects($this->once())->method('convertAndRound')->with($specialPriceValue)->will($this->returnValue($expected)); } else { $expected = $specialPriceValue; } $this->assertSame($expected, $specialPriceModel->getValue()); }
public function testPrepareDataSource() { $itemName = 'itemName'; $oldItemValue = 'oldItemValue'; $newItemValue = 'newItemValue'; $dataSource = ['data' => ['items' => [[$itemName => $oldItemValue]]]]; $this->priceFormatterMock->expects($this->once())->method('format')->with($oldItemValue, false)->willReturn($newItemValue); $this->model->setData('name', $itemName); $dataSource = $this->model->prepareDataSource($dataSource); $this->assertEquals($newItemValue, $dataSource['data']['items'][0][$itemName]); }
public function testGetMinimalPrice() { $expectedResult = 5; $this->saleableInterfaceMock->expects($this->once())->method('getPrice')->will($this->returnValue($expectedResult)); $this->priceCurrencyMock->expects($this->once())->method('convertAndRound')->will($this->returnArgument(0)); $this->bundleCalculatorMock->expects($this->once())->method('getMinRegularAmount')->with($expectedResult, $this->saleableInterfaceMock)->will($this->returnValue($expectedResult)); $result = $this->regularPrice->getMinimalPrice(); $this->assertEquals($expectedResult, $result, 'Incorrect amount'); //Calling a second time, should use cached value $result = $this->regularPrice->getMinimalPrice(); $this->assertEquals($expectedResult, $result, 'Incorrect amount the second time'); }
public function setUp() { $objectManager = new ObjectManager($this); $this->coreRegistry = $this->getMockBuilder('\\Magento\\Framework\\Registry')->disableOriginalConstructor()->setMethods(['registry'])->getMock(); $this->orderTaxService = $this->getMockBuilder('\\Magento\\Tax\\Service\\V1\\OrderTaxService')->disableOriginalConstructor()->setMethods(['getOrderTaxDetails'])->getMock(); $this->priceCurrency = $this->getMockBuilder('Magento\\Framework\\Pricing\\PriceCurrencyInterface')->getMock(); $this->priceCurrency->expects($this->any())->method('round')->will($this->returnCallback(function ($argument) { return round($argument, 2); })); $this->taxHelper = $objectManager->getObject('Magento\\Tax\\Helper\\Data', ['coreRegistry' => $this->coreRegistry, 'orderTaxService' => $this->orderTaxService, 'priceCurrency' => $this->priceCurrency]); $this->orderTaxDetailsBuilder = $objectManager->getObject('Magento\\Tax\\Service\\V1\\Data\\OrderTaxDetailsBuilder'); }
/** * @covers \Magento\Bundle\Pricing\Price\TierPrice::isFirstPriceBetter * @dataProvider providerForGetterTierPriceList */ public function testGetterTierPriceList($tierPrices, $basePrice, $expectedResult) { $this->product->setData(TierPrice::PRICE_CODE, $tierPrices); $price = $this->getMock('Magento\\Framework\\Pricing\\Price\\PriceInterface'); $price->expects($this->any())->method('getValue')->will($this->returnValue($basePrice)); $this->priceInfo->expects($this->any())->method('getPrice')->will($this->returnValue($price)); $this->calculator->expects($this->atLeastOnce())->method('getAmount')->will($this->returnArgument(0)); $this->priceCurrencyMock->expects($this->never())->method('convertAndRound'); $group = $this->getMock('\\Magento\\Customer\\Model\\Data\\Group', [], [], '', false); $group->expects($this->any())->method('getId')->willReturn(\Magento\Customer\Model\GroupManagement::CUST_GROUP_ALL); $this->groupManagement->expects($this->any())->method('getAllCustomersGroup')->will($this->returnValue($group)); $this->assertEquals($expectedResult, $this->model->getTierPriceList()); $this->assertEquals(count($expectedResult), $this->model->getTierPriceCount()); }
/** * Test getMinimalPrice() */ public function testGetMinimalPriceWithMinimalPrice() { $minimalPrice = 5.234; $convertedPrice = 3.98; $finalPrice = 3.89; $this->priceCurrencyMock->expects($this->once())->method('convertAndRound')->with($minimalPrice)->will($this->returnValue($convertedPrice)); $this->basePriceMock->expects($this->never())->method('getValue'); $this->calculatorMock->expects($this->once())->method('getAmount')->with($this->equalTo($convertedPrice))->will($this->returnValue($finalPrice)); $this->saleableMock->expects($this->once())->method('getMinimalPrice')->will($this->returnValue($minimalPrice)); $result = $this->model->getMinimalPrice(); $this->assertEquals($finalPrice, $result); //The second time will return cached value $result = $this->model->getMinimalPrice(); $this->assertEquals($finalPrice, $result); }
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 testCollect() { $this->shippingAssignment->expects($this->exactly(3))->method('getShipping')->willReturn($this->shipping); $this->shipping->expects($this->exactly(2))->method('getAddress')->willReturn($this->address); $this->shipping->expects($this->once())->method('getMethod')->willReturn('flatrate'); $this->shippingAssignment->expects($this->atLeastOnce())->method('getItems')->willReturn([$this->cartItem]); $this->freeShipping->expects($this->once())->method('isFreeShipping')->with($this->quote, [$this->cartItem])->willReturn(true); $this->address->expects($this->once())->method('setFreeShipping')->with(true); $this->total->expects($this->atLeastOnce())->method('setTotalAmount'); $this->total->expects($this->atLeastOnce())->method('setBaseTotalAmount'); $this->cartItem->expects($this->atLeastOnce())->method('getProduct')->willReturnSelf(); $this->cartItem->expects($this->atLeastOnce())->method('isVirtual')->willReturn(false); $this->cartItem->expects($this->once())->method('getParentItem')->willReturn(false); $this->cartItem->expects($this->once())->method('getHasChildren')->willReturn(false); $this->cartItem->expects($this->once())->method('getWeight')->willReturn(2); $this->cartItem->expects($this->atLeastOnce())->method('getQty')->willReturn(2); $this->address->expects($this->once())->method('getFreeShipping')->willReturn(true); $this->cartItem->expects($this->once())->method('setRowWeight')->with(0); $this->address->expects($this->once())->method('setItemQty')->with(2); $this->address->expects($this->atLeastOnce())->method('setWeight'); $this->address->expects($this->atLeastOnce())->method('setFreeMethodWeight'); $this->address->expects($this->once())->method('collectShippingRates'); $this->address->expects($this->once())->method('getAllShippingRates')->willReturn([$this->rate]); $this->rate->expects($this->once())->method('getCode')->willReturn('flatrate'); $this->quote->expects($this->once())->method('getStore')->willReturn($this->store); $this->rate->expects($this->atLeastOnce())->method('getPrice')->willReturn(5); $this->priceCurrency->expects($this->once())->method('convert')->with(5, $this->store)->willReturn(5); $this->total->expects($this->once())->method('setShippingAmount')->with(5); $this->rate->expects($this->once())->method('getCarrierTitle')->willReturn('Carrier title'); $this->rate->expects($this->once())->method('getMethodTitle')->willReturn('Method title'); $this->address->expects($this->once())->method('setShippingDescription')->with('Carrier title - Method title'); $this->address->expects($this->once())->method('getShippingDescription')->willReturn('Carrier title - Method title'); $this->total->expects($this->once())->method('setShippingDescription')->with('Carrier title - Method title'); $this->shippingModel->collect($this->quote, $this->shippingAssignment, $this->total); }
public function testPrepareJsonAttributes() { $options = []; $attributeId = 1; $attributeCode = 'test_attribute'; $attributeLabel = 'Test'; $pricingValue = 100; $amount = 120; $modifiedValue = 140; $valueIndex = 2; $optionId = 1; $expected = ['priceOptions' => [$attributeId => ['id' => $attributeId, 'code' => $attributeCode, 'label' => $attributeLabel, 'options' => [0 => ['id' => $valueIndex, 'label' => $attributeLabel, 'price' => $modifiedValue, 'oldPrice' => $modifiedValue, 'inclTaxPrice' => $modifiedValue, 'exclTaxPrice' => $pricingValue, 'products' => []]]]], 'defaultValues' => [$attributeId => $optionId]]; $attributePrices = [['is_percent' => false, 'pricing_value' => $pricingValue, 'value_index' => $valueIndex, 'label' => $attributeLabel]]; $configurableAttributes = [$this->getAttributeMock($attributeId, $attributeCode, $attributeLabel, $attributePrices)]; $configuredValueMock = $this->getMockBuilder('Magento\\Framework\\Object')->disableOriginalConstructor()->getMock(); $configuredValueMock->expects($this->any())->method('getData')->will($this->returnValue($optionId)); $configurableProduct = $this->getMockBuilder('Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable')->disableOriginalConstructor()->getMock(); $configurableProduct->expects($this->once())->method('getConfigurableAttributes')->with($this->equalTo($this->saleableItemMock))->will($this->returnValue($configurableAttributes)); $this->saleableItemMock->expects($this->once())->method('getTypeInstance')->will($this->returnValue($configurableProduct)); $this->saleableItemMock->expects($this->any())->method('setParentId'); $this->saleableItemMock->expects($this->any())->method('hasPreconfiguredValues')->will($this->returnValue(true)); $this->saleableItemMock->expects($this->any())->method('getPreconfiguredValues')->will($this->returnValue($configuredValueMock)); $this->priceModifier->expects($this->once())->method('modifyPrice')->with($this->equalTo($pricingValue), $this->equalTo($this->saleableItemMock))->will($this->returnValue($amount)); $this->calculatorMock->expects($this->any())->method('getAmount')->will($this->returnValue($this->getModifiedAmountMock($modifiedValue, $pricingValue))); $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $this->priceCurrency->expects($this->once())->method('convert')->with($this->equalTo($modifiedValue))->will($this->returnArgument(0)); $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($storeMock)); $result = $this->attribute->prepareAttributes($options); $this->assertEquals($expected, $result); }
public function testIsMinimalPriceLessMsrp() { $msrp = 120; $convertedFinalPrice = 200; $this->priceCurrencyMock->expects($this->any())->method('convertAndRound')->will($this->returnCallback(function ($arg) { return round(2 * $arg, 2); })); $finalPriceMock = $this->getMockBuilder('\\Magento\\Catalog\\Pricing\\Price\\FinalPrice')->disableOriginalConstructor()->getMock(); $finalPriceMock->expects($this->any())->method('getValue')->will($this->returnValue($convertedFinalPrice)); $priceInfoMock = $this->getMockBuilder('\\Magento\\Framework\\Pricing\\PriceInfo\\Base')->disableOriginalConstructor()->getMock(); $priceInfoMock->expects($this->once())->method('getPrice')->with(\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE)->will($this->returnValue($finalPriceMock)); $this->productMock->expects($this->any())->method('getMsrp')->will($this->returnValue($msrp)); $this->productMock->expects($this->any())->method('getPriceInfo')->will($this->returnValue($priceInfoMock)); $result = $this->helper->isMinimalPriceLessMsrp($this->productMock); $this->assertTrue($result, "isMinimalPriceLessMsrp returned incorrect value"); }
/** * Test for method _toHtml * * @return void */ public function testToHtml() { $productMock = $this->getMock('Magento\\Catalog\\Model\\Product', ['getProductUrl', 'getDescription', 'getAllowedPriceInRss', 'getName', '__wakeup', 'getResourceCollection'], [], '', false); $productCollectionMock = $this->getMock('Magento\\Catalog\\Model\\Resource\\Product\\CollectionFactory', ['addPriceDataFieldFilter', 'addPriceData', 'addAttributeToSelect', 'addAttributeToSort', 'getSelect'], [], '', false); $rssObjMock = $this->getMock('Magento\\Rss\\Model\\Rss', [], [], '', false); $productUrl = '<a href="http://product.url">Product Url</a>'; $imgThumbSrc = 'http://source-for-thumbnail'; $productTitle = 'Product title'; $basePriceFormatted = '<span class="price">$10.00</span>'; $finalPriceFormatted = '<span class="price">$20.00</span>'; $productDescription = '<table><tr>' . '<td><a href="' . $productUrl . '"><img src="' . $imgThumbSrc . '" alt="" border="0" align="left" height="75" width="75" /></a></td>' . '<td style="text-decoration:none;"><p>Price: ' . $basePriceFormatted . ' Special Price: ' . $finalPriceFormatted . '</p></td></tr></table>'; $expectedData = ['title' => $productTitle, 'link' => $productUrl, 'description' => $productDescription]; $expectedResult = new \Magento\Framework\Object(['rss_feed' => '<xml>Feed of the rss</xml>']); $this->addMocks(); $this->productFactoryMock->expects($this->once())->method('create')->will($this->returnValue($productMock)); $productMock->expects($this->once())->method('getResourceCollection')->will($this->returnValue($productCollectionMock)); $productCollectionMock->expects($this->once())->method('addPriceDataFieldFilter')->will($this->returnSelf()); $productCollectionMock->expects($this->once())->method('addPriceData')->will($this->returnSelf()); $productCollectionMock->expects($this->once())->method('addAttributeToSelect')->will($this->returnSelf()); $productCollectionMock->expects($this->once())->method('addAttributeToSort')->will($this->returnSelf()); $this->rssFactoryMock->expects($this->once())->method('create')->will($this->returnValue($rssObjMock)); $productMock->expects($this->exactly(2))->method('getProductUrl')->will($this->returnValue($productUrl)); $this->imageHelperMock->expects($this->once())->method('resize')->will($this->returnValue($imgThumbSrc)); $productMock->expects($this->any())->method('getAllowedPriceInRss')->will($this->returnValue(true)); $productMock->expects($this->once())->method('getName')->will($this->returnValue($productTitle)); $this->priceCurrencyMock->expects($this->exactly(2))->method('convertAndFormat')->will($this->returnValueMap([[10, true, PriceCurrencyInterface::DEFAULT_PRECISION, null, null, $basePriceFormatted], [20, true, PriceCurrencyInterface::DEFAULT_PRECISION, null, null, $finalPriceFormatted]])); $rssObjMock->expects($this->once())->method('_addEntry')->with($expectedData)->will($this->returnSelf()); $rssObjMock->expects($this->once())->method('createRssXml')->will($this->returnValue($expectedResult)); $this->assertEquals($expectedResult, $this->block->toHtml()); }
/** * test method testGetOptionValueModified with option is_percent = false */ public function testGetOptionValueModifiedIsNotPercent() { $this->saleableItemMock->expects($this->once())->method('setParentId')->with($this->equalTo(true))->will($this->returnValue($this->returnSelf())); $this->priceModifier->expects($this->once())->method('modifyPrice')->with($this->equalTo(77.33), $this->equalTo($this->saleableItemMock))->will($this->returnValue(77.67)); $this->calculatorMock->expects($this->once())->method('getAmount')->with($this->equalTo(77.67), $this->equalTo($this->saleableItemMock), null, [\Magento\Catalog\Pricing\Price\CustomOptionPriceInterface::CONFIGURATION_OPTION_FLAG => true])->will($this->returnValue(80.98999999999999)); $this->priceCurrency->expects($this->once())->method('convertAndRound')->will($this->returnArgument(0)); $this->assertEquals(80.98999999999999, $this->attribute->getOptionValueModified(['is_percent' => false, 'pricing_value' => 77.33])); }
public function testFormatPriceQuoteItem() { $price = 3.554; $formattedPrice = "\$3.55"; $storeMock = $this->getMockBuilder('\\Magento\\Store\\Model\\Store')->disableOriginalConstructor()->setMethods(['formatPrice', '__wakeup'])->getMock(); $this->priceCurrency->expects($this->once())->method('format')->with($price, true)->will($this->returnValue($formattedPrice)); $itemMock = $this->getMockBuilder('\\Magento\\Sales\\Model\\Quote\\Item')->disableOriginalConstructor()->setMethods(['getStore', '__wakeup'])->getMock(); $itemMock->expects($this->once())->method('getStore')->will($this->returnValue($storeMock)); $this->renderer->setItem($itemMock); $this->assertEquals($formattedPrice, $this->renderer->formatPrice($price)); }
public function testGetBasePriceInclTax() { $storeManager = $this->getMock('\\Magento\\Store\\Model\\StoreManagerInterface', [], [], '', false); $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $helper = $objectManagerHelper->getObject('\\Magento\\Checkout\\Helper\\Data', ['storeManager' => $storeManager, 'priceCurrency' => $this->priceCurrency]); $itemMock = $this->getMock('Magento\\Framework\\Object', ['getQty', 'getQtyOrdered'], [], '', false); $itemMock->expects($this->once())->method('getQty')->will($this->returnValue(false)); $itemMock->expects($this->exactly(2))->method('getQtyOrdered')->will($this->returnValue(5.5)); $this->priceCurrency->expects($this->once())->method('round'); $helper->getBasePriceInclTax($itemMock); }
/** * @param $regularPrice * @param $specialPrice * @param $isScopeDateInInterval * @param $value * @param $percent * @dataProvider getValueDataProvider */ public function testGetValue($regularPrice, $specialPrice, $isScopeDateInInterval, $value, $percent) { $specialFromDate = 'some date from'; $specialToDate = 'some date to'; $this->saleable->expects($this->once())->method('getSpecialPrice')->will($this->returnValue($specialPrice)); $store = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $this->saleable->expects($this->once())->method('getStore')->will($this->returnValue($store)); $this->saleable->expects($this->once())->method('getSpecialFromDate')->will($this->returnValue($specialFromDate)); $this->saleable->expects($this->once())->method('getSpecialToDate')->will($this->returnValue($specialToDate)); $this->localeDate->expects($this->once())->method('isScopeDateInInterval')->with($store, $specialFromDate, $specialToDate)->will($this->returnValue($isScopeDateInInterval)); $this->priceCurrencyMock->expects($this->never())->method('convertAndRound'); if ($isScopeDateInInterval) { $price = $this->getMock('Magento\\Framework\\Pricing\\Price\\PriceInterface'); $this->priceInfo->expects($this->once())->method('getPrice')->with(\Magento\Catalog\Pricing\Price\RegularPrice::PRICE_CODE)->will($this->returnValue($price)); $price->expects($this->once())->method('getValue')->will($this->returnValue($regularPrice)); } $this->assertEquals($value, $this->model->getValue()); //check that the second call will get data from cache the same as in first call $this->assertEquals($value, $this->model->getValue()); $this->assertEquals($percent, $this->model->getDiscountPercent()); }
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()); }
/** * Setup address mock * * @param \PHPUnit_Framework_MockObject_MockObject|\Magento\Quote\Model\Quote\Item $itemMock * @return \PHPUnit_Framework_MockObject_MockObject */ protected function setupAddressMock($itemMock) { $addressMock = $this->getMock('Magento\\Quote\\Model\\Quote\\Address', ['__wakeup', 'getAllItems', 'getQuote'], [], '', false); $quoteMock = $this->getMock('Magento\\Quote\\Model\\Quote', [], [], '', false); $storeMock = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false); $this->priceCurrency = $this->getMockBuilder('Magento\\Framework\\Pricing\\PriceCurrencyInterface')->getMock(); $this->priceCurrency->expects($this->any())->method('round')->willReturnArgument(0); $this->priceCurrency->expects($this->any())->method('convert')->willReturnArgument(0); $quoteMock->expects($this->any())->method('getStore')->will($this->returnValue($storeMock)); $addressMock->expects($this->any())->method('getAllItems')->will($this->returnValue([$itemMock])); $addressMock->expects($this->any())->method('getQuote')->will($this->returnValue($quoteMock)); return $addressMock; }
/** * test get group price, customer group in session * * @param int $customerGroup * @dataProvider dataProviderGroupPriceCustomerGroupInProduct */ public function testGroupPriceCustomerGroupInProduct($customerGroup) { $groupPrice = 80; $convertedPrice = 56.23; $this->productMock->expects($this->exactly(2))->method('getCustomerGroupId')->will($this->returnValue($customerGroup)); $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->productMock->expects($this->once())->method('getData')->with($this->equalTo('group_price'), $this->equalTo(null))->will($this->returnValue([['cust_group' => $customerGroup, 'website_price' => $groupPrice]])); $this->priceCurrencyMock->expects($this->once())->method('convertAndRound')->with($groupPrice)->will($this->returnValue($convertedPrice)); $this->assertEquals($convertedPrice, $this->groupPrice->getValue()); }