/** * 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.'); }
/** * Assert bestseller info in report: date, product name and qty. * * @param Bestsellers $bestsellers * @param OrderInjectable $order * @param string $date * @return void */ public function processAssert(Bestsellers $bestsellers, OrderInjectable $order, $date) { /** @var CatalogProductSimple $product */ $product = $order->getEntityId()['products'][0]; $filter = ['date' => date($date), 'product' => $product->getName(), 'price' => $product->getPrice(), 'orders' => $product->getCheckoutData()['qty']]; \PHPUnit_Framework_Assert::assertTrue($bestsellers->getGridBlock()->isRowVisible($filter, false), 'Bestseller does not present in report grid.'); }
/** * Create invoice. * * @param OrderInjectable $order * @param array $data * @return array */ public function test(OrderInjectable $order, array $data) { // Preconditions $order->persist(); // Steps $result = $this->objectManager->create('Magento\\Sales\\Test\\TestStep\\CreateInvoiceStep', ['order' => $order, 'data' => $data])->run(); return ['ids' => ['invoiceIds' => $result['invoiceIds'], 'shipmentIds' => isset($result['shipmentIds']) ? $result['shipmentIds'] : null]]; }
/** * Assert coupon info in report: code, rule name, subtotal, discount on coupons report page * * @param SalesCouponReportView $salesCouponReportView * @param OrderInjectable $order * @param string $currency * @return void */ public function processAssert(SalesCouponReportView $salesCouponReportView, OrderInjectable $order, $currency = '$') { $data = $order->getData(); $discount = $data['price']['discount'] != 0 ? '-' . $currency . number_format($data['price']['discount'], 2) : $currency . '0.00'; $couponCode = $data['coupon_code']->getCouponCode(); $filter = ['coupon_code' => $couponCode, 'rule_name' => $data['coupon_code']->getName(), 'subtotal' => $currency . number_format($data['price']['subtotal'], 2), 'discount' => $discount]; \PHPUnit_Framework_Assert::assertTrue($salesCouponReportView->getGridBlock()->isRowVisible($filter, false), "Coupon with code - '{$couponCode}' is not visible."); }
/** * 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.'); }
/** * Assert that order with fixture data in not more in the Orders grid * * @param OrderInjectable $order * @param OrderIndex $orderIndex * @return void */ public function processAssert(OrderInjectable $order, OrderIndex $orderIndex) { $data = $order->getData(); $filter = ['id' => $data['id']]; $orderIndex->open(); $errorMessage = implode(', ', $filter); \PHPUnit_Framework_Assert::assertFalse($orderIndex->getSalesOrderGrid()->isRowVisible($filter), 'Order with following data \'' . $errorMessage . '\' is present in Orders grid.'); }
/** * Prepare expected result * * @param array $expectedInvoiceData * @return array */ protected function prepareExpectedResult(array $expectedInvoiceData) { $totalInvoice = $this->order->getPrice()[0]['grand_invoice_total']; $expectedInvoiceData['invoiced'] += 1; $expectedInvoiceData['qty'] += 1; $expectedInvoiceData['total-invoiced'] += $totalInvoice; return $expectedInvoiceData; }
/** * Create invoice. * * @param OrderInjectable $order * @param array $data * @return array */ public function test(OrderInjectable $order, array $data) { // Preconditions $order->persist(); // Steps $result = $this->objectManager->create('Magento\\Sales\\Test\\TestStep\\CreateInvoiceStep', ['order' => $order, 'data' => $data])->run(); return $result; }
/** * Search order products report. * * @param OrderInjectable $order * @param array $customersReport * @return void */ public function test(OrderInjectable $order, array $customersReport) { // Preconditions $order->persist(); // Steps $this->orderedProducts->open(); $this->orderedProducts->getGridBlock()->searchAccounts($customersReport); }
/** * Create shipment. * * @param OrderInjectable $order * @param array $data * @return array */ public function test(OrderInjectable $order, array $data) { // Preconditions $order->persist(); // Steps $createShipping = $this->objectManager->create('Magento\\Sales\\Test\\TestStep\\CreateShipmentStep', ['order' => $order, 'data' => $data]); return ['ids' => $createShipping->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()); } }
/** * Get orders quantity from Ordered Products Report grid * * @param OrderInjectable $order * @return array */ public function getOrdersResults(OrderInjectable $order) { $products = $order->getEntityId()['products']; $views = []; foreach ($products as $key => $product) { $views[$key] = $this->_rootElement->find(sprintf($this->product, $product->getName()), Locator::SELECTOR_XPATH)->getText(); } return $views; }
/** * 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.'); } }
/** * Prepare order products * * @param OrderInjectable $order * @param array|null $data [optional] * @return array */ protected function prepareOrderProducts(OrderInjectable $order, array $data = null) { $products = $order->getEntityId()['products']; $productsData = []; /** @var CatalogProductSimple $product */ foreach ($products as $key => $product) { $productsData[] = ['product' => $product->getName(), 'sku' => $product->getSku(), 'qty' => isset($data[$key]['qty']) && $data[$key]['qty'] != '-' ? $data[$key]['qty'] : $product->getCheckoutData()['qty']]; } return $this->sortDataByPath($productsData, $this->sortKey); }
/** * Bestseller Products Report. * * @param OrderInjectable $order * @param array $bestsellerReport * @return void */ public function test(OrderInjectable $order, array $bestsellerReport) { // Preconditions $order->persist(); $this->bestsellers->open(); $this->bestsellers->getMessagesBlock()->clickLinkInMessages('notice', 'here'); // Steps $this->bestsellers->getFilterBlock()->viewsReport($bestsellerReport); $this->bestsellers->getActionsBlock()->showReport(); }
/** * Assert that ordered products in bestsellers on Dashboard successfully refreshed. * * @param OrderInjectable $order * @param Dashboard $dashboard * @return void */ public function processAssert(OrderInjectable $order, Dashboard $dashboard) { $dashboard->open(); $dashboard->getStoreStatsBlock()->refreshData(); /** @var \Magento\Backend\Test\Block\Dashboard\Tab\Products\Ordered $bestsellersGrid */ $bestsellersGrid = $dashboard->getStoreStatsBlock()->getTabElement('bestsellers')->getBestsellersGrid(); $products = $order->getEntityId()['products']; foreach ($products as $product) { \PHPUnit_Framework_Assert::assertTrue($bestsellersGrid->isProductVisible($product), 'Bestseller ' . $product->getName() . ' is not present in report grid after refresh data.'); } }
/** * 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()]; }
/** * Assert bestseller info in report: date, product name and qty * * @param Bestsellers $bestsellers * @param OrderInjectable $order * @param string $date * @return void * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function processAssert(Bestsellers $bestsellers, OrderInjectable $order, $date) { $products = $order->getEntityId()['products']; $totalQuantity = $bestsellers->getGridBlock()->getViewsResults($products, $date); $productQty = []; foreach ($products as $key => $product) { /** @var CatalogProductSimple $product*/ $productQty[$key] = $product->getCheckoutData()['qty']; } \PHPUnit_Framework_Assert::assertEquals($productQty, $totalQuantity); }
/** * 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 product info in report: product name, link title, sku, downloads number (Reports > Products > Downloads) * * @param OrderInjectable $order * @param DownloadsReport $downloadsReport * @param int $downloads * @return void */ public function processAssert(OrderInjectable $order, DownloadsReport $downloadsReport, $downloads) { $downloadsReport->open(); foreach ($order->getEntityId()['products'] as $product) { foreach ($product->getDownloadableLinks()['downloadable']['link'] as $link) { $filter = ['name' => $product->getName(), 'link_title' => $link['title'], 'sku' => $product->getSku()]; $downloadsReport->getGridBlock()->search($filter); $filter[] = $downloads; \PHPUnit_Framework_Assert::assertTrue($downloadsReport->getGridBlock()->isRowVisible($filter, false), "Downloads report link {$link['title']} is not present in reports grid."); } } }
/** * Assert product name and qty in Ordered Products report * * @param OrderedProductsReport $orderedProducts * @param OrderInjectable $order * @return void */ public function processAssert(OrderedProductsReport $orderedProducts, OrderInjectable $order) { $products = $order->getEntityId()['products']; $totalQuantity = $orderedProducts->getGridBlock()->getOrdersResults($order); $productQty = []; foreach ($totalQuantity as $key => $value) { /** @var CatalogProductSimple $product */ $product = $products[$key]; $productQty[$key] = $product->getCheckoutData()['qty']; } \PHPUnit_Framework_Assert::assertEquals($totalQuantity, $productQty); }
/** * 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.'); } }
/** * 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 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 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 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 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 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)); }