diff --git a/app/code/Magento/Bundle/Pricing/Adjustment/Calculator.php b/app/code/Magento/Bundle/Pricing/Adjustment/Calculator.php index 376a1c5f5e628..f59d63b4a5353 100644 --- a/app/code/Magento/Bundle/Pricing/Adjustment/Calculator.php +++ b/app/code/Magento/Bundle/Pricing/Adjustment/Calculator.php @@ -314,7 +314,7 @@ protected function calculateDynamicBundleAmount($basePriceValue, $bundleProduct, /** @var Store $store */ $store = $bundleProduct->getStore(); - $roundingMethod = $this->taxHelper->getCalculationAgorithm($store); + $roundingMethod = $this->taxHelper->getCalculationAlgorithm($store); foreach ($amountList as $amountInfo) { /** @var \Magento\Framework\Pricing\Amount\AmountInterface $itemAmount */ $itemAmount = $amountInfo['amount']; diff --git a/app/code/Magento/Catalog/Model/Product.php b/app/code/Magento/Catalog/Model/Product.php index 32a82364c17a0..40a973f14949d 100644 --- a/app/code/Magento/Catalog/Model/Product.php +++ b/app/code/Magento/Catalog/Model/Product.php @@ -777,8 +777,10 @@ public function afterSave() */ public function setQty($qty) { - $this->setData('qty', $qty); - $this->reloadPriceInfo(); + if ($this->getData('qty') != $qty) { + $this->setData('qty', $qty); + $this->reloadPriceInfo(); + } return $this; } diff --git a/app/code/Magento/Directory/Model/PriceCurrency.php b/app/code/Magento/Directory/Model/PriceCurrency.php index 6e6b5872f3795..8232d9220b412 100644 --- a/app/code/Magento/Directory/Model/PriceCurrency.php +++ b/app/code/Magento/Directory/Model/PriceCurrency.php @@ -58,18 +58,12 @@ public function convert($amount, $scope = null, $currency = null) } /** - * Convert and round price value for specified store or passed currency - * - * @param float $amount - * @param null|string|bool|int|\Magento\Store\Model\Store $store - * @param Currency|string|null $currency - * @param int $precision - * @return float + * {@inheritdoc} */ - public function convertAndRound($amount, $store = null, $currency = null, $precision = self::DEFAULT_PRECISION) + public function convertAndRound($amount, $scope = null, $currency = null, $precision = self::DEFAULT_PRECISION) { - $currentCurrency = $this->getCurrency($store, $currency); - $convertedValue = $this->getStore($store)->getBaseCurrency()->convert($amount, $currentCurrency); + $currentCurrency = $this->getCurrency($scope, $currency); + $convertedValue = $this->getStore($scope)->getBaseCurrency()->convert($amount, $currentCurrency); return round($convertedValue, $precision); } diff --git a/app/code/Magento/Sales/Model/Order/Invoice/Total/Subtotal.php b/app/code/Magento/Sales/Model/Order/Invoice/Total/Subtotal.php index b36e7cfabfefa..1b10667eaaddd 100644 --- a/app/code/Magento/Sales/Model/Order/Invoice/Total/Subtotal.php +++ b/app/code/Magento/Sales/Model/Order/Invoice/Total/Subtotal.php @@ -37,46 +37,15 @@ public function collect(\Magento\Sales\Model\Order\Invoice $invoice) $allowedSubtotal = $order->getSubtotal() - $order->getSubtotalInvoiced(); $baseAllowedSubtotal = $order->getBaseSubtotal() - $order->getBaseSubtotalInvoiced(); - $allowedSubtotalInclTax = $allowedSubtotal + - $order->getHiddenTaxAmount() + - $order->getTaxAmount() - - $order->getTaxInvoiced() - - $order->getHiddenTaxInvoiced(); - $baseAllowedSubtotalInclTax = $baseAllowedSubtotal + - $order->getBaseHiddenTaxAmount() + - $order->getBaseTaxAmount() - - $order->getBaseTaxInvoiced() - - $order->getBaseHiddenTaxInvoiced(); - - /** - * Check if shipping tax calculation is included to current invoice. - */ - $includeShippingTax = true; - foreach ($invoice->getOrder()->getInvoiceCollection() as $previousInvoice) { - if ($previousInvoice->getShippingAmount() && !$previousInvoice->isCanceled()) { - $includeShippingTax = false; - break; - } - } - - if ($includeShippingTax) { - $allowedSubtotalInclTax -= $order->getShippingTaxAmount(); - $baseAllowedSubtotalInclTax -= $order->getBaseShippingTaxAmount(); - } else { - $allowedSubtotalInclTax += $order->getShippingHiddenTaxAmount(); - $baseAllowedSubtotalInclTax += $order->getBaseShippingHiddenTaxAmount(); - } + //Note: The $subtotalInclTax and $baseSubtotalInclTax are not adjusted from those provide by the line items + //because the "InclTax" is displayed before any tax adjustments based on discounts, shipping, etc. if ($invoice->isLast()) { $subtotal = $allowedSubtotal; $baseSubtotal = $baseAllowedSubtotal; - $subtotalInclTax = $allowedSubtotalInclTax; - $baseSubtotalInclTax = $baseAllowedSubtotalInclTax; } else { $subtotal = min($allowedSubtotal, $subtotal); $baseSubtotal = min($baseAllowedSubtotal, $baseSubtotal); - $subtotalInclTax = min($allowedSubtotalInclTax, $subtotalInclTax); - $baseSubtotalInclTax = min($baseAllowedSubtotalInclTax, $baseSubtotalInclTax); } $invoice->setSubtotal($subtotal); diff --git a/app/code/Magento/Tax/Helper/Data.php b/app/code/Magento/Tax/Helper/Data.php index 38be2cfd6769e..8d824e169c888 100644 --- a/app/code/Magento/Tax/Helper/Data.php +++ b/app/code/Magento/Tax/Helper/Data.php @@ -629,7 +629,7 @@ public function getCalculationSequence($store = null) * @param null|string|bool|int|Store $store * @return string */ - public function getCalculationAgorithm($store = null) + public function getCalculationAlgorithm($store = null) { return $this->_config->getAlgorithm($store); } @@ -797,23 +797,6 @@ protected function calculateTaxForItems(EntityInterface $order, EntityInterface $orderTaxDetails = $this->orderTaxManagement->getOrderTaxDetails($order->getId()); - // Apply any taxes for shipping - $shippingTaxAmount = $salesItem->getShippingTaxAmount(); - $originalShippingTaxAmount = $order->getShippingTaxAmount(); - if ($shippingTaxAmount && $originalShippingTaxAmount && - $shippingTaxAmount != 0 && floatval($originalShippingTaxAmount) - ) { - //An invoice or credit memo can have a different qty than its order - $shippingRatio = $shippingTaxAmount / $originalShippingTaxAmount; - $itemTaxDetails = $orderTaxDetails->getItems(); - foreach ($itemTaxDetails as $itemTaxDetail) { - //Aggregate taxable items associated with shipping - if ($itemTaxDetail->getType() == \Magento\Quote\Model\Quote\Address::TYPE_SHIPPING) { - $taxClassAmount = $this->_aggregateTaxes($taxClassAmount, $itemTaxDetail, $shippingRatio); - } - } - } - // Apply any taxes for the items /** @var $item \Magento\Sales\Model\Order\Invoice\Item|\Magento\Sales\Model\Order\Creditmemo\Item */ foreach ($salesItem->getItems() as $item) { @@ -845,6 +828,23 @@ protected function calculateTaxForItems(EntityInterface $order, EntityInterface } } + // Apply any taxes for shipping + $shippingTaxAmount = $salesItem->getShippingTaxAmount(); + $originalShippingTaxAmount = $order->getShippingTaxAmount(); + if ($shippingTaxAmount && $originalShippingTaxAmount && + $shippingTaxAmount != 0 && floatval($originalShippingTaxAmount) + ) { + //An invoice or credit memo can have a different qty than its order + $shippingRatio = $shippingTaxAmount / $originalShippingTaxAmount; + $itemTaxDetails = $orderTaxDetails->getItems(); + foreach ($itemTaxDetails as $itemTaxDetail) { + //Aggregate taxable items associated with shipping + if ($itemTaxDetail->getType() == \Magento\Quote\Model\Quote\Address::TYPE_SHIPPING) { + $taxClassAmount = $this->_aggregateTaxes($taxClassAmount, $itemTaxDetail, $shippingRatio); + } + } + } + return $taxClassAmount; } } diff --git a/app/code/Magento/Tax/Model/Config.php b/app/code/Magento/Tax/Model/Config.php index 6dce2c84bb3db..a02796b698d1a 100644 --- a/app/code/Magento/Tax/Model/Config.php +++ b/app/code/Magento/Tax/Model/Config.php @@ -270,7 +270,7 @@ public function getNeedUseShippingExcludeTax() } /** - * Get defined tax calculation agorithm + * Get defined tax calculation algorithm * * @param null|string|bool|int|Store $store * @return string diff --git a/app/code/Magento/Tax/Model/Observer.php b/app/code/Magento/Tax/Model/Observer.php index 6780ad5bae60a..f7143a62112c1 100644 --- a/app/code/Magento/Tax/Model/Observer.php +++ b/app/code/Magento/Tax/Model/Observer.php @@ -300,7 +300,7 @@ public function updateProductOptions(\Magento\Framework\Event\Observer $observer return $this; } - $algorithm = $this->_taxData->getCalculationAgorithm(); + $algorithm = $this->_taxData->getCalculationAlgorithm(); $options['calculationAlgorithm'] = $algorithm; // prepare correct template for options render if ($this->_taxData->displayBothPrices()) { diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/Price.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/Price.php index 68f4197cafbf2..27f393e9dde0a 100755 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/Price.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/Price.php @@ -294,21 +294,23 @@ protected function escape($price, $currency = '$') * Get price excluding tax * * @param string $currency - * @return string + * @return string|null */ public function getPriceExcludingTax($currency = '$') { - return trim($this->_rootElement->find($this->priceExcludingTax)->getText(), $currency); + $priceElement = $this->_rootElement->find($this->priceExcludingTax); + return $priceElement->isVisible() ? trim($priceElement->getText(), $currency) : null; } /** * Get price including tax * * @param string $currency - * @return string + * @return string|null */ public function getPriceIncludingTax($currency = '$') { - return trim($this->_rootElement->find($this->priceIncludingTax)->getText(), $currency); + $priceElement = $this->_rootElement->find($this->priceIncludingTax); + return $priceElement->isVisible() ? trim($priceElement->getText(), $currency) : null; } } diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple/GroupPriceOptions.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple/GroupPriceOptions.php index 256bb41cb82cb..6821fb8dc279c 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple/GroupPriceOptions.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple/GroupPriceOptions.php @@ -69,6 +69,8 @@ public function getDataConfig() } /** + * Get preset array + * * @param string $name * @return mixed|null */ diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestStep/CreateProductStep.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestStep/CreateProductStep.php index 299dc6d37bf27..a65a564db0c08 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestStep/CreateProductStep.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestStep/CreateProductStep.php @@ -55,7 +55,6 @@ public function run() if ($product->hasData('id') === false) { $product->persist(); } - - return ['product' => $product]; + return ['product' => $product]; } } diff --git a/dev/tests/functional/tests/app/Magento/CatalogRule/Test/Repository/CatalogRule.php b/dev/tests/functional/tests/app/Magento/CatalogRule/Test/Repository/CatalogRule.php index a2d1254e13cff..384d6967cca59 100755 --- a/dev/tests/functional/tests/app/Magento/CatalogRule/Test/Repository/CatalogRule.php +++ b/dev/tests/functional/tests/app/Magento/CatalogRule/Test/Repository/CatalogRule.php @@ -88,5 +88,16 @@ public function __construct(array $defaultConfig = [], array $defaultData = []) 'simple_action' => 'By Fixed Amount', 'discount_amount' => '10', ]; + + $this->_data['catalog_price_rule_all_groups'] = [ + 'name' => 'catalog_price_rule_all_groups_%isolation%', + 'description' => '-50% of price, Priority = 0', + 'is_active' => 'Active', + 'website_ids' => ['Main Website'], + 'customer_group_ids' => ['NOT LOGGED IN', 'General', 'Wholesale', 'Retailer'], + 'sort_order' => '0', + 'simple_action' => 'By Percentage of the Original Price', + 'discount_amount' => '50', + ]; } } diff --git a/dev/tests/functional/tests/app/Magento/CatalogRule/Test/TestStep/CreateCatalogRuleStep.php b/dev/tests/functional/tests/app/Magento/CatalogRule/Test/TestStep/CreateCatalogRuleStep.php new file mode 100644 index 0000000000000..f17c6b3962160 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/CatalogRule/Test/TestStep/CreateCatalogRuleStep.php @@ -0,0 +1,62 @@ +fixtureFactory = $fixtureFactory; + $this->catalogRule = $catalogRule; + } + + /** + * Create catalog rule + * + * @return array + */ + public function run() + { + $result['catalogRule'] = null; + if ($this->catalogRule != '-') { + $catalogRule = $this->fixtureFactory->createByCode( + 'catalogRule', + ['dataSet' => $this->catalogRule] + ); + $catalogRule->persist(); + $result['catalogRule'] = $catalogRule; + } + return $result; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart/CartItem.php b/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart/CartItem.php index 28eb3677d16eb..4e9222ccd1348 100755 --- a/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart/CartItem.php +++ b/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart/CartItem.php @@ -69,23 +69,27 @@ public function getProductName() /** * Get product price * - * @return string + * @return string|null */ public function getPrice() { - $cartProductPrice = $this->_rootElement->find($this->price, Locator::SELECTOR_XPATH)->getText(); - return str_replace(',', '', $this->escapeCurrency($cartProductPrice)); + $cartProductPrice = $this->_rootElement->find($this->price, Locator::SELECTOR_XPATH); + return $cartProductPrice->isVisible() + ? str_replace(',', '', $this->escapeCurrency($cartProductPrice->getText())) + : null; } /** * Get product price including tax * - * @return string + * @return string|null */ public function getPriceInclTax() { - $cartProductPrice = $this->_rootElement->find($this->priceInclTax, Locator::SELECTOR_XPATH)->getText(); - return str_replace(',', '', $this->escapeCurrency($cartProductPrice)); + $cartProductPrice = $this->_rootElement->find($this->priceInclTax, Locator::SELECTOR_XPATH); + return $cartProductPrice->isVisible() + ? str_replace(',', '', $this->escapeCurrency($cartProductPrice->getText())) + : null; } /** @@ -112,29 +116,33 @@ public function getQty() /** * Get sub-total for the specified item in the cart * - * @return string + * @return string|null */ public function getSubtotalPrice() { - $price = $this->_rootElement->find($this->subtotalPrice, Locator::SELECTOR_XPATH)->getText(); - return str_replace(',', '', $this->escapeCurrency($price)); + $cartProductPrice = $this->_rootElement->find($this->subtotalPrice, Locator::SELECTOR_XPATH); + return $cartProductPrice->isVisible() + ? str_replace(',', '', $this->escapeCurrency($cartProductPrice->getText())) + : null; } /** * Get sub-total including tax for the specified item in the cart * - * @return string + * @return string|null */ public function getSubtotalPriceInclTax() { - $price = $this->_rootElement->find($this->subTotalPriceInclTax, Locator::SELECTOR_XPATH)->getText(); - return str_replace(',', '', $this->escapeCurrency($price)); + $cartProductPrice = $this->_rootElement->find($this->subTotalPriceInclTax, Locator::SELECTOR_XPATH); + return $cartProductPrice->isVisible() + ? str_replace(',', '', $this->escapeCurrency($cartProductPrice->getText())) + : null; } /** * Get product options in the cart * - * @return string + * @return array */ public function getOptions() { diff --git a/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart/Totals.php b/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart/Totals.php index 009dbf2080cec..1d099279d5f8e 100644 --- a/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart/Totals.php +++ b/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Cart/Totals.php @@ -76,7 +76,7 @@ class Totals extends Block * * @var string */ - protected $discount = '//tr[normalize-space(th)="Discount"]//span'; + protected $discount = '[class=totals] .amount .price'; /** * Get shipping price including tax selector @@ -95,45 +95,45 @@ class Totals extends Block /** * Get Grand Total Text * - * @return array|string + * @return string */ public function getGrandTotal() { - $grandTotal = $this->_rootElement->find($this->grandTotal)->getText(); + $grandTotal = $this->_rootElement->find($this->grandTotal, Locator::SELECTOR_CSS)->getText(); return $this->escapeCurrency($grandTotal); } /** * Get Grand Total Text * - * @return string + * @return string|null */ public function getGrandTotalIncludingTax() { - $grandTotal = $this->_rootElement->find($this->grandTotalInclTax, Locator::SELECTOR_CSS)->getText(); - return $this->escapeCurrency($grandTotal); + $priceElement = $this->_rootElement->find($this->grandTotalInclTax, Locator::SELECTOR_CSS); + return $priceElement->isVisible() ? $this->escapeCurrency($priceElement->getText()) : null; } /** * Get Grand Total Text * - * @return string + * @return string|null */ public function getGrandTotalExcludingTax() { - $grandTotal = $this->_rootElement->find($this->grandTotalExclTax, Locator::SELECTOR_CSS)->getText(); - return $this->escapeCurrency($grandTotal); + $priceElement = $this->_rootElement->find($this->grandTotalExclTax, Locator::SELECTOR_CSS); + return $priceElement->isVisible() ? $this->escapeCurrency($priceElement->getText()) : null; } /** * Get Tax text from Order Totals * - * @return array|string + * @return string|null */ public function getTax() { - $taxPrice = $this->_rootElement->find($this->tax, Locator::SELECTOR_CSS)->getText(); - return $this->escapeCurrency($taxPrice); + $priceElement = $this->_rootElement->find($this->tax, Locator::SELECTOR_CSS); + return $priceElement->isVisible() ? $this->escapeCurrency($priceElement->getText()) : null; } /** @@ -153,37 +153,37 @@ public function isTaxVisible() */ public function getSubtotal() { - $subTotal = $this->_rootElement->find($this->subtotal)->getText(); + $subTotal = $this->_rootElement->find($this->subtotal, Locator::SELECTOR_CSS)->getText(); return $this->escapeCurrency($subTotal); } /** * Get Subtotal text * - * @return string + * @return string|null */ public function getSubtotalIncludingTax() { - $subTotal = $this->_rootElement->find($this->subtotalInclTax, Locator::SELECTOR_CSS)->getText(); - return $this->escapeCurrency($subTotal); + $priceElement = $this->_rootElement->find($this->subtotalInclTax, Locator::SELECTOR_CSS); + return $priceElement->isVisible() ? $this->escapeCurrency($priceElement->getText()) : null; } /** * Get Subtotal text * - * @return string + * @return string|null */ public function getSubtotalExcludingTax() { - $subTotal = $this->_rootElement->find($this->subtotalExclTax, Locator::SELECTOR_CSS)->getText(); - return $this->escapeCurrency($subTotal); + $priceElement = $this->_rootElement->find($this->subtotalExclTax, Locator::SELECTOR_CSS); + return $priceElement->isVisible() ? $this->escapeCurrency($priceElement->getText()) : null; } /** * Method that escapes currency symbols * * @param string $price - * @return string + * @return string|null */ protected function escapeCurrency($price) { @@ -194,35 +194,34 @@ protected function escapeCurrency($price) /** * Get discount * - * @return string + * @return string|null */ public function getDiscount() { - $discount = $this->_rootElement->find($this->discount, Locator::SELECTOR_XPATH)->getText(); - return $this->escapeCurrency($discount); + $priceElement = $this->_rootElement->find($this->discount, Locator::SELECTOR_CSS); + return $priceElement->isVisible() ? $this->escapeCurrency($priceElement->getText()) : null; } /** * Get shipping price * - * @return string + * @return string|null */ public function getShippingPrice() { - $shippingPrice = $this->_rootElement->find($this->shippingPriceSelector, Locator::SELECTOR_CSS)->getText(); - return $this->escapeCurrency($shippingPrice); + $priceElement = $this->_rootElement->find($this->shippingPriceSelector, Locator::SELECTOR_CSS); + return $priceElement->isVisible() ? $this->escapeCurrency($priceElement->getText()) : null; } /** * Get shipping price * - * @return string + * @return string|null */ public function getShippingPriceInclTax() { - $shippingPrice = $this->_rootElement - ->find($this->shippingPriceInclTaxSelector, Locator::SELECTOR_CSS)->getText(); - return $this->escapeCurrency($shippingPrice); + $priceElement = $this->_rootElement->find($this->shippingPriceInclTaxSelector, Locator::SELECTOR_CSS); + return $priceElement->isVisible() ? $this->escapeCurrency($priceElement->getText()) : null; } /** diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AbstractAssertTaxCalculationAfterCheckoutDownloadable.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AbstractAssertTaxCalculationAfterCheckoutDownloadable.php new file mode 100644 index 0000000000000..f8bf3012cfa96 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AbstractAssertTaxCalculationAfterCheckoutDownloadable.php @@ -0,0 +1,74 @@ +checkoutOnepage = $checkoutOnepage; + $this->orderView = $orderView; + + $checkoutCart->getProceedToCheckoutBlock()->proceedToCheckout(); + $checkoutOnepage->getBillingBlock()->clickContinue(); + $checkoutOnepage->getPaymentMethodsBlock()->selectPaymentMethod(['method' => 'check_money_order']); + $checkoutOnepage->getPaymentMethodsBlock()->clickContinue(); + $actualPrices = []; + $actualPrices = $this->getReviewPrices($actualPrices, $product); + $actualPrices = $this->getReviewTotals($actualPrices); + $prices = $this->preparePrices($prices); + //Order review prices verification + $message = 'Prices on order review should be equal to defined in dataset.'; + \PHPUnit_Framework_Assert::assertEquals($prices, $actualPrices, $message); + + $checkoutOnepage->getReviewBlock()->placeOrder(); + $checkoutOnepageSuccess->getSuccessBlock()->getGuestOrderId(); + $checkoutOnepageSuccess->getSuccessBlock()->openOrder(); + $actualPrices = []; + $actualPrices = $this->getOrderPrices($actualPrices, $product); + $actualPrices = $this->getOrderTotals($actualPrices); + + //Frontend order prices verification + $message = 'Prices on order view page should be equal to defined in dataset.'; + \PHPUnit_Framework_Assert::assertEquals($prices, $actualPrices, $message); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AbstractAssertTaxRuleIsAppliedToAllPricesDownloadable.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AbstractAssertTaxRuleIsAppliedToAllPricesDownloadable.php new file mode 100644 index 0000000000000..bd74cdb32ae3b --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AbstractAssertTaxRuleIsAppliedToAllPricesDownloadable.php @@ -0,0 +1,72 @@ +cmsIndex = $cmsIndex; + $this->catalogCategoryView = $catalogCategoryView; + $this->catalogProductView = $catalogProductView; + $this->checkoutCart = $checkoutCart; + $actualPrices = []; + //Assertion steps + $productName = $product->getName(); + $productCategory = $product->getCategoryIds()[0]; + $this->openCategory($productCategory); + $actualPrices = $this->getCategoryPrices($productName, $actualPrices); + $catalogCategoryView->getListProductBlock()->openProductViewPage($productName); + $catalogProductView->getViewBlock()->fillOptions($product); + $actualPrices = $this->getProductPagePrices($actualPrices); + $catalogProductView->getViewBlock()->clickAddToCart(); + $actualPrices = $this->getCartPrices($product, $actualPrices); + $actualPrices = $this->getTotals($actualPrices); + //Prices verification + $message = 'Prices from dataset should be equal to prices on frontend'; + \PHPUnit_Framework_Assert::assertEquals($prices, $actualPrices, $message); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AssertTaxCalculationAfterCheckoutDownloadableExcludingIncludingTax.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AssertTaxCalculationAfterCheckoutDownloadableExcludingIncludingTax.php new file mode 100644 index 0000000000000..64896843ae68b --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AssertTaxCalculationAfterCheckoutDownloadableExcludingIncludingTax.php @@ -0,0 +1,63 @@ +checkoutOnepage->getReviewBlock(); + $actualPrices['subtotal_excl_tax'] = $reviewBlock->getSubtotalExclTax(); + $actualPrices['subtotal_incl_tax'] = $reviewBlock->getSubtotalInclTax(); + $actualPrices['discount'] = $reviewBlock->getDiscount(); + $actualPrices['shipping_excl_tax'] = $reviewBlock->getShippingExclTax(); + $actualPrices['shipping_incl_tax'] = $reviewBlock->getShippingInclTax(); + $actualPrices['tax'] = $reviewBlock->getTax(); + $actualPrices['grand_total_excl_tax'] = $reviewBlock->getGrandTotalExclTax(); + $actualPrices['grand_total_incl_tax'] = $reviewBlock->getGrandTotalInclTax(); + + return $actualPrices; + } + + /** + * Get order totals. + * + * @param $actualPrices + * @return array + */ + public function getOrderTotals($actualPrices) + { + $viewBlock = $this->orderView->getOrderViewBlock(); + $actualPrices['subtotal_excl_tax'] = $viewBlock->getSubtotalExclTax(); + $actualPrices['subtotal_incl_tax'] = $viewBlock->getSubtotalInclTax(); + $actualPrices['discount'] = $viewBlock->getDiscount(); + $actualPrices['shipping_excl_tax'] = $viewBlock->getShippingExclTax(); + $actualPrices['shipping_incl_tax'] = $viewBlock->getShippingInclTax(); + $actualPrices['tax'] = $viewBlock->getTax(); + $actualPrices['grand_total_excl_tax'] = $viewBlock->getGrandTotal(); + $actualPrices['grand_total_incl_tax'] = $viewBlock->getGrandTotalInclTax(); + + return $actualPrices; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AssertTaxCalculationAfterCheckoutDownloadableExcludingTax.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AssertTaxCalculationAfterCheckoutDownloadableExcludingTax.php new file mode 100644 index 0000000000000..60a4e36293d08 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AssertTaxCalculationAfterCheckoutDownloadableExcludingTax.php @@ -0,0 +1,66 @@ +checkoutOnepage->getReviewBlock(); + $actualPrices['subtotal_excl_tax'] = $reviewBlock->getSubtotal(); + $actualPrices['subtotal_incl_tax'] = null; + $actualPrices['discount'] = $reviewBlock->getDiscount(); + $actualPrices['shipping_excl_tax'] = $reviewBlock->getShippingExclTax(); + $actualPrices['shipping_incl_tax'] = $reviewBlock->getShippingInclTax(); + $actualPrices['tax'] = $reviewBlock->getTax(); + $actualPrices['grand_total_excl_tax'] = $reviewBlock->getGrandTotal(); + $actualPrices['grand_total_incl_tax'] = null; + + return $actualPrices; + } + + /** + * Get order totals. + * + * @param $actualPrices + * @return array + */ + public function getOrderTotals($actualPrices) + { + $viewBlock = $this->orderView->getOrderViewBlock(); + $actualPrices['subtotal_excl_tax'] = $viewBlock->getSubtotal(); + $actualPrices['subtotal_incl_tax'] = null; + + $actualPrices['discount'] = $viewBlock->getDiscount(); + $actualPrices['shipping_excl_tax'] = $viewBlock->getShippingExclTax(); + $actualPrices['shipping_incl_tax'] = $viewBlock->getShippingInclTax(); + $actualPrices['tax'] = $viewBlock->getTax(); + $actualPrices['grand_total_excl_tax'] = $viewBlock->getGrandTotal(); + $actualPrices['grand_total_incl_tax'] = null; + + return $actualPrices; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AssertTaxCalculationAfterCheckoutDownloadableIncludingTax.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AssertTaxCalculationAfterCheckoutDownloadableIncludingTax.php new file mode 100644 index 0000000000000..653b30217dbb1 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AssertTaxCalculationAfterCheckoutDownloadableIncludingTax.php @@ -0,0 +1,63 @@ +checkoutOnepage->getReviewBlock(); + $actualPrices['subtotal_excl_tax'] = null; + $actualPrices['subtotal_incl_tax'] = $reviewBlock->getSubtotal(); + $actualPrices['discount'] = $reviewBlock->getDiscount(); + $actualPrices['shipping_excl_tax'] = $reviewBlock->getShippingExclTax(); + $actualPrices['shipping_incl_tax'] = $reviewBlock->getShippingInclTax(); + $actualPrices['tax'] = $reviewBlock->getTax(); + $actualPrices['grand_total_excl_tax'] = $reviewBlock->getGrandTotalExclTax(); + $actualPrices['grand_total_incl_tax'] = $reviewBlock->getGrandTotalInclTax(); + + return $actualPrices; + } + + /** + * Get order totals. + * + * @param $actualPrices + * @return array + */ + public function getOrderTotals($actualPrices) + { + $viewBlock = $this->orderView->getOrderViewBlock(); + $actualPrices['subtotal_excl_tax'] = null; + $actualPrices['subtotal_incl_tax'] = $viewBlock->getSubtotal(); + $actualPrices['discount'] = $viewBlock->getDiscount(); + $actualPrices['shipping_excl_tax'] = $viewBlock->getShippingExclTax(); + $actualPrices['shipping_incl_tax'] = $viewBlock->getShippingInclTax(); + $actualPrices['tax'] = $viewBlock->getTax(); + $actualPrices['grand_total_excl_tax'] = $viewBlock->getGrandTotal(); + $actualPrices['grand_total_incl_tax'] = $viewBlock->getGrandTotalInclTax(); + + return $actualPrices; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AssertTaxRuleIsAppliedToAllPricesDownloadableExcludingIncludingTax.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AssertTaxRuleIsAppliedToAllPricesDownloadableExcludingIncludingTax.php new file mode 100644 index 0000000000000..2ea9f0bc5bd24 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AssertTaxRuleIsAppliedToAllPricesDownloadableExcludingIncludingTax.php @@ -0,0 +1,73 @@ +catalogCategoryView->getListProductBlock()->getProductPriceBlock($productName); + $actualPrices['category_price_excl_tax'] = $priceBlock->getPriceExcludingTax(); + $actualPrices['category_price_incl_tax'] = $priceBlock->getPriceIncludingTax(); + + return $actualPrices; + } + + /** + * Get product view prices. + * + * @param array $actualPrices + * @return array + */ + public function getProductPagePrices($actualPrices) + { + $viewBlock = $this->catalogProductView->getViewBlock(); + $actualPrices['product_view_price_excl_tax'] = $viewBlock->getProductPriceExcludingTax(); + $actualPrices['product_view_price_incl_tax'] = $viewBlock->getProductPriceIncludingTax(); + + return $actualPrices; + } + + /** + * Get totals. + * + * @param $actualPrices + * @return array + */ + public function getTotals($actualPrices) + { + $totalsBlock = $this->checkoutCart->getTotalsBlock(); + $actualPrices['subtotal_excl_tax'] = $totalsBlock->getSubtotalExcludingTax(); + $actualPrices['subtotal_incl_tax'] = $totalsBlock->getSubtotalIncludingTax(); + $actualPrices['discount'] = $totalsBlock->getDiscount(); + $actualPrices['shipping_excl_tax'] = $totalsBlock->getShippingPrice(); + $actualPrices['shipping_incl_tax'] = $totalsBlock->getShippingPriceInclTax(); + $actualPrices['tax'] = $totalsBlock->getTax(); + $actualPrices['grand_total_excl_tax'] = $totalsBlock->getGrandTotalExcludingTax(); + $actualPrices['grand_total_incl_tax'] = $totalsBlock->getGrandTotalIncludingTax(); + + return $actualPrices; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AssertTaxRuleIsAppliedToAllPricesDownloadableExcludingTax.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AssertTaxRuleIsAppliedToAllPricesDownloadableExcludingTax.php new file mode 100644 index 0000000000000..eaa5d5e115f59 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AssertTaxRuleIsAppliedToAllPricesDownloadableExcludingTax.php @@ -0,0 +1,74 @@ +catalogCategoryView->getListProductBlock()->getProductPriceBlock($productName); + $actualPrices['category_price_excl_tax'] = $priceBlock->getEffectivePrice(); + $actualPrices['category_price_incl_tax'] = null; + + return $actualPrices; + } + + /** + * Get product view prices. + * + * @param array $actualPrices + * @return array + */ + public function getProductPagePrices($actualPrices) + { + $viewBlock = $this->catalogProductView->getViewBlock(); + $actualPrices['product_view_price_excl_tax'] = $viewBlock->getPriceBlock()->getEffectivePrice(); + $actualPrices['product_view_price_incl_tax'] = null; + + return $actualPrices; + } + + /** + * Get totals. + * + * @param array $actualPrices + * @return array + */ + public function getTotals($actualPrices) + { + $totalsBlock = $this->checkoutCart->getTotalsBlock(); + $actualPrices['subtotal_excl_tax'] = $totalsBlock->getSubtotal(); + $actualPrices['subtotal_incl_tax'] = null; + $actualPrices['discount'] = $totalsBlock->getDiscount(); + $actualPrices['shipping_excl_tax'] = $totalsBlock->getShippingPrice(); + $actualPrices['shipping_incl_tax'] = $totalsBlock->getShippingPriceInclTax(); + $actualPrices['tax'] = $totalsBlock->getTax(); + $actualPrices['grand_total_excl_tax'] = $totalsBlock->getGrandTotal(); + $actualPrices['grand_total_incl_tax'] = null; + + return $actualPrices; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AssertTaxRuleIsAppliedToAllPricesDownloadableIncludingTax.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AssertTaxRuleIsAppliedToAllPricesDownloadableIncludingTax.php new file mode 100644 index 0000000000000..31fc3a1154b3d --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AssertTaxRuleIsAppliedToAllPricesDownloadableIncludingTax.php @@ -0,0 +1,73 @@ +catalogCategoryView->getListProductBlock()->getProductPriceBlock($productName); + $actualPrices['category_price_excl_tax'] = null; + $actualPrices['category_price_incl_tax'] = $priceBlock->getEffectivePrice(); + + return $actualPrices; + } + + /** + * Get product view prices. + * + * @param array $actualPrices + * @return array + */ + public function getProductPagePrices($actualPrices) + { + $viewBlock = $this->catalogProductView->getViewBlock(); + $actualPrices['product_view_price_excl_tax'] = null; + $actualPrices['product_view_price_incl_tax'] = $viewBlock->getPriceBlock()->getEffectivePrice(); + + return $actualPrices; + } + + /** + * Get totals. + * + * @param $actualPrices + * @return array + */ + public function getTotals($actualPrices) + { + $totalsBlock = $this->checkoutCart->getTotalsBlock(); + $actualPrices['subtotal_excl_tax'] = null; + $actualPrices['subtotal_incl_tax'] = $totalsBlock->getSubtotal(); + $actualPrices['discount'] = $totalsBlock->getDiscount(); + $actualPrices['shipping_excl_tax'] = $totalsBlock->getShippingPrice(); + $actualPrices['shipping_incl_tax'] = $totalsBlock->getShippingPriceInclTax(); + $actualPrices['tax'] = $totalsBlock->getTax(); + $actualPrices['grand_total_excl_tax'] = $totalsBlock->getGrandTotalExcludingTax(); + $actualPrices['grand_total_incl_tax'] = $totalsBlock->getGrandTotalIncludingTax(); + + return $actualPrices; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/DownloadableProductInjectable.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/DownloadableProductInjectable.php index ae72fdb25a22d..9b649d0c949a1 100644 --- a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/DownloadableProductInjectable.php +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/DownloadableProductInjectable.php @@ -144,7 +144,7 @@ class DownloadableProductInjectable extends InjectableFixture 'default_value' => '', 'input' => 'text', 'group' => 'advanced-pricing', - 'source' => 'Magento\Catalog\Test\Fixture\CatalogProductSimple\GroupPriceOptions', + 'source' => '\Magento\Downloadable\Test\Fixture\DownloadableProductInjectable\GroupPriceOptions' ]; protected $has_options = [ diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/DownloadableProductInjectable/CheckoutData.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/DownloadableProductInjectable/CheckoutData.php index 3607174b0c716..6273955c5ba95 100644 --- a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/DownloadableProductInjectable/CheckoutData.php +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/DownloadableProductInjectable/CheckoutData.php @@ -80,6 +80,23 @@ protected function getPreset($name) ], ], ], + + 'one_custom_option_and_downloadable_link' => [ + 'options' => [ + 'custom_options' => [ + [ + 'title' => 'attribute_key_0', + 'value' => 'option_key_0' + ], + ], + 'links' => [ + [ + 'label' => 'link_1', + 'value' => 'Yes' + ] + ], + ] + ], ]; return isset($presets[$name]) ? $presets[$name] : []; } diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/DownloadableProductInjectable/GroupPriceOptions.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/DownloadableProductInjectable/GroupPriceOptions.php new file mode 100644 index 0000000000000..2d0b2c8f339df --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/DownloadableProductInjectable/GroupPriceOptions.php @@ -0,0 +1,43 @@ + [ + [ + 'price' => 20, + 'website' => 'All Websites [USD]', + 'customer_group' => 'NOT LOGGED IN', + ], + ], + 'downloadable_with_tax' => [ + [ + 'price' => 20.00, + 'website' => 'All Websites [USD]', + 'customer_group' => 'General', + ], + ], + ]; + if (!isset($presets[$name])) { + return null; + } + return $presets[$name]; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Repository/DownloadableProductInjectable.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Repository/DownloadableProductInjectable.php index de7dda22fc1d3..240e3b2b1b206 100644 --- a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Repository/DownloadableProductInjectable.php +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Repository/DownloadableProductInjectable.php @@ -21,6 +21,7 @@ class DownloadableProductInjectable extends AbstractRepository * @param array $defaultData [optional] * * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function __construct(array $defaultConfig = [], array $defaultData = []) { @@ -74,5 +75,65 @@ public function __construct(array $defaultConfig = [], array $defaultData = []) 'downloadable_links' => ['preset' => 'with_two_separately_links'], 'checkout_data' => ['preset' => 'with_two_bought_links'], ]; + $this->_data['with_two_separately_links_special_price_and_category'] = [ + 'name' => 'Downloadable product %isolation%', + 'sku' => 'downloadable_product_%isolation%', + 'type_id' => 'downloadable', + 'url_key' => 'downloadable-product-%isolation%', + 'price' => ['value' => '30'], + 'special_price' => '20', + 'tax_class_id' => ['dataSet' => 'Taxable Goods'], + 'quantity_and_stock_status' => [ + 'qty' => 1111, + 'is_in_stock' => 'In Stock' + ], + 'status' => 'Product online', + 'category_ids' => ['presets' => 'default'], + 'visibility' => 'Catalog, Search', + 'is_virtual' => 'Yes', + 'website_ids' => ['Main Website'], + 'downloadable_links' => ['preset' => 'with_two_separately_links'], + 'checkout_data' => ['preset' => 'with_two_separately_links'] + ]; + $this->_data['with_two_separately_links_group_price_and_category'] = [ + 'name' => 'Downloadable product %isolation%', + 'sku' => 'downloadable_product_%isolation%', + 'type_id' => 'downloadable', + 'url_key' => 'downloadable-product-%isolation%', + 'price' => ['value' => '30'], + 'group_price' => ['preset' => 'downloadable_with_tax'], + 'tax_class_id' => ['dataSet' => 'Taxable Goods'], + 'quantity_and_stock_status' => [ + 'qty' => 1111, + 'is_in_stock' => 'In Stock' + ], + 'status' => 'Product online', + 'category_ids' => ['presets' => 'default'], + 'visibility' => 'Catalog, Search', + 'is_virtual' => 'Yes', + 'website_ids' => ['Main Website'], + 'downloadable_links' => ['preset' => 'with_two_separately_links'], + 'checkout_data' => ['preset' => 'with_two_separately_links'] + ]; + $this->_data['with_two_separately_links_custom_options_and_category'] = [ + 'name' => 'Downloadable product %isolation%', + 'sku' => 'downloadable_product_%isolation%', + 'type_id' => 'downloadable', + 'url_key' => 'downloadable-product-%isolation%', + 'price' => ['value' => '20'], + 'tax_class_id' => ['dataSet' => 'Taxable Goods'], + 'quantity_and_stock_status' => [ + 'qty' => 1111, + 'is_in_stock' => 'In Stock' + ], + 'status' => 'Product online', + 'category_ids' => ['presets' => 'default'], + 'visibility' => 'Catalog, Search', + 'is_virtual' => 'Yes', + 'website_ids' => ['Main Website'], + 'custom_options' => ['preset' => 'drop_down_with_one_option_percent_price'], + 'downloadable_links' => ['preset' => 'with_two_separately_links'], + 'checkout_data' => ['preset' => 'one_custom_option_and_downloadable_link'] + ]; } } diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/etc/constraint.xml b/dev/tests/functional/tests/app/Magento/Downloadable/Test/etc/constraint.xml index 61e5435814dbc..bfa96b20b8790 100644 --- a/dev/tests/functional/tests/app/Magento/Downloadable/Test/etc/constraint.xml +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/etc/constraint.xml @@ -26,4 +26,31 @@ low + + high + + + high + + + high + + + high + + + high + + + high + + + high + + + high + + + high + diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/AbstractForm/Product.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/AbstractForm/Product.php index 9c0993bfbe16a..5ce54826b4e37 100644 --- a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/AbstractForm/Product.php +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/AbstractForm/Product.php @@ -7,6 +7,7 @@ namespace Magento\Sales\Test\Block\Adminhtml\Order\AbstractForm; use Mtf\Block\Form; +use Mtf\Client\Element\Locator; /** * Class Product @@ -14,6 +15,91 @@ */ class Product extends Form { + /** + * Product price excluding tax search mask + * + * @var string + */ + protected $itemExclTax = '//td[@class="col-price"]/div[@class="price-excl-tax"]/span[@class="price"]'; + + /** + * Product price including tax search mask + * + * @var string + */ + protected $itemInclTax = '//td[@class="col-price"]/div[@class="price-incl-tax"]/span[@class="price"]'; + + /** + * Product price subtotal excluding tax search mask + * + * @var string + */ + protected $itemSubExclTax = '//td[@class="col-subtotal"]/div[@class="price-excl-tax"]/span[@class="price"]'; + + /** + * Product price subtotal including tax search mask + * + * @var string + */ + protected $itemSubInclTax = '//td[@class="col-subtotal"]/div[@class="price-incl-tax"]/span[@class="price"]'; + + /** + * Get Item price excluding tax + * + * @return string|null + */ + public function getItemPriceExclTax() + { + $price = $this->_rootElement->find($this->itemExclTax, Locator::SELECTOR_XPATH); + return $price->isVisible() ? $this->escapeCurrency($price->getText()) : null; + } + + /** + * Get Item price including tax + * + * @return string|null + */ + public function getItemPriceInclTax() + { + $price = $this->_rootElement->find($this->itemInclTax, Locator::SELECTOR_XPATH); + return $price->isVisible() ? $this->escapeCurrency($price->getText()) : null; + } + + /** + * Get Item price excluding tax + * + * @return string|null + */ + public function getItemSubExclTax() + { + $price = $this->_rootElement->find($this->itemSubExclTax, Locator::SELECTOR_XPATH); + return $price->isVisible() ? $this->escapeCurrency($price->getText()) : null; + } + + /** + * Get Item price excluding tax + * + * @return string|null + */ + + public function getItemSubInclTax() + { + $price = $this->_rootElement->find($this->itemSubInclTax, Locator::SELECTOR_XPATH); + return $price->isVisible() ? $this->escapeCurrency($price->getText()) : null; + } + + /** + * Method that escapes currency symbols + * + * @param string $price + * @return string|null + */ + protected function escapeCurrency($price) + { + preg_match("/^\\D*\\s*([\\d,\\.]+)\\s*\\D*$/", $price, $matches); + return (isset($matches[1])) ? $matches[1] : null; + } + /** * Fill item product data * diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Grid.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Grid.php index a740f6dcc214e..d290e90c50a3e 100644 --- a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Grid.php +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Grid.php @@ -43,6 +43,13 @@ class Grid extends GridInterface */ protected $editLink = 'td[class*=col-action] a'; + /** + * First row selector + * + * @var string + */ + protected $firstRowSelector = '//tbody/tr[1]//a'; + /** * {@inheritdoc} */ diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Invoice/Form.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Invoice/Form.php index 83f8ab5d76e9c..d6578371062e9 100644 --- a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Invoice/Form.php +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Invoice/Form.php @@ -27,7 +27,7 @@ class Form extends AbstractForm * * @return Items */ - protected function getItemsBlock() + public function getItemsBlock() { return $this->blockFactory->create( 'Magento\Sales\Test\Block\Adminhtml\Order\Invoice\Form\Items', diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Invoice/Totals.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Invoice/Totals.php index 59ba8ff2333cf..2d8e37fb31a7c 100644 --- a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Invoice/Totals.php +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Invoice/Totals.php @@ -13,7 +13,7 @@ * Class Totals * Invoice totals block */ -class Totals extends Block +class Totals extends \Magento\Sales\Test\Block\Adminhtml\Order\Totals { /** * Submit invoice button selector diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Totals.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Totals.php index 7e1a293ba76d7..9be916c69feb7 100644 --- a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Totals.php +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Totals.php @@ -10,23 +10,84 @@ use Mtf\Client\Locator; /** - * Class Totals - * Order totals block - * + * Invoice totals block */ class Totals extends Block { /** - * Grand total search mask + * Grand total search mask. * * @var string */ protected $grandTotal = '//tr[normalize-space(td)="Grand Total"]//span'; /** - * Get Grand Total Text + * Grand total excluding tax search mask. * - * @return array|string + * @var string + */ + protected $grandTotalExclTax = '//tr[normalize-space(td)="Grand Total (Excl.Tax)"]//span'; + + /** + * Grand total including tax search mask. + * + * @var string + */ + protected $grandTotalInclTax = '//tr[normalize-space(td)="Grand Total (Incl.Tax)"]//span'; + + /** + * Subtotal search mask. + * + * @var string + */ + protected $subtotal = '//tr[normalize-space(td)="Subtotal"]//span'; + + /** + * Subtotal excluding tax search mask. + * + * @var string + */ + protected $subtotalExclTax = '//tr[normalize-space(td)="Subtotal (Excl.Tax)"]//span'; + + /** + * Subtotal including tax search mask. + * + * @var string + */ + protected $subtotalInclTax = '//tr[normalize-space(td)="Subtotal (Incl.Tax)"]//span'; + + /** + * Tax search mask. + * + * @var string + */ + protected $tax = '//tr[normalize-space(td)="Tax"]//span'; + + /** + * Discount search mask. + * + * @var string + */ + protected $discount = '//tr[normalize-space(td)="Discount"]//span'; + + /** + * Shipping excluding tax search mask. + * + * @var string + */ + protected $shippingExclTax = '//tr[contains (.,"Shipping") and contains (.,"(Excl.Tax)")]//span'; + + /** + * Shipping including tax search mask. + * + * @var string + */ + protected $shippingInclTax = '//tr[contains (.,"Shipping") and contains (.,"(Incl.Tax)")]//span'; + + /** + * Get Grand Total Text. + * + * @return string */ public function getGrandTotal() { @@ -35,7 +96,106 @@ public function getGrandTotal() } /** - * Method that escapes currency symbols + * Get Grand Total Excluding Tax Text. + * + * @return string + */ + public function getGrandTotalExclTax() + { + $grandTotal = $this->_rootElement->find($this->grandTotalExclTax, Locator::SELECTOR_XPATH)->getText(); + return $this->escapeCurrency($grandTotal); + } + + /** + * Get Grand Total Including Tax Text. + * + * @return string + */ + public function getGrandTotalInclTax() + { + $grandTotal = $this->_rootElement->find($this->grandTotalInclTax, Locator::SELECTOR_XPATH)->getText(); + return $this->escapeCurrency($grandTotal); + } + + /** + * Get Tax text from Order Totals. + * + * @return string + */ + public function getTax() + { + $tax = $this->_rootElement->find($this->tax, Locator::SELECTOR_XPATH)->getText(); + return $this->escapeCurrency($tax); + } + + /** + * Get Tax text from Order Totals. + * + * @return string|null + */ + public function getDiscount() + { + $discount = $this->_rootElement->find($this->discount, Locator::SELECTOR_XPATH); + return $discount->isVisible() ? $this->escapeCurrency($discount->getText()) : null; + } + + /** + * Get Subtotal text. + * + * @return string + */ + public function getSubtotal() + { + $subTotal = $this->_rootElement->find($this->subtotal, Locator::SELECTOR_XPATH)->getText(); + return $this->escapeCurrency($subTotal); + } + + /** + * Get Subtotal text. + * + * @return string + */ + public function getSubtotalExclTax() + { + $subTotal = $this->_rootElement->find($this->subtotalExclTax, Locator::SELECTOR_XPATH)->getText(); + return $this->escapeCurrency($subTotal); + } + + /** + * Get Subtotal text. + * + * @return string + */ + public function getSubtotalInclTax() + { + $subTotal = $this->_rootElement->find($this->subtotalInclTax, Locator::SELECTOR_XPATH)->getText(); + return $this->escapeCurrency($subTotal); + } + + /** + * Get Shipping Excluding tax price text. + * + * @return string|null + */ + public function getShippingInclTax() + { + $subTotal = $this->_rootElement->find($this->shippingInclTax, Locator::SELECTOR_XPATH); + return $subTotal->isVisible() ? $this->escapeCurrency($subTotal->getText()) : null; + } + + /** + * Get Shipping Including tax price text. + * + * @return string|null + */ + public function getShippingExclTax() + { + $subTotal = $this->_rootElement->find($this->shippingExclTax, Locator::SELECTOR_XPATH); + return $subTotal->isVisible() ? $this->escapeCurrency($subTotal->getText()) : null; + } + + /** + * Method that escapes currency symbols. * * @param string $price * @return string|null diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/View/Items.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/View/Items.php index 4eec62d00bff2..6c1fe10c67bf7 100644 --- a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/View/Items.php +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/View/Items.php @@ -24,6 +24,36 @@ class Items extends Block */ protected $priceSelector = '//div[@class="price-excl-tax"]//span[@class="price"]'; + // @codingStandardsIgnoreStart + /** + * Product price excluding tax search mask + * + * @var string + */ + protected $itemExclTax = '//tr[contains (.,"%s")]/td[@class="col-price"]/div[@class="price-excl-tax"]/span[@class="price"]'; + + /** + * Product price including tax search mask + * + * @var string + */ + protected $itemInclTax = '//tr[contains (.,"%s")]/td[@class="col-price"]/div[@class="price-incl-tax"]/span[@class="price"]'; + + /** + * Product price subtotal excluding tax search mask + * + * @var string + */ + protected $itemSubExclTax = '//tr[contains (.,"%s")]/td[@class="col-subtotal"]/div[@class="price-excl-tax"]/span[@class="price"]'; + + /** + * Product price subtotal including tax search mask + * + * @var string + */ + protected $itemSubInclTax = '//tr[contains (.,"%s")]/td[@class="col-subtotal"]/div[@class="price-incl-tax"]/span[@class="price"]'; + // @codingStandardsIgnoreEnd + /** * Returns the item price for the specified product. * @@ -53,4 +83,68 @@ public function getPrice(Product $product) return $this->_rootElement->find($selector, Locator::SELECTOR_XPATH)->getText(); } + + /** + * Get Item price excluding tax + * + * @param string $productName + * @return string|null + */ + public function getItemPriceExclTax($productName) + { + $locator = sprintf($this->itemExclTax, $productName); + $price = $this->_rootElement->find($locator, Locator::SELECTOR_XPATH); + return $price->isVisible() ? $this->escapeCurrency($price->getText()) : null; + } + + /** + * Get Item price including tax + * + * @param string $productName + * @return string|null + */ + public function getItemPriceInclTax($productName) + { + $locator = sprintf($this->itemInclTax, $productName); + $price = $this->_rootElement->find($locator, Locator::SELECTOR_XPATH); + return $price->isVisible() ? $this->escapeCurrency($price->getText()) : null; + } + + /** + * Get Item price excluding tax + * + * @param string $productName + * @return string|null + */ + public function getItemSubExclTax($productName) + { + $locator = sprintf($this->itemSubExclTax, $productName); + $price = $this->_rootElement->find($locator, Locator::SELECTOR_XPATH); + return $price->isVisible() ? $this->escapeCurrency($price->getText()) : null; + } + + /** + * Get Item price excluding tax + * + * @param string $productName + * @return string|null + */ + public function getItemSubInclTax($productName) + { + $locator = sprintf($this->itemSubInclTax, $productName); + $price = $this->_rootElement->find($locator, Locator::SELECTOR_XPATH); + return $price->isVisible() ? $this->escapeCurrency($price->getText()) : null; + } + + /** + * Method that escapes currency symbols + * + * @param string $price + * @return string|null + */ + protected function escapeCurrency($price) + { + preg_match("/^\\D*\\s*([\\d,\\.]+)\\s*\\D*$/", $price, $matches); + return (isset($matches[1])) ? $matches[1] : null; + } } diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Order/View.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Order/View.php index 41b73a9a29e89..2eea79852dbb7 100644 --- a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Order/View.php +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Order/View.php @@ -12,6 +12,8 @@ /** * Class View * View block on order's view page + * + * @SuppressWarnings(PHPMD.TooManyFields) */ class View extends Block { @@ -36,6 +38,99 @@ class View extends Block */ protected $link = '//*[contains(@class,"order-links")]//a[normalize-space(.)="%s"]'; + /** + * Grand total search mask + * + * @var string + */ + protected $grandTotal = '.grand_total span'; + + /** + * Grand total including tax search mask + * + * @var string + */ + protected $grandTotalInclTax = '.grand_total_incl span'; + + /** + * Subtotal search mask + * + * @var string + */ + protected $subtotal = '.subtotal .amount span'; + + /** + * Subtotal excluding tax search mask + * + * @var string + */ + protected $subtotalExclTax = '.subtotal_excl span'; + + /** + * Subtotal including tax search mask + * + * @var string + */ + protected $subtotalInclTax = '.subtotal_incl span'; + + /** + * Tax search mask + * + * @var string + */ + protected $tax = '.totals-tax span'; + + /** + * Discount search mask + * + * @var string + */ + protected $discount = '.discount span'; + + /** + * Shipping search mask + * + * @var string + */ + protected $shippingExclTax = '.shipping span'; + + /** + * Shipping search mask + * + * @var string + */ + protected $shippingInclTax = '.shipping_incl span'; + + /** + * Product price excluding tax search mask + * + * @var string + */ + protected $itemExclTax = '//tr[contains (.,"%s")]/td[@class="col price"]/span[@class="price-excluding-tax"]/span'; + + /** + * Product price including tax search mask + * + * @var string + */ + protected $itemInclTax = '//tr[contains (.,"%s")]/td[@class="col price"]/span[@class="price-including-tax"]/span'; + + // @codingStandardsIgnoreStart + /** + * Product price subtotal excluding tax search mask + * + * @var string + */ + protected $itemSubExclTax = '//tr[contains (.,"%s")]/td[@class="col subtotal"]/span[@class="price-excluding-tax"]/span'; + + /** + * Product price subtotal including tax search mask + * + * @var string + */ + protected $itemSubInclTax = '//tr[contains (.,"%s")]/td[@class="col subtotal"]/span[@class="price-including-tax"]/span'; + // @codingStandardsIgnoreEnd + /** * Get item block * @@ -61,4 +156,167 @@ public function openLinkByName($name) { $this->_rootElement->find(sprintf($this->link, $name), Locator::SELECTOR_XPATH)->click(); } + + /** + * Get Grand Total Text + * + * @return string + */ + public function getGrandTotal() + { + $grandTotal = $this->_rootElement->find($this->grandTotal, Locator::SELECTOR_CSS)->getText(); + return $this->escapeCurrency($grandTotal); + } + + /** + * Get Item price excluding tax + * + * @param string $productName + * @return string|null + */ + public function getItemPriceExclTax($productName) + { + $locator = sprintf($this->itemExclTax, $productName); + $price = $this->_rootElement->find($locator, Locator::SELECTOR_XPATH); + return $price->isVisible() ? $this->escapeCurrency($price->getText()) : null; + } + + /** + * Get Item price excluding tax + * + * @param string $productName + * @return string|null + */ + public function getItemPriceInclTax($productName) + { + $locator = sprintf($this->itemInclTax, $productName); + $price = $this->_rootElement->find($locator, Locator::SELECTOR_XPATH); + return $price->isVisible() ? $this->escapeCurrency($price->getText()) : null; + } + + /** + * Get Item price excluding tax + * + * @param string $productName + * @return string|null + */ + public function getItemSubExclTax($productName) + { + $locator = sprintf($this->itemSubExclTax, $productName); + $price = $this->_rootElement->find($locator, Locator::SELECTOR_XPATH); + return $price->isVisible() ? $this->escapeCurrency($price->getText()) : null; + } + + /** + * Get Item price excluding tax + * + * @param string $productName + * @return string|null + */ + public function getItemSubInclTax($productName) + { + $locator = sprintf($this->itemSubInclTax, $productName); + $price = $this->_rootElement->find($locator, Locator::SELECTOR_XPATH); + return $price->isVisible() ? $this->escapeCurrency($price->getText()) : null; + } + + /** + * Get Grand Total Text + * + * @return string|null + */ + public function getGrandTotalInclTax() + { + $grandTotal = $this->_rootElement->find($this->grandTotalInclTax, Locator::SELECTOR_CSS)->getText(); + return $this->escapeCurrency($grandTotal); + } + + /** + * Get Tax text from Order Totals + * + * @return string + */ + public function getTax() + { + $tax = $this->_rootElement->find($this->tax, Locator::SELECTOR_CSS)->getText(); + return $this->escapeCurrency($tax); + } + + /** + * Get Tax text from Order Totals + * + * @return string|null + */ + public function getDiscount() + { + $discount = $this->_rootElement->find($this->discount, Locator::SELECTOR_CSS); + return $discount->isVisible() ? $this->escapeCurrency($discount->getText()) : null; + } + + /** + * Get Subtotal text + * + * @return string + */ + public function getSubtotal() + { + $subTotal = $this->_rootElement->find($this->subtotal, Locator::SELECTOR_CSS)->getText(); + return $this->escapeCurrency($subTotal); + } + + /** + * Get Subtotal text + * + * @return string + */ + public function getSubtotalExclTax() + { + $subTotal = $this->_rootElement->find($this->subtotalExclTax, Locator::SELECTOR_CSS)->getText(); + return $this->escapeCurrency($subTotal); + } + + /** + * Get Subtotal text + * + * @return string + */ + public function getSubtotalInclTax() + { + $subTotal = $this->_rootElement->find($this->subtotalInclTax, Locator::SELECTOR_CSS)->getText(); + return $this->escapeCurrency($subTotal); + } + + /** + * Get Shipping Excluding tax price text + * + * @return string|null + */ + public function getShippingInclTax() + { + $subTotal = $this->_rootElement->find($this->shippingInclTax, Locator::SELECTOR_CSS); + return $subTotal->isVisible() ? $this->escapeCurrency($subTotal->getText()) : null; + } + + /** + * Get Shipping Including tax price text + * + * @return string|null + */ + public function getShippingExclTax() + { + $subTotal = $this->_rootElement->find($this->shippingExclTax, Locator::SELECTOR_CSS); + return $subTotal->isVisible() ? $this->escapeCurrency($subTotal->getText()) : null; + } + + /** + * Method that escapes currency symbols + * + * @param string $price + * @return string|null + */ + protected function escapeCurrency($price) + { + preg_match("/^\\D*\\s*([\\d,\\.]+)\\s*\\D*$/", $price, $matches); + return (isset($matches[1])) ? $matches[1] : null; + } } diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Page/Adminhtml/OrderCreditMemoNew.xml b/dev/tests/functional/tests/app/Magento/Sales/Test/Page/Adminhtml/OrderCreditMemoNew.xml index f7c762432c4d7..08bab6e84bf98 100644 --- a/dev/tests/functional/tests/app/Magento/Sales/Test/Page/Adminhtml/OrderCreditMemoNew.xml +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Page/Adminhtml/OrderCreditMemoNew.xml @@ -17,5 +17,10 @@ #edit_form css selector + + Magento\Sales\Test\Block\Adminhtml\Order\Creditmemo\Totals + .creditmemo-totals + css selector + diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AbstractAssertOrderTaxOnBackend.php b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AbstractAssertOrderTaxOnBackend.php new file mode 100644 index 0000000000000..aa63949e9de9d --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AbstractAssertOrderTaxOnBackend.php @@ -0,0 +1,231 @@ +orderView = $orderView; + $this->orderInvoiceNew = $orderInvoiceNew; + $this->orderCreditMemoNew = $orderCreditMemoNew; + $orderIndex->open(); + $orderIndex->getSalesOrderGrid()->openFirstRow(); + //Check prices on order page + $actualPrices = []; + $actualPrices = $this->getOrderPrices($actualPrices, $product); + $actualPrices = $this->getOrderTotals($actualPrices); + $prices = $this->preparePrices($prices); + $message = 'Prices on order view page should be equal to defined in dataset.'; + \PHPUnit_Framework_Assert::assertEquals($prices, $actualPrices, $message); + $orderView->getPageActions()->invoice(); + //Check prices on invoice creation page + $actualPrices = []; + $actualPrices = $this->getInvoiceNewPrices($actualPrices, $product); + $actualPrices = $this->getInvoiceNewTotals($actualPrices); + $message = 'Prices on invoice new page should be equal to defined in dataset.'; + \PHPUnit_Framework_Assert::assertEquals($prices, $actualPrices, $message); + $orderInvoiceNew->getTotalsBlock()->submit(); + //Check prices after invoice on order page + $actualPrices = []; + $actualPrices = $this->getOrderPrices($actualPrices, $product); + $actualPrices = $this->getOrderTotals($actualPrices); + $message = 'Prices on invoice page should be equal to defined in dataset.'; + \PHPUnit_Framework_Assert::assertEquals($prices, $actualPrices, $message); + $orderView->getPageActions()->orderCreditMemo(); + //Check prices on credit memo creation page + $pricesCreditMemo = $this->preparePricesCreditMemo($prices); + $actualPrices = []; + $actualPrices = $this->getCreditMemoNewPrices($actualPrices, $product); + $actualPrices = $this->getCreditMemoNewTotals($actualPrices); + $message = 'Prices on credit memo new page should be equal to defined in dataset.'; + \PHPUnit_Framework_Assert::assertEquals($pricesCreditMemo, $actualPrices, $message); + $orderCreditMemoNew->getFormBlock()->submit(); + //Check prices after refund on order page + $actualPrices = []; + $actualPrices = $this->getOrderPrices($actualPrices, $product); + $actualPrices = $this->getOrderTotals($actualPrices); + $message = 'Prices on credit memo page should be equal to defined in dataset.'; + \PHPUnit_Framework_Assert::assertEquals($prices, $actualPrices, $message); + } + + /** + * Unset category and product page expected prices. + * + * @param array $prices + * @return array + */ + protected function preparePrices($prices) + { + $deletePrices = [ + 'category_price_excl_tax', + 'category_price_incl_tax', + 'product_view_price_excl_tax', + 'product_view_price_incl_tax' + ]; + foreach ($deletePrices as $key) { + if (array_key_exists($key, $prices)) { + unset($prices[$key]); + } + } + + return $prices; + } + + /** + * Unset category and product page expected prices. + * + * @param array $prices + * @return array + */ + protected function preparePricesCreditMemo($prices) + { + $prices['shipping_excl_tax'] = null; + $prices['shipping_incl_tax'] = null; + return $prices; + } + + /** + * Get order product prices. + * + * @param InjectableFixture $product + * @param array $actualPrices + * @return array + */ + public function getOrderPrices($actualPrices, InjectableFixture $product) + { + $viewBlock = $this->orderView->getItemsOrderedBlock(); + $actualPrices['cart_item_price_excl_tax'] = $viewBlock->getItemPriceExclTax($product->getName()); + $actualPrices['cart_item_price_incl_tax'] = $viewBlock->getItemPriceInclTax($product->getName()); + $actualPrices['cart_item_subtotal_excl_tax'] = $viewBlock->getItemSubExclTax($product->getName()); + $actualPrices['cart_item_subtotal_incl_tax'] = $viewBlock->getItemSubInclTax($product->getName()); + return $actualPrices; + } + + /** + * Get invoice new product prices. + * + * @param InjectableFixture $product + * @param array $actualPrices + * @return array + */ + public function getInvoiceNewPrices($actualPrices, InjectableFixture $product) + { + $productBlock = $this->orderInvoiceNew->getFormBlock()->getItemsBlock()->getItemProductBlock($product); + $actualPrices['cart_item_price_excl_tax'] = $productBlock->getItemPriceExclTax(); + $actualPrices['cart_item_price_incl_tax'] = $productBlock->getItemPriceInclTax(); + $actualPrices['cart_item_subtotal_excl_tax'] = $productBlock->getItemSubExclTax(); + $actualPrices['cart_item_subtotal_incl_tax'] = $productBlock->getItemSubInclTax(); + return $actualPrices; + } + + /** + * Get Credit Memo new product prices. + * + * @param InjectableFixture $product + * @param array $actualPrices + * @return array + */ + public function getCreditMemoNewPrices($actualPrices, InjectableFixture $product) + { + $productBlock = $this->orderCreditMemoNew->getFormBlock()->getItemsBlock()->getItemProductBlock($product); + $actualPrices['cart_item_price_excl_tax'] = $productBlock->getItemPriceExclTax(); + $actualPrices['cart_item_price_incl_tax'] = $productBlock->getItemPriceInclTax(); + $actualPrices['cart_item_subtotal_excl_tax'] = $productBlock->getItemSubExclTax(); + $actualPrices['cart_item_subtotal_incl_tax'] = $productBlock->getItemSubInclTax(); + return $actualPrices; + } + + /** + * Text of price verification after order creation. + * + * @return string + */ + public function toString() + { + return 'Prices on backend after order creation is correct.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AbstractAssertTaxCalculationAfterCheckout.php b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AbstractAssertTaxCalculationAfterCheckout.php new file mode 100644 index 0000000000000..debc24c79bb65 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AbstractAssertTaxCalculationAfterCheckout.php @@ -0,0 +1,174 @@ +checkoutOnepage = $checkoutOnepage; + $this->orderView = $orderView; + + $checkoutCart->getProceedToCheckoutBlock()->proceedToCheckout(); + $checkoutOnepage->getBillingBlock()->clickContinue(); + $shippingMethod = ['shipping_service' => 'Flat Rate', 'shipping_method' => 'Fixed']; + $checkoutOnepage->getShippingMethodBlock()->selectShippingMethod($shippingMethod); + $checkoutOnepage->getShippingMethodBlock()->clickContinue(); + $checkoutOnepage->getPaymentMethodsBlock()->selectPaymentMethod(['method' => 'check_money_order']); + $checkoutOnepage->getPaymentMethodsBlock()->clickContinue(); + $actualPrices = []; + $actualPrices = $this->getReviewPrices($actualPrices, $product); + $actualPrices = $this->getReviewTotals($actualPrices); + $prices = $this->preparePrices($prices); + //Order review prices verification + $message = 'Prices on order review should be equal to defined in dataset.'; + \PHPUnit_Framework_Assert::assertEquals($prices, $actualPrices, $message); + + $checkoutOnepage->getReviewBlock()->placeOrder(); + $checkoutOnepageSuccess->getSuccessBlock()->getGuestOrderId(); + $checkoutOnepageSuccess->getSuccessBlock()->openOrder(); + $actualPrices = []; + $actualPrices = $this->getOrderPrices($actualPrices, $product); + $actualPrices = $this->getOrderTotals($actualPrices); + + //Frontend order prices verification + $message = 'Prices on order view page should be equal to defined in dataset.'; + \PHPUnit_Framework_Assert::assertEquals($prices, $actualPrices, $message); + } + + /** + * Prepare expected prices prices. + * + * @param array $prices + * @return array $prices + */ + protected function preparePrices($prices) + { + if (isset($prices['category_price_excl_tax'])) { + unset($prices['category_price_excl_tax']); + } + if (isset($prices['category_price_incl_tax'])) { + unset($prices['category_price_incl_tax']); + } + if (isset($prices['product_view_price_excl_tax'])) { + unset($prices['product_view_price_excl_tax']); + } + if (isset($prices['product_view_price_incl_tax'])) { + unset($prices['product_view_price_incl_tax']); + } + return $prices; + } + + /** + * Get review product prices. + * + * @param InjectableFixture $product + * @param $actualPrices + * @return array + */ + public function getReviewPrices($actualPrices, InjectableFixture $product) + { + $reviewBlock = $this->checkoutOnepage->getReviewBlock(); + $actualPrices['cart_item_price_excl_tax'] = $reviewBlock->getItemPriceExclTax($product->getName()); + $actualPrices['cart_item_price_incl_tax'] = $reviewBlock->getItemPriceInclTax($product->getName()); + $actualPrices['cart_item_subtotal_excl_tax'] = $reviewBlock->getItemSubExclTax($product->getName()); + $actualPrices['cart_item_subtotal_incl_tax'] = $reviewBlock->getItemSubInclTax($product->getName()); + return $actualPrices; + } + + /** + * Get order product prices. + * + * @param InjectableFixture $product + * @param $actualPrices + * @return array + */ + public function getOrderPrices($actualPrices, InjectableFixture $product) + { + $viewBlock = $this->orderView->getOrderViewBlock(); + $actualPrices['cart_item_price_excl_tax'] = $viewBlock->getItemPriceExclTax($product->getName()); + $actualPrices['cart_item_price_incl_tax'] = $viewBlock->getItemPriceInclTax($product->getName()); + $actualPrices['cart_item_subtotal_excl_tax'] = $viewBlock->getItemSubExclTax($product->getName()); + $actualPrices['cart_item_subtotal_incl_tax'] = $viewBlock->getItemSubInclTax($product->getName()); + return $actualPrices; + } + + /** + * Text of price verification after order creation + * + * @return string + */ + public function toString() + { + return 'Prices on front after order creation is correct.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRuleIsAppliedToAllPrices.php b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AbstractAssertTaxRuleIsAppliedToAllPrices.php similarity index 56% rename from dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRuleIsAppliedToAllPrices.php rename to dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AbstractAssertTaxRuleIsAppliedToAllPrices.php index 55704a8de1ebe..87787c1638f10 100644 --- a/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRuleIsAppliedToAllPrices.php +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AbstractAssertTaxRuleIsAppliedToAllPrices.php @@ -6,58 +6,86 @@ namespace Magento\Tax\Test\Constraint; -use Magento\Catalog\Test\Fixture\CatalogProductSimple; +use Mtf\Constraint\AbstractConstraint; +use Magento\Cms\Test\Page\CmsIndex; use Magento\Catalog\Test\Page\Category\CatalogCategoryView; use Magento\Catalog\Test\Page\Product\CatalogProductView; use Magento\Checkout\Test\Page\CheckoutCart; -use Magento\Cms\Test\Page\CmsIndex; use Magento\Customer\Test\Fixture\AddressInjectable; -use Mtf\Constraint\AbstractConstraint; use Mtf\Fixture\FixtureFactory; +use Mtf\Fixture\InjectableFixture; /** - * Class AssertTaxRuleIsAppliedToAllPrice - * Checks that prices on category, product and cart pages are equal to specified in dataset + * Checks that prices excl tax on category, product and cart pages are equal to specified in dataset. */ -class AssertTaxRuleIsAppliedToAllPrices extends AbstractConstraint +abstract class AbstractAssertTaxRuleIsAppliedToAllPrices extends AbstractConstraint { - /* tags */ - const SEVERITY = 'high'; - /* end tags */ - /** - * Cms index page + * Cms index page. * * @var CmsIndex */ protected $cmsIndex; /** - * Catalog product page + * Catalog product page. * * @var catalogCategoryView */ protected $catalogCategoryView; /** - * Catalog product page + * Catalog product page. * * @var CatalogProductView */ protected $catalogProductView; /** - * Catalog product page + * Catalog product page. * * @var CheckoutCart */ protected $checkoutCart; /** - * Assert that specified prices are actual on category, product and cart pages + * Constraint severeness. + * + * @var string + */ + protected $severeness = 'high'; + + /** + * Implementation for get category prices function + * + * @param string $productName + * @param array $actualPrices + * @return array + */ + abstract protected function getCategoryPrices($productName, $actualPrices); + + /** + * Implementation for get product page prices function + * + * @param array $actualPrices + * @return array + */ + abstract protected function getProductPagePrices($actualPrices); + + /** + * Implementation for get totals in cart function * - * @param CatalogProductSimple $product + * @param array $actualPrices + * @return array + */ + abstract protected function getTotals($actualPrices); + + /** + * Assert that specified prices are actual on category, product and cart pages. + * + * @param InjectableFixture $product * @param array $prices + * @param int $qty * @param CmsIndex $cmsIndex * @param CatalogCategoryView $catalogCategoryView * @param CatalogProductView $catalogProductView @@ -66,8 +94,9 @@ class AssertTaxRuleIsAppliedToAllPrices extends AbstractConstraint * @return void */ public function processAssert( - CatalogProductSimple $product, + InjectableFixture $product, array $prices, + $qty, CmsIndex $cmsIndex, CatalogCategoryView $catalogCategoryView, CatalogProductView $catalogProductView, @@ -81,98 +110,60 @@ public function processAssert( //Preconditions $address = $fixtureFactory->createByCode('addressInjectable', ['dataSet' => 'US_address_NY']); $shipping = ['carrier' => 'Flat Rate', 'method' => 'Fixed']; - + $actualPrices = []; //Assertion steps $productName = $product->getName(); - $this->openCategory($product); - $actualPrices = []; + $productCategory = $product->getCategoryIds()[0]; + $this->openCategory($productCategory); $actualPrices = $this->getCategoryPrices($productName, $actualPrices); $catalogCategoryView->getListProductBlock()->openProductViewPage($productName); + $catalogProductView->getViewBlock()->fillOptions($product); $actualPrices = $this->getProductPagePrices($actualPrices); - $catalogProductView->getViewBlock()->setQtyAndClickAddToCart(3); - $actualPrices = $this->getCartPrices($product, $actualPrices); + $catalogProductView->getViewBlock()->setQtyAndClickAddToCart($qty); $this->fillEstimateBlock($address, $shipping); + $actualPrices = $this->getCartPrices($product, $actualPrices); $actualPrices = $this->getTotals($actualPrices); - //Prices verification - \PHPUnit_Framework_Assert::assertEquals($prices, $actualPrices, 'Arrays should be equal'); + $message = 'Prices from dataset should be equal to prices on frontend.'; + \PHPUnit_Framework_Assert::assertEquals($prices, $actualPrices, $message); } /** - * Open product category + * Open product category. * - * @param CatalogProductSimple $product + * @param string $productCategory * @return void */ - public function openCategory(CatalogProductSimple $product) + public function openCategory($productCategory) { $this->cmsIndex->open(); - $this->cmsIndex->getTopmenu()->selectCategoryByName($product->getCategoryIds()[0]); - } - - /** - * Get prices on category page - * - * @param $productName - * @param array $actualPrices - * @return array - */ - public function getCategoryPrices($productName, $actualPrices) - { - $actualPrices['category_price_excl_tax'] = - $this->catalogCategoryView - ->getListProductBlock() - ->getProductPriceBlock($productName) - ->getPriceExcludingTax(); - $actualPrices['category_price_incl_tax'] = - $this->catalogCategoryView - ->getListProductBlock() - ->getProductPriceBlock($productName) - ->getPriceIncludingTax(); - return $actualPrices; + $this->cmsIndex->getTopmenu()->selectCategoryByName($productCategory); } - /** - * Get product view prices - * - * @param $actualPrices - * @return array - */ - public function getProductPagePrices($actualPrices) - { - $actualPrices['product_view_price_excl_tax'] = - $this->catalogProductView - ->getViewBlock() - ->getProductPriceExcludingTax(); - $actualPrices['product_view_price_incl_tax'] = - $this->catalogProductView - ->getViewBlock() - ->getProductPriceIncludingTax(); - return $actualPrices; - } /** - * Get cart prices + * Get cart prices. * - * @param CatalogProductSimple $product + * @param InjectableFixture $product * @param $actualPrices * @return array */ - public function getCartPrices(CatalogProductSimple $product, $actualPrices) + public function getCartPrices(InjectableFixture $product, $actualPrices) { - $actualPrices['cart_item_subtotal_excl_tax'] = - $this->checkoutCart->getCartBlock()->getCartItem($product)->getSubtotalPrice(); - $actualPrices['cart_item_subtotal_incl_tax'] = - $this->checkoutCart->getCartBlock()->getCartItem($product)->getSubtotalPriceInclTax(); $actualPrices['cart_item_price_excl_tax'] = $this->checkoutCart->getCartBlock()->getCartItem($product)->getPrice(); $actualPrices['cart_item_price_incl_tax'] = $this->checkoutCart->getCartBlock()->getCartItem($product)->getPriceInclTax(); + $actualPrices['cart_item_subtotal_excl_tax'] = + $this->checkoutCart->getCartBlock()->getCartItem($product)->getSubtotalPrice(); + $actualPrices['cart_item_subtotal_incl_tax'] = + $this->checkoutCart->getCartBlock()->getCartItem($product)->getSubtotalPriceInclTax(); + return $actualPrices; } /** - * Fill estimate block + * Fill estimate block. * * @param AddressInjectable $address * @param array $shipping @@ -184,27 +175,6 @@ public function fillEstimateBlock(AddressInjectable $address, $shipping) $this->checkoutCart->getShippingBlock()->selectShippingMethod($shipping); } - /** - * Get totals - * - * @param $actualPrices - * @return array - */ - public function getTotals($actualPrices) - { - $actualPrices['subtotal_excl_tax'] = $this->checkoutCart->getTotalsBlock()->getSubtotalExcludingTax(); - $actualPrices['subtotal_incl_tax'] = $this->checkoutCart->getTotalsBlock()->getSubtotalIncludingTax(); - $actualPrices['discount'] = $this->checkoutCart->getTotalsBlock()->getDiscount(); - $actualPrices['shipping_excl_tax'] = $this->checkoutCart->getTotalsBlock()->getShippingPrice(); - $actualPrices['shipping_incl_tax'] = $this->checkoutCart->getTotalsBlock()->getShippingPriceInclTax(); - $actualPrices['tax'] = $this->checkoutCart->getTotalsBlock()->getTax(); - $actualPrices['grand_total_excl_tax'] = - $this->checkoutCart->getTotalsBlock()->getGrandTotalExcludingTax(); - $actualPrices['grand_total_incl_tax'] = - $this->checkoutCart->getTotalsBlock()->getGrandTotalIncludingTax(); - return $actualPrices; - } - /** * Text of Tax Rule is applied * @@ -212,6 +182,6 @@ public function getTotals($actualPrices) */ public function toString() { - return 'Prices on front is correct'; + return 'Prices on front is correct.'; } } diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AbstractAssertTaxWithCrossBorderApplying.php b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AbstractAssertTaxWithCrossBorderApplying.php index 03aeedefc594d..d85f62a4574a1 100644 --- a/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AbstractAssertTaxWithCrossBorderApplying.php +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AbstractAssertTaxWithCrossBorderApplying.php @@ -167,7 +167,7 @@ protected function getCartPrice(CatalogProductSimple $product, $actualPrices) $actualPrices['cart_item_subtotal_incl_tax'] = $this->checkoutCart->getCartBlock()->getCartItem($product)->getSubtotalPriceInclTax(); $actualPrices['grand_total'] = - $this->checkoutCart->getTotalsBlock()->getGrandTotal(); + $this->checkoutCart->getTotalsBlock()->getGrandTotalIncludingTax(); return $actualPrices; } diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertOrderTaxOnBackendExcludingIncludingTax.php b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertOrderTaxOnBackendExcludingIncludingTax.php new file mode 100644 index 0000000000000..1851caffdb0c7 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertOrderTaxOnBackendExcludingIncludingTax.php @@ -0,0 +1,90 @@ +orderView->getOrderTotalsBlock(); + $actualPrices['subtotal_excl_tax'] = $viewBlock->getSubtotalExclTax(); + $actualPrices['subtotal_incl_tax'] = $viewBlock->getSubtotalInclTax(); + + $actualPrices['discount'] = $viewBlock->getDiscount(); + + $actualPrices['shipping_excl_tax'] = $viewBlock->getShippingExclTax(); + $actualPrices['shipping_incl_tax'] = $viewBlock->getShippingInclTax(); + $actualPrices['tax'] = $viewBlock->getTax(); + $actualPrices['grand_total_excl_tax'] = $viewBlock->getGrandTotalExclTax(); + $actualPrices['grand_total_incl_tax'] = $viewBlock->getGrandTotalInclTax(); + + return $actualPrices; + } + + /** + * Get invoice new totals. + * + * @param array $actualPrices + * @return array + */ + public function getInvoiceNewTotals($actualPrices) + { + $totalsBlock = $this->orderInvoiceNew->getTotalsBlock(); + $actualPrices['subtotal_excl_tax'] = $totalsBlock->getSubtotalExclTax(); + $actualPrices['subtotal_incl_tax'] = $totalsBlock->getSubtotalInclTax(); + + $actualPrices['discount'] = $totalsBlock->getDiscount(); + + $actualPrices['shipping_excl_tax'] = $totalsBlock->getShippingExclTax(); + $actualPrices['shipping_incl_tax'] = $totalsBlock->getShippingInclTax(); + $actualPrices['tax'] = $totalsBlock->getTax(); + + $actualPrices['grand_total_excl_tax'] = $totalsBlock->getGrandTotalExclTax(); + $actualPrices['grand_total_incl_tax'] = $totalsBlock->getGrandTotalInclTax(); + + return $actualPrices; + } + + /** + * Get Credit Memo new totals. + * + * @param array $actualPrices + * @return array + */ + public function getCreditMemoNewTotals($actualPrices) + { + $totalsBlock = $this->orderCreditMemoNew->getTotalsBlock(); + $actualPrices['subtotal_excl_tax'] = $totalsBlock->getSubtotalExclTax(); + $actualPrices['subtotal_incl_tax'] = $totalsBlock->getSubtotalInclTax(); + + $actualPrices['discount'] = $totalsBlock->getDiscount(); + + $actualPrices['shipping_excl_tax'] = $totalsBlock->getShippingExclTax(); + $actualPrices['shipping_incl_tax'] = $totalsBlock->getShippingInclTax(); + $actualPrices['tax'] = $totalsBlock->getTax(); + $actualPrices['grand_total_excl_tax'] = $totalsBlock->getGrandTotalExclTax(); + $actualPrices['grand_total_incl_tax'] = $totalsBlock->getGrandTotalInclTax(); + + return $actualPrices; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertOrderTaxOnBackendExcludingTax.php b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertOrderTaxOnBackendExcludingTax.php new file mode 100644 index 0000000000000..9b0c4846f2711 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertOrderTaxOnBackendExcludingTax.php @@ -0,0 +1,92 @@ +orderView->getOrderTotalsBlock(); + $actualPrices['subtotal_excl_tax'] = $viewBlock->getSubtotal(); + $actualPrices['subtotal_incl_tax'] = null; + + $actualPrices['discount'] = $viewBlock->getDiscount(); + + $actualPrices['shipping_excl_tax'] = $viewBlock->getShippingExclTax(); + $actualPrices['shipping_incl_tax'] = $viewBlock->getShippingInclTax(); + $actualPrices['tax'] = $viewBlock->getTax(); + + $actualPrices['grand_total_excl_tax'] = $viewBlock->getGrandTotal(); + $actualPrices['grand_total_incl_tax'] = null; + return $actualPrices; + } + + /** + * Get invoice new totals. + * + * @param $actualPrices + * @return array + */ + public function getInvoiceNewTotals($actualPrices) + { + $totalsBlock = $this->orderInvoiceNew->getTotalsBlock(); + $actualPrices['subtotal_excl_tax'] = $totalsBlock->getSubtotal(); + $actualPrices['subtotal_incl_tax'] = null; + + $actualPrices['discount'] = $totalsBlock->getDiscount(); + + $actualPrices['shipping_excl_tax'] = $totalsBlock->getShippingExclTax(); + $actualPrices['shipping_incl_tax'] = $totalsBlock->getShippingInclTax(); + $actualPrices['tax'] = $totalsBlock->getTax(); + + $actualPrices['grand_total_excl_tax'] = $totalsBlock->getGrandTotal(); + $actualPrices['grand_total_incl_tax'] = null; + + return $actualPrices; + } + + /** + * Get Credit Memo new totals. + * + * @param $actualPrices + * @return array + */ + public function getCreditMemoNewTotals($actualPrices) + { + $totalsBlock = $this->orderCreditMemoNew->getTotalsBlock(); + $actualPrices['subtotal_excl_tax'] = $totalsBlock->getSubtotal(); + $actualPrices['subtotal_incl_tax'] = null; + + $actualPrices['discount'] = $totalsBlock->getDiscount(); + + $actualPrices['shipping_excl_tax'] = $totalsBlock->getShippingExclTax(); + $actualPrices['shipping_incl_tax'] = $totalsBlock->getShippingInclTax(); + $actualPrices['tax'] = $totalsBlock->getTax(); + + $actualPrices['grand_total_excl_tax'] = $totalsBlock->getGrandTotal(); + $actualPrices['grand_total_incl_tax'] = null; + + return $actualPrices; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertOrderTaxOnBackendIncludingTax.php b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertOrderTaxOnBackendIncludingTax.php new file mode 100644 index 0000000000000..8843f04669a88 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertOrderTaxOnBackendIncludingTax.php @@ -0,0 +1,90 @@ +orderView->getOrderTotalsBlock(); + $actualPrices['subtotal_excl_tax'] = null; + $actualPrices['subtotal_incl_tax'] = $viewBlock->getSubtotal(); + + $actualPrices['discount'] = $viewBlock->getDiscount(); + + $actualPrices['shipping_excl_tax'] = $viewBlock->getShippingExclTax(); + $actualPrices['shipping_incl_tax'] = $viewBlock->getShippingInclTax(); + $actualPrices['tax'] = $viewBlock->getTax(); + $actualPrices['grand_total_excl_tax'] = $viewBlock->getGrandTotalExclTax(); + $actualPrices['grand_total_incl_tax'] = $viewBlock->getGrandTotalInclTax(); + + return $actualPrices; + } + + /** + * Get invoice new totals. + * + * @param $actualPrices + * @return array + */ + public function getInvoiceNewTotals($actualPrices) + { + $totalsBlock = $this->orderInvoiceNew->getTotalsBlock(); + $actualPrices['subtotal_excl_tax'] = null; + $actualPrices['subtotal_incl_tax'] = $totalsBlock->getSubtotal(); + + $actualPrices['discount'] = $totalsBlock->getDiscount(); + + $actualPrices['shipping_excl_tax'] = $totalsBlock->getShippingExclTax(); + $actualPrices['shipping_incl_tax'] = $totalsBlock->getShippingInclTax(); + $actualPrices['tax'] = $totalsBlock->getTax(); + + $actualPrices['grand_total_excl_tax'] = $totalsBlock->getGrandTotalExclTax(); + $actualPrices['grand_total_incl_tax'] = $totalsBlock->getGrandTotalInclTax(); + + return $actualPrices; + } + + /** + * Get Credit Memo new totals. + * + * @param $actualPrices + * @return array + */ + public function getCreditMemoNewTotals($actualPrices) + { + $totalsBlock = $this->orderCreditMemoNew->getTotalsBlock(); + $actualPrices['subtotal_excl_tax'] = null; + $actualPrices['subtotal_incl_tax'] = $totalsBlock->getSubtotal(); + + $actualPrices['discount'] = $totalsBlock->getDiscount(); + + $actualPrices['shipping_excl_tax'] = $totalsBlock->getShippingExclTax(); + $actualPrices['shipping_incl_tax'] = $totalsBlock->getShippingInclTax(); + $actualPrices['tax'] = $totalsBlock->getTax(); + $actualPrices['grand_total_excl_tax'] = $totalsBlock->getGrandTotalExclTax(); + $actualPrices['grand_total_incl_tax'] = $totalsBlock->getGrandTotalInclTax(); + + return $actualPrices; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxCalculationAfterCheckoutExcludingIncludingTax.php b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxCalculationAfterCheckoutExcludingIncludingTax.php new file mode 100644 index 0000000000000..7d65c80e0aee4 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxCalculationAfterCheckoutExcludingIncludingTax.php @@ -0,0 +1,63 @@ +checkoutOnepage->getReviewBlock(); + $actualPrices['subtotal_excl_tax'] = $reviewBlock->getSubtotalExclTax(); + $actualPrices['subtotal_incl_tax'] = $reviewBlock->getSubtotalInclTax(); + $actualPrices['discount'] = $reviewBlock->getDiscount(); + $actualPrices['shipping_excl_tax'] = $reviewBlock->getShippingExclTax(); + $actualPrices['shipping_incl_tax'] = $reviewBlock->getShippingInclTax(); + $actualPrices['tax'] = $reviewBlock->getTax(); + $actualPrices['grand_total_excl_tax'] = $reviewBlock->getGrandTotalExclTax(); + $actualPrices['grand_total_incl_tax'] = $reviewBlock->getGrandTotalInclTax(); + + return $actualPrices; + } + + /** + * Get order totals. + * + * @param $actualPrices + * @return array + */ + public function getOrderTotals($actualPrices) + { + $viewBlock = $this->orderView->getOrderViewBlock(); + $actualPrices['subtotal_excl_tax'] = $viewBlock->getSubtotalExclTax(); + $actualPrices['subtotal_incl_tax'] = $viewBlock->getSubtotalInclTax(); + $actualPrices['discount'] = $viewBlock->getDiscount(); + $actualPrices['shipping_excl_tax'] = $viewBlock->getShippingExclTax(); + $actualPrices['shipping_incl_tax'] = $viewBlock->getShippingInclTax(); + $actualPrices['tax'] = $viewBlock->getTax(); + $actualPrices['grand_total_excl_tax'] = $viewBlock->getGrandTotal(); + $actualPrices['grand_total_incl_tax'] = $viewBlock->getGrandTotalInclTax(); + + return $actualPrices; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxCalculationAfterCheckoutExcludingTax.php b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxCalculationAfterCheckoutExcludingTax.php new file mode 100644 index 0000000000000..eecf9cc8c8740 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxCalculationAfterCheckoutExcludingTax.php @@ -0,0 +1,62 @@ +checkoutOnepage->getReviewBlock(); + $actualPrices['subtotal_excl_tax'] = $reviewBlock->getSubtotal(); + $actualPrices['subtotal_incl_tax'] = null; + $actualPrices['discount'] = $reviewBlock->getDiscount(); + $actualPrices['shipping_excl_tax'] = $reviewBlock->getShippingExclTax(); + $actualPrices['shipping_incl_tax'] = $reviewBlock->getShippingInclTax(); + $actualPrices['tax'] = $reviewBlock->getTax(); + $actualPrices['grand_total_excl_tax'] = $reviewBlock->getGrandTotal(); + $actualPrices['grand_total_incl_tax'] = null; + + return $actualPrices; + } + + /** + * Get order totals. + * + * @param $actualPrices + * @return array + */ + public function getOrderTotals($actualPrices) + { + $viewBlock = $this->orderView->getOrderViewBlock(); + $actualPrices['subtotal_excl_tax'] = $viewBlock->getSubtotal(); + $actualPrices['subtotal_incl_tax'] = null; + + $actualPrices['discount'] = $viewBlock->getDiscount(); + $actualPrices['shipping_excl_tax'] = $viewBlock->getShippingExclTax(); + $actualPrices['shipping_incl_tax'] = $viewBlock->getShippingInclTax(); + $actualPrices['tax'] = $viewBlock->getTax(); + $actualPrices['grand_total_excl_tax'] = $viewBlock->getGrandTotal(); + $actualPrices['grand_total_incl_tax'] = null; + + return $actualPrices; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxCalculationAfterCheckoutIncludingTax.php b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxCalculationAfterCheckoutIncludingTax.php new file mode 100644 index 0000000000000..59869e99eaa92 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxCalculationAfterCheckoutIncludingTax.php @@ -0,0 +1,62 @@ +checkoutOnepage->getReviewBlock(); + $actualPrices['subtotal_excl_tax'] = null; + $actualPrices['subtotal_incl_tax'] = $reviewBlock->getSubtotal(); + $actualPrices['discount'] = $reviewBlock->getDiscount(); + $actualPrices['shipping_excl_tax'] = $reviewBlock->getShippingExclTax(); + $actualPrices['shipping_incl_tax'] = $reviewBlock->getShippingInclTax(); + $actualPrices['tax'] = $reviewBlock->getTax(); + $actualPrices['grand_total_excl_tax'] = $reviewBlock->getGrandTotalExclTax(); + $actualPrices['grand_total_incl_tax'] = $reviewBlock->getGrandTotalInclTax(); + + return $actualPrices; + } + + /** + * Get order totals. + * + * @param $actualPrices + * @return array + */ + public function getOrderTotals($actualPrices) + { + $viewBlock = $this->orderView->getOrderViewBlock(); + $actualPrices['subtotal_excl_tax'] = null; + $actualPrices['subtotal_incl_tax'] = $viewBlock->getSubtotal(); + $actualPrices['discount'] = $viewBlock->getDiscount(); + $actualPrices['shipping_excl_tax'] = $viewBlock->getShippingExclTax(); + $actualPrices['shipping_incl_tax'] = $viewBlock->getShippingInclTax(); + $actualPrices['tax'] = $viewBlock->getTax(); + $actualPrices['grand_total_excl_tax'] = $viewBlock->getGrandTotal(); + $actualPrices['grand_total_incl_tax'] = $viewBlock->getGrandTotalInclTax(); + + return $actualPrices; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRuleIsAppliedToAllPricesExcludingIncludingTax.php b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRuleIsAppliedToAllPricesExcludingIncludingTax.php new file mode 100644 index 0000000000000..b685b18e9608d --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRuleIsAppliedToAllPricesExcludingIncludingTax.php @@ -0,0 +1,75 @@ +catalogCategoryView->getListProductBlock()->getProductPriceBlock($productName); + $actualPrices['category_price_excl_tax'] = $priceBlock->getPriceExcludingTax(); + $actualPrices['category_price_incl_tax'] = $priceBlock->getPriceIncludingTax(); + + return $actualPrices; + } + + /** + * Get product view prices. + * + * @param array $actualPrices + * @return array + */ + public function getProductPagePrices($actualPrices) + { + $viewBlock = $this->catalogProductView->getViewBlock(); + $actualPrices['product_view_price_excl_tax'] = $viewBlock->getProductPriceExcludingTax(); + $actualPrices['product_view_price_incl_tax'] = $viewBlock->getProductPriceIncludingTax(); + + return $actualPrices; + } + + /** + * Get totals. + * + * @param $actualPrices + * @return array + */ + public function getTotals($actualPrices) + { + $totalsBlock = $this->checkoutCart->getTotalsBlock(); + $actualPrices['subtotal_excl_tax'] = $totalsBlock->getSubtotalExcludingTax(); + $actualPrices['subtotal_incl_tax'] = $totalsBlock->getSubtotalIncludingTax(); + $actualPrices['discount'] = $totalsBlock->getDiscount(); + $actualPrices['shipping_excl_tax'] = $totalsBlock->getShippingPrice(); + $actualPrices['shipping_incl_tax'] = $totalsBlock->getShippingPriceInclTax(); + $actualPrices['tax'] = $totalsBlock->getTax(); + $actualPrices['grand_total_excl_tax'] = $totalsBlock->getGrandTotalExcludingTax(); + $actualPrices['grand_total_incl_tax'] = $totalsBlock->getGrandTotalIncludingTax(); + + return $actualPrices; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRuleIsAppliedToAllPricesExcludingTax.php b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRuleIsAppliedToAllPricesExcludingTax.php new file mode 100644 index 0000000000000..8088fe6e3da3a --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRuleIsAppliedToAllPricesExcludingTax.php @@ -0,0 +1,74 @@ +catalogCategoryView->getListProductBlock()->getProductPriceBlock($productName); + $actualPrices['category_price_excl_tax'] = $priceBlock->getEffectivePrice(); + $actualPrices['category_price_incl_tax'] = null; + + return $actualPrices; + } + + /** + * Get product view prices. + * + * @param array $actualPrices + * @return array + */ + public function getProductPagePrices($actualPrices) + { + $viewBlock = $this->catalogProductView->getViewBlock(); + $actualPrices['product_view_price_excl_tax'] = $viewBlock->getPriceBlock()->getEffectivePrice(); + $actualPrices['product_view_price_incl_tax'] = null; + + return $actualPrices; + } + + /** + * Get totals. + * + * @param $actualPrices + * @return array + */ + public function getTotals($actualPrices) + { + $totalsBlock = $this->checkoutCart->getTotalsBlock(); + $actualPrices['subtotal_excl_tax'] = $totalsBlock->getSubtotal(); + $actualPrices['subtotal_incl_tax'] = null; + $actualPrices['discount'] = $totalsBlock->getDiscount(); + $actualPrices['shipping_excl_tax'] = $totalsBlock->getShippingPrice(); + $actualPrices['shipping_incl_tax'] = $totalsBlock->getShippingPriceInclTax(); + $actualPrices['tax'] = $totalsBlock->getTax(); + $actualPrices['grand_total_excl_tax'] = $totalsBlock->getGrandTotal(); + $actualPrices['grand_total_incl_tax'] = null; + + return $actualPrices; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRuleIsAppliedToAllPricesIncludingTax.php b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRuleIsAppliedToAllPricesIncludingTax.php new file mode 100644 index 0000000000000..9e7fbe7ef376f --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRuleIsAppliedToAllPricesIncludingTax.php @@ -0,0 +1,74 @@ +catalogCategoryView->getListProductBlock()->getProductPriceBlock($productName); + $actualPrices['category_price_excl_tax'] = null; + $actualPrices['category_price_incl_tax'] = $priceBlock->getEffectivePrice(); + + return $actualPrices; + } + + /** + * Get product view prices. + * + * @param array $actualPrices + * @return array + */ + public function getProductPagePrices($actualPrices) + { + $viewBlock = $this->catalogProductView->getViewBlock(); + $actualPrices['product_view_price_excl_tax'] = null; + $actualPrices['product_view_price_incl_tax'] = $viewBlock->getPriceBlock()->getEffectivePrice(); + + return $actualPrices; + } + + /** + * Get totals. + * + * @param $actualPrices + * @return array + */ + public function getTotals($actualPrices) + { + $totalsBlock = $this->checkoutCart->getTotalsBlock(); + $actualPrices['subtotal_excl_tax'] = null; + $actualPrices['subtotal_incl_tax'] = $totalsBlock->getSubtotal(); + $actualPrices['discount'] = $totalsBlock->getDiscount(); + $actualPrices['shipping_excl_tax'] = $totalsBlock->getShippingPrice(); + $actualPrices['shipping_incl_tax'] = $totalsBlock->getShippingPriceInclTax(); + $actualPrices['tax'] = $totalsBlock->getTax(); + $actualPrices['subtotal_excl_tax'] = $totalsBlock->getSubtotalExcludingTax(); + $actualPrices['subtotal_incl_tax'] = $totalsBlock->getSubtotalIncludingTax(); + + return $actualPrices; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/TestStep/CreateTaxRuleStep.php b/dev/tests/functional/tests/app/Magento/Tax/Test/TestStep/CreateTaxRuleStep.php new file mode 100644 index 0000000000000..e90c0be6bc439 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/TestStep/CreateTaxRuleStep.php @@ -0,0 +1,63 @@ +fixtureFactory = $fixtureFactory; + $this->taxRule = $taxRule; + } + + /** + * Create tax rule + * + * @return array + */ + public function run() + { + $result['taxRule'] = null; + if ($this->taxRule != '-') { + $taxRule = $this->fixtureFactory->createByCode( + 'taxRule', + ['dataSet' => $this->taxRule] + ); + $taxRule->persist(); + $result['taxRule'] = $taxRule; + } + + return $result; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/etc/constraint.xml b/dev/tests/functional/tests/app/Magento/Tax/Test/etc/constraint.xml index cdc24d17ed077..6776506ada7ba 100644 --- a/dev/tests/functional/tests/app/Magento/Tax/Test/etc/constraint.xml +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/etc/constraint.xml @@ -57,6 +57,33 @@ high + + high + + + high + + + high + + + high + + + high + + + high + + + high + + + high + + + high + high diff --git a/dev/tests/integration/testsuite/Magento/TaxImportExport/Model/Rate/CsvImportHandlerTest.php b/dev/tests/integration/testsuite/Magento/TaxImportExport/Model/Rate/CsvImportHandlerTest.php index de8fa89724500..465309edf1772 100644 --- a/dev/tests/integration/testsuite/Magento/TaxImportExport/Model/Rate/CsvImportHandlerTest.php +++ b/dev/tests/integration/testsuite/Magento/TaxImportExport/Model/Rate/CsvImportHandlerTest.php @@ -8,7 +8,7 @@ class CsvImportHandlerTest extends \PHPUnit_Framework_TestCase { /** - * @var \Magento\Tax\Model\Rate\CsvImportHandler + * @var \Magento\TaxImportExport\Model\Rate\CsvImportHandler */ protected $_importHandler; diff --git a/dev/tests/unit/testsuite/Magento/Catalog/Model/ProductTest.php b/dev/tests/unit/testsuite/Magento/Catalog/Model/ProductTest.php index 5706d834dfd2a..67628ef7ea3e5 100644 --- a/dev/tests/unit/testsuite/Magento/Catalog/Model/ProductTest.php +++ b/dev/tests/unit/testsuite/Magento/Catalog/Model/ProductTest.php @@ -424,10 +424,16 @@ public function testGetPriceInfo() */ public function testSetQty() { - $this->productTypeInstanceMock->expects($this->once()) + $this->productTypeInstanceMock->expects($this->exactly(2)) ->method('getPriceInfo') ->with($this->equalTo($this->model)) ->will($this->returnValue($this->_priceInfoMock)); + + //initialize the priceInfo field + $this->model->getPriceInfo(); + //Calling setQty will reset the priceInfo field + $this->assertEquals($this->model, $this->model->setQty(1)); + //Call the setQty method with the same qty, getPriceInfo should not be called this time $this->assertEquals($this->model, $this->model->setQty(1)); $this->assertEquals($this->model->getPriceInfo(), $this->_priceInfoMock); } diff --git a/dev/tests/unit/testsuite/Magento/Framework/Pricing/Price/CollectionTest.php b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Price/CollectionTest.php index 4b495ba6e0162..8c007c762bbfc 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Pricing/Price/CollectionTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Price/CollectionTest.php @@ -80,6 +80,8 @@ public function testGet() ) ->will($this->returnValue($this->priceMock)); $this->assertEquals($this->priceMock, $this->collection->get('regular_price')); + //Calling the get method again with the same code, cached copy should be used + $this->assertEquals($this->priceMock, $this->collection->get('regular_price')); } /** diff --git a/dev/tests/unit/testsuite/Magento/Tax/Helper/DataTest.php b/dev/tests/unit/testsuite/Magento/Tax/Helper/DataTest.php index 68c8fe6eb6b0e..6bc869feb9022 100644 --- a/dev/tests/unit/testsuite/Magento/Tax/Helper/DataTest.php +++ b/dev/tests/unit/testsuite/Magento/Tax/Helper/DataTest.php @@ -366,6 +366,74 @@ public function getCalculatedTaxesForOrderItemsDataProvider() ], ], ], + //Scenario 3: one item, with both shipping and product taxes + // note that 'shipping tax' is listed before 'product tax' + 'one_item_with_both_shipping_and_product_taxes' => [ + 'order' => [ + 'order_id' => 1, + 'shipping_tax_amount' => 2, + 'order_tax_details' => [ + 'items' => [ + 'shippingTax1' => [ + 'item_id' => null, + 'type' => 'shipping', + 'applied_taxes' => [ + [ + 'amount' => 2.0, + 'base_amount' => 2.0, + 'code' => 'US-CA-Ship', + 'title' => 'US-CA-Sales-Tax-Ship', + 'percent' => 10.0, + ], + ], + ], + 'itemTax1' => [ + 'item_id' => 1, + 'applied_taxes' => [ + [ + 'amount' => 5.0, + 'base_amount' => 5.0, + 'code' => 'US-CA', + 'title' => 'US-CA-Sales-Tax', + 'percent' => 20.0, + ], + ], + ], + ], + ], + ], + 'invoice' => [ + 'shipping_tax_amount' => 2, + 'invoice_items' => [ + 'item1' => new MagentoObject( + [ + 'order_item' => new MagentoObject( + [ + 'id' => 1, + 'tax_amount' => 5.00, + ] + ), + 'tax_amount' => 5.00, + ] + ), + ], + ], + // note that 'shipping tax' is now listed after 'product tax' + 'expected_results' => [ + [ + 'title' => 'US-CA-Sales-Tax', + 'percent' => 20.0, + 'tax_amount' => 5.00, + 'base_tax_amount' => 5.00, + ], + [ + 'title' => 'US-CA-Sales-Tax-Ship', + 'percent' => 10.0, + 'tax_amount' => 2.00, + 'base_tax_amount' => 2.00, + ], + ], + ], ]; return $data; diff --git a/dev/tests/unit/testsuite/Magento/Weee/Model/Total/Quote/WeeeTaxTest.php b/dev/tests/unit/testsuite/Magento/Weee/Model/Total/Quote/WeeeTaxTest.php index f42bcdd7808be..b1be049dd0c50 100644 --- a/dev/tests/unit/testsuite/Magento/Weee/Model/Total/Quote/WeeeTaxTest.php +++ b/dev/tests/unit/testsuite/Magento/Weee/Model/Total/Quote/WeeeTaxTest.php @@ -279,7 +279,7 @@ public function collectDataProvider() $data['price_incl_tax_weee_taxable_unit_included_in_subtotal'] = [ 'tax_config' => [ 'priceIncludesTax' => true, - 'getCalculationAgorithm' => Calculation::CALC_UNIT_BASE, + 'getCalculationAlgorithm' => Calculation::CALC_UNIT_BASE, ], 'weee_config' => [ 'isEnabled' => true, @@ -323,7 +323,7 @@ public function collectDataProvider() $data['price_incl_tax_weee_taxable_unit_not_included_in_subtotal'] = [ 'tax_config' => [ 'priceIncludesTax' => true, - 'getCalculationAgorithm' => Calculation::CALC_UNIT_BASE, + 'getCalculationAlgorithm' => Calculation::CALC_UNIT_BASE, ], 'weee_config' => [ 'isEnabled' => true, @@ -367,7 +367,7 @@ public function collectDataProvider() $data['price_excl_tax_weee_taxable_unit_included_in_subtotal'] = [ 'tax_config' => [ 'priceIncludesTax' => false, - 'getCalculationAgorithm' => Calculation::CALC_UNIT_BASE, + 'getCalculationAlgorithm' => Calculation::CALC_UNIT_BASE, ], 'weee_config' => [ 'isEnabled' => true, @@ -411,7 +411,7 @@ public function collectDataProvider() $data['price_incl_tax_weee_non_taxable_unit_included_in_subtotal'] = [ 'tax_config' => [ 'priceIncludesTax' => true, - 'getCalculationAgorithm' => Calculation::CALC_UNIT_BASE, + 'getCalculationAlgorithm' => Calculation::CALC_UNIT_BASE, ], 'weee_config' => [ 'isEnabled' => true, @@ -449,7 +449,7 @@ public function collectDataProvider() $data['price_excl_tax_weee_non_taxable_unit_include_in_subtotal'] = [ 'tax_config' => [ 'priceIncludesTax' => false, - 'getCalculationAgorithm' => Calculation::CALC_UNIT_BASE, + 'getCalculationAlgorithm' => Calculation::CALC_UNIT_BASE, ], 'weee_config' => [ 'isEnabled' => true, @@ -487,7 +487,7 @@ public function collectDataProvider() $data['price_incl_tax_weee_taxable_row_include_in_subtotal'] = [ 'tax_config' => [ 'priceIncludesTax' => true, - 'getCalculationAgorithm' => Calculation::CALC_ROW_BASE, + 'getCalculationAlgorithm' => Calculation::CALC_ROW_BASE, ], 'weee_config' => [ 'isEnabled' => true, @@ -531,7 +531,7 @@ public function collectDataProvider() $data['price_excl_tax_weee_taxable_row_include_in_subtotal'] = [ 'tax_config' => [ 'priceIncludesTax' => false, - 'getCalculationAgorithm' => Calculation::CALC_ROW_BASE, + 'getCalculationAlgorithm' => Calculation::CALC_ROW_BASE, ], 'weee_config' => [ 'isEnabled' => true, @@ -575,7 +575,7 @@ public function collectDataProvider() $data['price_incl_tax_weee_non_taxable_row_include_in_subtotal'] = [ 'tax_config' => [ 'priceIncludesTax' => true, - 'getCalculationAgorithm' => Calculation::CALC_ROW_BASE, + 'getCalculationAlgorithm' => Calculation::CALC_ROW_BASE, ], 'weee_config' => [ 'isEnabled' => true, @@ -613,7 +613,7 @@ public function collectDataProvider() $data['price_excl_tax_weee_non_taxable_row_not_included_in_subtotal'] = [ 'tax_config' => [ 'priceIncludesTax' => false, - 'getCalculationAgorithm' => Calculation::CALC_ROW_BASE, + 'getCalculationAlgorithm' => Calculation::CALC_ROW_BASE, ], 'weee_config' => [ 'isEnabled' => true, diff --git a/dev/tests/unit/testsuite/Magento/Weee/Model/Total/Quote/WeeeTest.php b/dev/tests/unit/testsuite/Magento/Weee/Model/Total/Quote/WeeeTest.php index a13403e3ad8c1..4ddcc5d6296da 100644 --- a/dev/tests/unit/testsuite/Magento/Weee/Model/Total/Quote/WeeeTest.php +++ b/dev/tests/unit/testsuite/Magento/Weee/Model/Total/Quote/WeeeTest.php @@ -221,7 +221,7 @@ public function collectDataProvider() $data['price_incl_tax_weee_taxable_unit_included_in_subtotal'] = [ 'tax_config' => [ 'priceIncludesTax' => true, - 'getCalculationAgorithm' => Calculation::CALC_UNIT_BASE, + 'getCalculationAlgorithm' => Calculation::CALC_UNIT_BASE, ], 'weee_config' => [ 'isEnabled' => true, @@ -261,7 +261,7 @@ public function collectDataProvider() $data['price_incl_tax_weee_taxable_unit_not_included_in_subtotal'] = [ 'tax_config' => [ 'priceIncludesTax' => true, - 'getCalculationAgorithm' => Calculation::CALC_UNIT_BASE, + 'getCalculationAlgorithm' => Calculation::CALC_UNIT_BASE, ], 'weee_config' => [ 'isEnabled' => true, @@ -301,7 +301,7 @@ public function collectDataProvider() $data['price_excl_tax_weee_taxable_unit_included_in_subtotal'] = [ 'tax_config' => [ 'priceIncludesTax' => false, - 'getCalculationAgorithm' => Calculation::CALC_UNIT_BASE, + 'getCalculationAlgorithm' => Calculation::CALC_UNIT_BASE, ], 'weee_config' => [ 'isEnabled' => true, @@ -341,7 +341,7 @@ public function collectDataProvider() $data['price_incl_tax_weee_non_taxable_unit_included_in_subtotal'] = [ 'tax_config' => [ 'priceIncludesTax' => true, - 'getCalculationAgorithm' => Calculation::CALC_UNIT_BASE, + 'getCalculationAlgorithm' => Calculation::CALC_UNIT_BASE, ], 'weee_config' => [ 'isEnabled' => true, @@ -383,7 +383,7 @@ public function collectDataProvider() $data['price_excl_tax_weee_non_taxable_unit_included_in_subtotal'] = [ 'tax_config' => [ 'priceIncludesTax' => false, - 'getCalculationAgorithm' => Calculation::CALC_UNIT_BASE, + 'getCalculationAlgorithm' => Calculation::CALC_UNIT_BASE, ], 'weee_config' => [ 'isEnabled' => true, @@ -425,7 +425,7 @@ public function collectDataProvider() $data['price_incl_tax_weee_taxable_row_included_in_subtotal'] = [ 'tax_config' => [ 'priceIncludesTax' => true, - 'getCalculationAgorithm' => Calculation::CALC_ROW_BASE, + 'getCalculationAlgorithm' => Calculation::CALC_ROW_BASE, ], 'weee_config' => [ 'isEnabled' => true, @@ -465,7 +465,7 @@ public function collectDataProvider() $data['price_excl_tax_weee_taxable_row_included_in_subtotal'] = [ 'tax_config' => [ 'priceIncludesTax' => false, - 'getCalculationAgorithm' => Calculation::CALC_ROW_BASE, + 'getCalculationAlgorithm' => Calculation::CALC_ROW_BASE, ], 'weee_config' => [ 'isEnabled' => true, @@ -505,7 +505,7 @@ public function collectDataProvider() $data['price_incl_tax_weee_non_taxable_row_included_in_subtotal'] = [ 'tax_config' => [ 'priceIncludesTax' => true, - 'getCalculationAgorithm' => Calculation::CALC_ROW_BASE, + 'getCalculationAlgorithm' => Calculation::CALC_ROW_BASE, ], 'weee_config' => [ 'isEnabled' => true, @@ -547,7 +547,7 @@ public function collectDataProvider() $data['price_excl_tax_weee_non_taxable_row_included_in_subtotal'] = [ 'tax_config' => [ 'priceIncludesTax' => false, - 'getCalculationAgorithm' => Calculation::CALC_ROW_BASE, + 'getCalculationAlgorithm' => Calculation::CALC_ROW_BASE, ], 'weee_config' => [ 'isEnabled' => true, @@ -589,7 +589,7 @@ public function collectDataProvider() $data['price_excl_tax_weee_non_taxable_row_not_included_in_subtotal'] = [ 'tax_config' => [ 'priceIncludesTax' => false, - 'getCalculationAgorithm' => Calculation::CALC_ROW_BASE, + 'getCalculationAlgorithm' => Calculation::CALC_ROW_BASE, ], 'weee_config' => [ 'isEnabled' => true, diff --git a/lib/internal/Magento/Framework/Pricing/Price/Collection.php b/lib/internal/Magento/Framework/Pricing/Price/Collection.php index e0d9fbe0cf894..d9bd5730df654 100644 --- a/lib/internal/Magento/Framework/Pricing/Price/Collection.php +++ b/lib/internal/Magento/Framework/Pricing/Price/Collection.php @@ -43,6 +43,13 @@ class Collection implements \Iterator */ protected $excludes; + /** + * Cached price models + * + * @var array + */ + protected $priceModels; + /** * Constructor * @@ -61,6 +68,7 @@ public function __construct( $this->priceFactory = $priceFactory; $this->pool = $pool; $this->quantity = $quantity; + $this->priceModels = []; } /** @@ -121,10 +129,13 @@ public function valid() */ public function get($code) { - return $this->priceFactory->create( - $this->saleableItem, - $this->pool[$code], - $this->quantity - ); + if (!isset($this->priceModels[$code])) { + $this->priceModels[$code] = $this->priceFactory->create( + $this->saleableItem, + $this->pool[$code], + $this->quantity + ); + } + return $this->priceModels[$code]; } } diff --git a/lib/internal/Magento/Framework/Pricing/PriceCurrencyInterface.php b/lib/internal/Magento/Framework/Pricing/PriceCurrencyInterface.php index aa86b245666d2..9a0c8b2925b02 100644 --- a/lib/internal/Magento/Framework/Pricing/PriceCurrencyInterface.php +++ b/lib/internal/Magento/Framework/Pricing/PriceCurrencyInterface.php @@ -30,12 +30,12 @@ public function convert($amount, $scope = null, $currency = null); * Convert and round price value * * @param float $amount - * @param null|string|bool|int|\Magento\Store\Model\Store $store - * @param \Magento\Directory\Model\Currency|string|null $currency + * @param null|string|bool|int|\Magento\Framework\App\ScopeInterface $scope + * @param \Magento\Framework\Model\AbstractModel|string|null $currency * @param int $precision * @return float */ - public function convertAndRound($amount, $store = null, $currency = null, $precision = self::DEFAULT_PRECISION); + public function convertAndRound($amount, $scope = null, $currency = null, $precision = self::DEFAULT_PRECISION); /** * Format price value