Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MassOrdersUpdateTest.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Mtf\Fixture\FixtureFactory;
10 use Magento\Mtf\TestCase\Injectable;
12 use Magento\Sales\Test\Page\Adminhtml\OrderIndex;
13 
28 class MassOrdersUpdateTest extends Injectable
29 {
30  /* tags */
31  const MVP = 'yes';
32  /* end tags */
33 
39  protected $orderIndex;
40 
46  protected $fixtureFactory;
47 
55  public function __inject(OrderIndex $orderIndex, FixtureFactory $fixtureFactory)
56  {
57  $this->orderIndex = $orderIndex;
58  $this->fixtureFactory = $fixtureFactory;
59  }
60 
70  public function test($steps, $ordersCount, $action, $resultStatuses)
71  {
72  // Preconditions
73  $orders = $this->createOrders($ordersCount, $steps);
74  $items = $this->prepareFilter($orders);
75 
76  // Steps
77  $this->orderIndex->open();
78  $this->orderIndex->getSalesOrderGrid()->massaction($items, $action);
79 
80  return ['orders' => $orders, 'orderStatuses' => explode(',', $resultStatuses)];
81  }
82 
90  protected function createOrders($count, $steps)
91  {
92  $orders = [];
93  $steps = explode('|', $steps);
94  for ($i = 0; $i < $count; $i++) {
96  $order = $this->fixtureFactory->createByCode('orderInjectable', ['dataset' => 'default']);
97  $order->persist();
98  $orders[$i] = $order;
99  $this->processSteps($order, $steps[$i]);
100  }
101 
102  return $orders;
103  }
104 
112  protected function processSteps(OrderInjectable $order, $steps)
113  {
114  $products = $order->getEntityId()['products'];
115  $cart['data']['items'] = ['products' => $products];
116  $cart = $this->fixtureFactory->createByCode('cart', $cart);
117  $steps = array_diff(explode(',', $steps), ['-']);
118  foreach ($steps as $step) {
119  $action = str_replace(' ', '', ucwords($step));
120  $methodAction = (($action != 'OnHold') ? 'Create' : '') . $action . 'Step';
121  $path = 'Magento\Sales\Test\TestStep';
122  $processStep = $this->objectManager->create(
123  $path . '\\' . $methodAction,
124  ['order' => $order, 'cart' => $cart]
125  );
126  $processStep->run();
127  }
128  }
129 
136  protected function prepareFilter(array $orders)
137  {
138  $items = [];
139  foreach ($orders as $order) {
140  $items[] = ['id' => $order->getId()];
141  }
142 
143  return $items;
144  }
145 }
__inject(OrderIndex $orderIndex, FixtureFactory $fixtureFactory)
$count
Definition: recent.phtml:13
$order
Definition: order.php:55
test($steps, $ordersCount, $action, $resultStatuses)
$i
Definition: gallery.phtml:31
$items