/** * Create shipping for order on backend. * * @return array */ public function run() { $this->orderIndex->open(); $this->orderIndex->getSalesOrderGrid()->searchAndOpen(['id' => $this->order->getId()]); $this->salesOrderView->getPageActions()->ship(); if (!empty($this->data)) { $this->orderShipmentNew->getFormBlock()->fillData($this->data, $this->order->getEntityId()['products']); } $this->orderShipmentNew->getFormBlock()->submit(); return ['shipmentIds' => $this->getShipmentIds()]; }
/** * Create credit memo from order on backend. * * @return array */ public function run() { $this->orderIndex->open(); $this->orderIndex->getSalesOrderGrid()->searchAndOpen(['id' => $this->order->getId()]); $this->salesOrderView->getPageActions()->orderCreditMemo(); if (!empty($this->data)) { $this->orderCreditMemoNew->getFormBlock()->fillProductData($this->data, $this->order->getEntityId()['products']); $this->orderCreditMemoNew->getFormBlock()->updateQty(); $this->orderCreditMemoNew->getFormBlock()->fillFormData($this->data); } $this->orderCreditMemoNew->getFormBlock()->submit(); return ['creditMemoIds' => $this->getCreditMemoIds()]; }
/** * Assert order is not visible in customer account on frontend * * @param OrderInjectable $order * @param Customer $customer * @param CustomerAccountIndex $customerAccountIndex * @param OrderHistory $orderHistory * @param string $status * @return void */ public function processAssert(OrderInjectable $order, Customer $customer, CustomerAccountIndex $customerAccountIndex, OrderHistory $orderHistory, $status) { $filter = ['id' => $order->getId(), 'status' => $status]; $this->objectManager->create('Magento\\Customer\\Test\\TestStep\\LoginCustomerOnFrontendStep', ['customer' => $customer])->run(); $customerAccountIndex->getAccountMenuBlock()->openMenuItem('My Orders'); \PHPUnit_Framework_Assert::assertFalse($orderHistory->getOrderHistoryBlock()->isVisible() && $orderHistory->getOrderHistoryBlock()->isOrderVisible($filter), 'Order with following data \'' . implode(', ', $filter) . '\' is present in Orders block on frontend.'); }
/** * Create credit memo. * * @return array */ public function run() { $this->orderIndex->open(); $this->orderIndex->getSalesOrderGrid()->searchAndOpen(['id' => $this->order->getId()]); /** @var \Magento\Sales\Test\Block\Adminhtml\Order\View\Tab\Invoices\Grid $invoicesGrid */ $invoicesGrid = $this->salesOrderView->getOrderForm()->getTab('invoices')->getGridBlock(); $this->salesOrderView->getOrderForm()->openTab('invoices'); $invoicesGrid->viewInvoice(); $this->salesOrderView->getPageActions()->orderInvoiceCreditMemo(); if (!empty($this->refundData)) { $this->orderCreditMemoNew->getFormBlock()->fillProductData($this->refundData, $this->order->getEntityId()['products']); $this->orderCreditMemoNew->getFormBlock()->updateQty(); } $this->orderCreditMemoNew->getFormBlock()->submit(); return ['ids' => ['creditMemoIds' => $this->getCreditMemoIds()]]; }
/** * Change created order status and unassign custom order status if order was created. * * @return void */ public function tearDown() { if ($this->order->hasData('id')) { $this->orderIndex->open()->getSalesOrderGrid()->massaction([['id' => $this->order->getId()]], 'Cancel'); $filter = ['label' => $this->orderStatus->getLabel(), 'status' => $this->orderStatusInitial->getStatus()]; $this->orderStatusIndex->open()->getOrderStatusGrid()->searchAndUnassign($filter); } }
/** * Assert that order is present in Orders grid on frontend. * * @param OrderInjectable $order * @param Customer $customer * @param ObjectManager $objectManager * @param CustomerAccountIndex $customerAccountIndex * @param OrderHistory $orderHistory * @param string $status * @param string $orderId * @param string|null $statusToCheck * @return void */ public function processAssert(OrderInjectable $order, Customer $customer, ObjectManager $objectManager, CustomerAccountIndex $customerAccountIndex, OrderHistory $orderHistory, $status, $orderId = '', $statusToCheck = null) { $filter = ['id' => $order->hasData('id') ? $order->getId() : $orderId, 'status' => $statusToCheck === null ? $status : $statusToCheck]; $objectManager->create('Magento\\Customer\\Test\\TestStep\\LoginCustomerOnFrontendStep', ['customer' => $customer])->run(); $customerAccountIndex->getAccountMenuBlock()->openMenuItem('My Orders'); $errorMessage = implode(', ', $filter); \PHPUnit_Framework_Assert::assertTrue($orderHistory->getOrderHistoryBlock()->isOrderVisible($filter), 'Order with following data \'' . $errorMessage . '\' is absent in Orders block on frontend.'); }
/** * Change created order status and unassign custom order status if order was created. * * @return void */ public function tearDown() { if ($this->order->hasData('id')) { $this->orderIndex->open()->getSalesOrderGrid()->massaction([['id' => $this->order->getId()]], 'Cancel'); $filter = ['label' => $this->orderStatus->getLabel(), 'status' => $this->orderStatusInitial->getStatus()]; $this->orderStatusIndex->open()->getOrderStatusGrid()->searchAndUnassign($filter); $this->objectManager->create('Magento\\Config\\Test\\TestStep\\SetupConfigurationStep', ['configData' => 'checkmo_custom_new_order_status_rollback'])->run(); } }
/** * Assert that invoiced Grand Total amount is equal to placed order Grand total amount on invoice page (frontend) * * @param OrderHistory $orderHistory * @param OrderInjectable $order * @param CustomerOrderView $customerOrderView * @param InvoiceView $invoiceView * @param array $ids * @return void */ public function processAssert(OrderHistory $orderHistory, OrderInjectable $order, CustomerOrderView $customerOrderView, InvoiceView $invoiceView, array $ids) { $this->loginCustomerAndOpenOrderPage($order->getDataFieldConfig('customer_id')['source']->getCustomer()); $orderHistory->getOrderHistoryBlock()->openOrderById($order->getId()); $customerOrderView->getOrderViewBlock()->openLinkByName('Invoices'); foreach ($ids['invoiceIds'] as $key => $invoiceId) { \PHPUnit_Framework_Assert::assertEquals(number_format($order->getPrice()[$key]['grand_invoice_total'], 2), $invoiceView->getInvoiceBlock()->getItemBlock($invoiceId)->getGrandTotal()); } }
/** * Put created order on hold. * * @param OrderInjectable $order * @return array */ public function test(OrderInjectable $order) { // Preconditions $order->persist(); // Steps $this->orderIndex->open(); $this->orderIndex->getSalesOrderGrid()->searchAndOpen(['id' => $order->getId()]); $this->salesOrderView->getPageActions()->hold(); return ['customer' => $order->getDataFieldConfig('customer_id')['source']->getCustomer()]; }
/** * Assert that shipped items quantity in 'Total Quantity' is equal to data from fixture on My Account page * * @param OrderHistory $orderHistory * @param OrderInjectable $order * @param CustomerOrderView $customerOrderView * @param ShipmentView $shipmentView * @param array $ids * @return void */ public function processAssert(OrderHistory $orderHistory, OrderInjectable $order, CustomerOrderView $customerOrderView, ShipmentView $shipmentView, array $ids) { $totalQty = $order->getTotalQtyOrdered(); $this->loginCustomerAndOpenOrderPage($order->getDataFieldConfig('customer_id')['source']->getCustomer()); $orderHistory->getOrderHistoryBlock()->openOrderById($order->getId()); $customerOrderView->getOrderViewBlock()->openLinkByName('Order Shipments'); foreach ($ids['shipmentIds'] as $key => $shipmentIds) { \PHPUnit_Framework_Assert::assertEquals($totalQty[$key], $shipmentView->getShipmentBlock()->getItemShipmentBlock($shipmentIds)->getTotalQty()); } }
/** * Assert shipment with corresponding shipment/order ID is present in 'Shipments' with correct total qty field * * @param ShipmentIndex $shipmentIndex * @param OrderInjectable $order * @param array $ids * @return void */ public function processAssert(ShipmentIndex $shipmentIndex, OrderInjectable $order, array $ids) { $shipmentIndex->open(); $orderId = $order->getId(); $totalQty = $order->getTotalQtyOrdered(); foreach ($ids['shipmentIds'] as $key => $shipmentIds) { $filter = ['id' => $shipmentIds, 'order_id' => $orderId, 'total_qty_from' => $totalQty[$key], 'total_qty_to' => $totalQty[$key]]; \PHPUnit_Framework_Assert::assertTrue($shipmentIndex->getShipmentsGrid()->isRowVisible($filter), 'Shipment is absent in shipment grid on shipment index page.'); } }
/** * Process assert. * * @param OrderInjectable $order * @param array $ids * @param SalesShipmentView $salesShipmentView * @param array|null $data [optional] * @return void */ protected function assert(OrderInjectable $order, array $ids, SalesShipmentView $salesShipmentView, array $data = null) { $orderId = $order->getId(); $productsData = $this->prepareOrderProducts($order, $data['items_data']); foreach ($ids['shipmentIds'] as $shipmentId) { $filter = ['order_id' => $orderId, 'id' => $shipmentId]; $this->shipmentPage->getShipmentsGrid()->searchAndOpen($filter); $itemsData = $this->preparePageItems($salesShipmentView->getItemsBlock()->getData()); $error = $this->verifyData($productsData, $itemsData); \PHPUnit_Framework_Assert::assertEmpty($error, $error); } }
/** * Assert that shipment is present in the Shipments tab with correct shipped items quantity * * @param SalesOrderView $salesOrderView * @param OrderIndex $orderIndex * @param OrderInjectable $order * @param array $ids * @return void */ public function processAssert(SalesOrderView $salesOrderView, OrderIndex $orderIndex, OrderInjectable $order, array $ids) { $orderIndex->open(); $orderIndex->getSalesOrderGrid()->searchAndOpen(['id' => $order->getId()]); $salesOrderView->getOrderForm()->openTab('shipments'); $totalQty = $order->getTotalQtyOrdered(); $totalQty = is_array($totalQty) ? $totalQty : [$totalQty]; foreach ($ids['shipmentIds'] as $key => $shipmentId) { $filter = ['id' => $shipmentId, 'qty_from' => $totalQty[$key], 'qty_to' => $totalQty[$key]]; \PHPUnit_Framework_Assert::assertTrue($salesOrderView->getOrderForm()->getTabElement('shipments')->getGridBlock()->isRowVisible($filter), 'Shipment is absent on shipments tab.'); } }
/** * Assert that buttons from dataset are not present on page * * @param OrderIndex $orderIndex * @param SalesOrderView $salesOrderView * @param OrderInjectable $order * @param string $orderButtonsUnavailable * @return void */ public function processAssert(OrderIndex $orderIndex, SalesOrderView $salesOrderView, OrderInjectable $order, $orderButtonsUnavailable) { $orderIndex->open(); $orderIndex->getSalesOrderGrid()->searchAndOpen(['id' => $order->getId()]); $buttons = explode(',', $orderButtonsUnavailable); $matches = []; foreach ($buttons as $button) { if ($salesOrderView->getPageActions()->isActionButtonVisible(trim($button))) { $matches[] = $button; } } \PHPUnit_Framework_Assert::assertEmpty($matches, 'Buttons are present on order page.' . "\nLog:\n" . implode(";\n", $matches)); }
/** * Assert credit memo items on credit memo view page * * @param CreditMemoIndex $creditMemoIndex * @param SalesCreditMemoView $salesCreditMemoView * @param OrderInjectable $order * @param array $ids * @param array|null $data [optional] * @return void */ public function processAssert(CreditMemoIndex $creditMemoIndex, SalesCreditMemoView $salesCreditMemoView, OrderInjectable $order, array $ids, array $data = null) { $creditMemoIndex->open(); $orderId = $order->getId(); $productsData = $this->prepareOrderProducts($order, $data['items_data']); foreach ($ids['creditMemoIds'] as $creditMemoId) { $filter = ['order_id' => $orderId, 'id' => $creditMemoId]; $creditMemoIndex->getCreditMemoGrid()->searchAndOpen($filter); $itemsData = $this->preparePageItems($salesCreditMemoView->getItemsBlock()->getData()); $error = $this->verifyData($productsData, $itemsData); \PHPUnit_Framework_Assert::assertEmpty($error, $error); } }
/** * Assert that refund is present in the 'Refunds' grid with correct ID, order ID, refunded amount * * @param CreditMemoIndex $creditMemoIndex * @param OrderInjectable $order * @param array $ids * @return void */ public function processAssert(CreditMemoIndex $creditMemoIndex, OrderInjectable $order, array $ids) { $creditMemoIndex->open(); $amount = $order->getPrice(); $orderId = $order->getId(); foreach ($ids['creditMemoIds'] as $key => $creditMemoId) { $filter = ['id' => $creditMemoId, 'order_id' => $orderId, 'grand_total_from' => $amount[$key]['grand_creditmemo_total'], 'grand_total_to' => $amount[$key]['grand_creditmemo_total']]; $creditMemoIndex->getCreditMemoGrid()->search($filter); $filter['grand_total_from'] = number_format($amount[$key]['grand_creditmemo_total'], 2); $filter['grand_total_to'] = number_format($amount[$key]['grand_creditmemo_total'], 2); \PHPUnit_Framework_Assert::assertTrue($creditMemoIndex->getCreditMemoGrid()->isRowVisible($filter, false, false), "Credit memo '#{$creditMemoId}' is absent in credit memos grid on credit memo index page."); } }
/** * Assert that refund is present in the tab with ID and refunded amount(depending on full/partial refund). * * @param SalesOrderView $salesOrderView * @param OrderIndex $orderIndex * @param OrderInjectable $order * @param array $ids * @return void */ public function processAssert(SalesOrderView $salesOrderView, OrderIndex $orderIndex, OrderInjectable $order, array $ids) { $orderIndex->open(); $orderIndex->getSalesOrderGrid()->searchAndOpen(['id' => $order->getId()]); $salesOrderView->getOrderForm()->openTab('creditmemos'); /** @var Grid $grid */ $grid = $salesOrderView->getOrderForm()->getTab('creditmemos')->getGridBlock(); $amount = $order->getPrice(); foreach ($ids['creditMemoIds'] as $key => $creditMemoId) { $filter = ['id' => $creditMemoId, 'amount_from' => $amount[$key]['grand_creditmemo_total'], 'amount_to' => $amount[$key]['grand_creditmemo_total']]; \PHPUnit_Framework_Assert::assertTrue($grid->isRowVisible($filter, true, false), 'Credit memo is absent on credit memos tab.'); } }
/** * Assert invoice with corresponding order ID is present in the invoices grid with corresponding amount * * @param InvoiceIndex $invoiceIndex * @param OrderInjectable $order * @param array $ids * @return void */ public function processAssert(InvoiceIndex $invoiceIndex, OrderInjectable $order, array $ids) { $invoiceIndex->open(); $amount = $order->getPrice(); $orderId = $order->getId(); foreach ($ids['invoiceIds'] as $key => $invoiceId) { $filter = ['id' => $invoiceId, 'order_id' => $orderId, 'grand_total_from' => $amount[$key]['grand_invoice_total'], 'grand_total_to' => $amount[$key]['grand_invoice_total']]; $invoiceIndex->getInvoicesGrid()->search($filter); $filter['grand_total_from'] = number_format($amount[$key]['grand_invoice_total'], 2); $filter['grand_total_to'] = number_format($amount[$key]['grand_invoice_total'], 2); \PHPUnit_Framework_Assert::assertTrue($invoiceIndex->getInvoicesGrid()->isRowVisible($filter, false, false), 'Invoice is absent in invoices grid on invoice index page.'); } }
/** * Assert that invoice is present in the invoices tab of the order with corresponding amount(Grand Total) * * @param SalesOrderView $salesOrderView * @param OrderIndex $orderIndex * @param OrderInjectable $order * @param array $ids * @return void */ public function processAssert(SalesOrderView $salesOrderView, OrderIndex $orderIndex, OrderInjectable $order, array $ids) { $orderIndex->open(); $orderIndex->getSalesOrderGrid()->searchAndOpen(['id' => $order->getId()]); $salesOrderView->getOrderForm()->openTab('invoices'); /** @var Grid $grid */ $grid = $salesOrderView->getOrderForm()->getTabElement('invoices')->getGridBlock(); $amount = $order->getPrice(); foreach ($ids['invoiceIds'] as $key => $invoiceId) { $filter = ['id' => $invoiceId, 'amount_from' => $amount[$key]['grand_invoice_total'], 'amount_to' => $amount[$key]['grand_invoice_total']]; $grid->search($filter); $filter['amount_from'] = number_format($amount[$key]['grand_invoice_total'], 2); $filter['amount_to'] = number_format($amount[$key]['grand_invoice_total'], 2); \PHPUnit_Framework_Assert::assertTrue($grid->isRowVisible($filter, false, false), 'Invoice is absent on invoices tab.'); } }
/** * Create invoice (with shipment optionally) for order on backend. * * @return array */ public function run() { $this->orderIndex->open(); $this->orderIndex->getSalesOrderGrid()->searchAndOpen(['id' => $this->order->getId()]); $this->salesOrderView->getPageActions()->invoice(); if (!empty($this->data)) { $this->orderInvoiceNew->getFormBlock()->fillData($this->data, $this->order->getEntityId()['products']); $this->orderInvoiceNew->getFormBlock()->updateQty(); } $this->orderInvoiceNew->getFormBlock()->submit(); $invoiceIds = $this->getInvoiceIds(); if (!empty($this->data)) { $shipmentIds = $this->getShipmentIds(); } return ['invoiceIds' => $invoiceIds, 'shipmentIds' => isset($shipmentIds) ? $shipmentIds : null]; }
/** * On hold order on backend. * * @return void */ public function run() { $this->orderIndex->open(); $this->orderIndex->getSalesOrderGrid()->searchAndOpen(['id' => $this->order->getId()]); $this->salesOrderView->getPageActions()->hold(); }
/** * Sales coupon report * * @param OrderInjectable $order * @param array $viewsReport * @return void */ public function test(OrderInjectable $order, array $viewsReport) { // Precondition $order->persist(); $this->orderIndex->open(); $this->orderIndex->getSalesOrderGrid()->searchAndOpen(['id' => $order->getId()]); $this->salesOrderView->getPageActions()->invoice(); $this->orderInvoiceNew->getTotalsBlock()->submit(); $this->reportStatistic->open(); $this->reportStatistic->getGridBlock()->massaction([['report' => 'Coupons']], 'Refresh Statistics for the Last Day', true); // Steps $this->salesCouponReportView->open(); $ruleName = $order->getCouponCode()->getName(); if (isset($viewsReport['rules_list'])) { $viewsReport['rules_list'] = str_replace('%rule_name%', $ruleName, $viewsReport['rules_list']); } $this->salesCouponReportView->getFilterBlock()->viewsReport($viewsReport); $this->salesCouponReportView->getActionBlock()->showReport(); }
/** * Assert that 'Credit Memo' button is present on order's page * * @param SalesOrderView $salesOrderView * @param OrderIndex $orderIndex * @param OrderInjectable $order * @return void */ public function processAssert(SalesOrderView $salesOrderView, OrderIndex $orderIndex, OrderInjectable $order) { $orderIndex->open(); $orderIndex->getSalesOrderGrid()->searchAndOpen(['id' => $order->getId()]); \PHPUnit_Framework_Assert::assertTrue($salesOrderView->getPageActions()->isActionButtonVisible('CreditMemo'), 'Credit memo button is absent on order view page.'); }
/** * Automatic Apply Tax Based on VAT ID. * * @param ConfigData $vatConfig * @param OrderInjectable $order * @param TaxRule $taxRule * @param Cart $cart * @param string $configData * @param string $customerGroup * @return array */ public function test(ConfigData $vatConfig, OrderInjectable $order, TaxRule $taxRule, Cart $cart, $configData, $customerGroup) { // Preconditions $this->configData = $configData; $this->objectManager->create('Magento\\Config\\Test\\TestStep\\SetupConfigurationStep', ['configData' => $this->configData])->run(); $taxRule->persist(); // Prepare data $this->customer = $order->getDataFieldConfig('customer_id')['source']->getCustomer(); $address = $this->customer->getDataFieldConfig('address')['source']->getAddresses()[0]; $this->prepareVatConfig($vatConfig, $customerGroup); $poducts = $order->getEntityId()['products']; $cart = $this->fixtureFactory->createByCode('cart', ['data' => array_merge($cart->getData(), ['items' => ['products' => $poducts]])]); // Steps $order->persist(); $this->objectManager->create('Magento\\Customer\\Test\\TestStep\\LoginCustomerOnFrontendStep', ['customer' => $this->customer])->run(); $this->objectManager->create('Magento\\Checkout\\Test\\TestStep\\AddProductsToTheCartStep', $order->getEntityId())->run(); $this->checkoutCart->open(); $this->checkoutCart->getCartBlock()->waitCartContainerLoading(); $this->checkoutCart->getShippingBlock()->fillEstimateShippingAndTax($address); $this->checkoutCart->getCartBlock()->waitCartContainerLoading(); return ['customer' => $this->customer, 'address' => $address, 'orderId' => $order->getId(), 'cart' => $cart, 'products' => $poducts]; }
/** * Assert that status is correct on order page in backend (same with value of orderStatus variable) * * @param string $previousOrderStatus * @param OrderInjectable $order * @param OrderIndex $salesOrder * @param SalesOrderView $salesOrderView * @return void */ public function processAssert($previousOrderStatus, OrderInjectable $order, OrderIndex $salesOrder, SalesOrderView $salesOrderView) { $salesOrder->open(); $salesOrder->getSalesOrderGrid()->searchAndOpen(['id' => $order->getId()]); \PHPUnit_Framework_Assert::assertEquals($previousOrderStatus, $salesOrderView->getOrderForm()->getOrderInfoBlock()->getOrderStatus(), 'Order status is incorrect on order page in backend.'); }
/** * Process assert * * @param OrderInjectable $order * @param OrderIndex $orderIndex * @param string $status * @param string $orderId [optional] * @return void */ protected function assert(OrderInjectable $order, OrderIndex $orderIndex, $status, $orderId = '') { $filter = ['id' => $order->hasData('id') ? $order->getId() : $orderId, 'status' => $status]; $errorMessage = implode(', ', $filter); \PHPUnit_Framework_Assert::assertTrue($orderIndex->getSalesOrderGrid()->isRowVisible($filter), 'Order with following data \'' . $errorMessage . '\' is absent in Orders grid.'); }
/** * Create tax report entity. * * @param OrderInjectable $order * @param TaxRule $taxRule * @param array $report * @param string $orderSteps * @return void */ public function test(OrderInjectable $order, TaxRule $taxRule, array $report, $orderSteps) { // Precondition $taxRule->persist(); $this->taxRule = $taxRule; $order->persist(); $this->orderIndex->open(); $this->orderIndex->getSalesOrderGrid()->searchAndOpen(['id' => $order->getId()]); $this->processOrder($orderSteps, $order); $this->reportStatistic->open(); $this->reportStatistic->getGridBlock()->massaction([['report' => 'Tax']], 'Refresh Statistics for the Last Day', true); // Steps $this->salesTaxReport->open(); $this->salesTaxReport->getFilterBlock()->viewsReport($report); $this->salesTaxReport->getActionBlock()->showReport(); }
/** * Assert that 'Unhold' button present on order page * * @param OrderIndex $orderIndex * @param SalesOrderView $salesOrderView * @param OrderInjectable $order * @return void */ public function processAssert(OrderIndex $orderIndex, SalesOrderView $salesOrderView, OrderInjectable $order) { $orderIndex->open(); $orderIndex->getSalesOrderGrid()->searchAndOpen(['id' => $order->getId()]); \PHPUnit_Framework_Assert::assertTrue($salesOrderView->getPageActions()->isActionButtonVisible('Unhold'), 'Button "Unhold" is absent on order page.'); }