|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2015 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Magento\Reports\Test\Block\Adminhtml\Product\Sold; |
| 8 | + |
| 9 | +use Magento\Sales\Test\Fixture\OrderInjectable; |
| 10 | +use Magento\Mtf\Client\Locator; |
| 11 | +use Magento\Mtf\ObjectManager; |
| 12 | + |
| 13 | +/** |
| 14 | + * Class Grid |
| 15 | + * Ordered Products Report grid |
| 16 | + */ |
| 17 | +class Grid extends \Magento\Backend\Test\Block\Widget\Grid |
| 18 | +{ |
| 19 | + /** |
| 20 | + * Mapping for fields in Ordered Products Report Grid |
| 21 | + * |
| 22 | + * @var array |
| 23 | + */ |
| 24 | + protected $dataMapping = [ |
| 25 | + 'report_from' => 'datepicker', |
| 26 | + 'report_to' => 'datepicker', |
| 27 | + 'report_period' => 'select', |
| 28 | + ]; |
| 29 | + |
| 30 | + /** |
| 31 | + * Product in grid locator |
| 32 | + * |
| 33 | + * @var string |
| 34 | + */ |
| 35 | + protected $product = './/*[contains(.,"%s")]/*[contains(@class,"col-qty")]'; |
| 36 | + |
| 37 | + /** |
| 38 | + * Filter locator |
| 39 | + * |
| 40 | + * @var string |
| 41 | + */ |
| 42 | + protected $filter = '[name=%s]'; |
| 43 | + |
| 44 | + /** |
| 45 | + * Refresh button locator |
| 46 | + * |
| 47 | + * @var string |
| 48 | + */ |
| 49 | + protected $refreshButton = '[data-ui-id="adminhtml-report-grid-refresh-button"]'; |
| 50 | + |
| 51 | + /** |
| 52 | + * Search accounts in report grid |
| 53 | + * |
| 54 | + * @var array $customersReport |
| 55 | + * @return void |
| 56 | + */ |
| 57 | + public function searchAccounts(array $customersReport) |
| 58 | + { |
| 59 | + $customersReport = $this->prepareData($customersReport); |
| 60 | + foreach ($customersReport as $name => $value) { |
| 61 | + $this->_rootElement |
| 62 | + ->find(sprintf($this->filter, $name), Locator::SELECTOR_CSS, $this->dataMapping[$name]) |
| 63 | + ->setValue($value); |
| 64 | + } |
| 65 | + $this->_rootElement->find($this->refreshButton)->click(); |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * Prepare data |
| 70 | + * |
| 71 | + * @param array $customersReport |
| 72 | + * @return array |
| 73 | + */ |
| 74 | + protected function prepareData(array $customersReport) |
| 75 | + { |
| 76 | + foreach ($customersReport as $name => $reportFilter) { |
| 77 | + if ($name === 'report_period') { |
| 78 | + continue; |
| 79 | + } |
| 80 | + $date = ObjectManager::getInstance()->create( |
| 81 | + '\Magento\Backend\Test\Fixture\Source\Date', |
| 82 | + ['params' => [], 'data' => ['pattern' => $reportFilter]] |
| 83 | + ); |
| 84 | + $customersReport[$name] = $date->getData(); |
| 85 | + } |
| 86 | + return $customersReport; |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * Get orders quantity from Ordered Products Report grid |
| 91 | + * |
| 92 | + * @param OrderInjectable $order |
| 93 | + * @return array |
| 94 | + */ |
| 95 | + public function getOrdersResults(OrderInjectable $order) |
| 96 | + { |
| 97 | + $products = $order->getEntityId()['products']; |
| 98 | + $views = []; |
| 99 | + foreach ($products as $key => $product) { |
| 100 | + $views[$key] = $this->_rootElement |
| 101 | + ->find(sprintf($this->product, $product->getName()), Locator::SELECTOR_XPATH)->getText(); |
| 102 | + } |
| 103 | + return $views; |
| 104 | + } |
| 105 | +} |
0 commit comments