Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CreateOrderFromEditCustomerPageTest.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Customer\Test\Fixture\Address;
11 use Magento\Customer\Test\Page\Adminhtml\CustomerIndex;
12 use Magento\Customer\Test\Page\Adminhtml\CustomerIndexEdit;
13 use Magento\Mtf\TestCase\Injectable;
14 use Magento\Mtf\TestStep\TestStepFactory;
19 use Magento\Sales\Test\Page\Adminhtml\OrderCreateIndex;
20 use Magento\Sales\Test\Page\Adminhtml\SalesOrderView;
24 
61 class CreateOrderFromEditCustomerPageTest extends Injectable
62 {
68  private $configData;
69 
75  private $stepFactory;
76 
82  protected $customerIndex;
83 
89  protected $customerIndexEdit;
90 
96  protected $store;
97 
103  protected $orderCreateIndex;
104 
110  protected $salesOrderView;
111 
118 
125 
132 
139 
146 
153 
162  public function __prepare(
166  ) {
167  $this->assertItemsOrderedSectionOnBackendOrderIsEmpty = $assertItemsOrderedSectionOnBackendOrderIsEmpty;
168  $this->assertCartSectionWithProductsOnBackendOrderPage = $assertCartSectionWithProductsOnBackendOrderPage;
169  $this->assertProductsIsPresentInCustomerBackendWishlist = $assertProductsIsPresentInCustomerBackendWishlist;
170  }
171 
186  public function __inject(
187  TestStepFactory $stepFactory,
188  CustomerIndex $customerIndex,
189  CustomerIndexEdit $customerIndexEdit,
190  Store $store,
191  SalesOrderView $salesOrderView,
192  OrderCreateIndex $orderCreateIndex,
196  ) {
197  $this->stepFactory = $stepFactory;
198  $this->customerIndex = $customerIndex;
199  $this->customerIndexEdit = $customerIndexEdit;
200  $this->store = $store;
201  $this->salesOrderView = $salesOrderView;
202  $this->orderCreateIndex = $orderCreateIndex;
203  $this->assertItemsOrderedSectionContainsProducts = $assertItemsOrderedSectionContainsProducts;
204  $this->assertCustomerWishlistOnBackendIsEmpty = $assertCustomerWishlistOnBackendIsEmpty;
205  $this->assertCartSectionIsEmptyOnBackendOrderPage = $assertCartSectionIsEmptyOnBackendOrderPage;
206  }
207 
219  public function test(
220  Customer $customer,
221  array $payment,
223  $configData = null,
224  array $shipping = null,
225  array $products = []
226  ) {
227  // Preconditions:
228  $this->configData = $configData;
229  $this->stepFactory->create(
230  \Magento\Config\Test\TestStep\SetupConfigurationStep::class,
231  ['configData' => $this->configData]
232  )->run();
233  $customer->persist();
234  $products = $this->stepFactory->create(
235  \Magento\Catalog\Test\TestStep\CreateProductsStep::class,
236  ['products' => $products]
237  )->run()['products'];
238 
239  // Steps:
240  $this->customerIndex->open();
241  $this->customerIndex->getCustomerGridBlock()->searchAndOpen(['email' => $customer->getEmail()]);
242  $this->customerIndexEdit->getPageActionsBlock()->createOrder();
243  if ($this->orderCreateIndex->getStoreBlock()->isVisible()) {
244  $this->orderCreateIndex->getStoreBlock()->selectStoreView($this->store);
245  }
246  $this->stepFactory->create(
247  \Magento\Sales\Test\TestStep\AddProductsStep::class,
248  ['products' => $products]
249  )->run();
250  $createBlock = $this->orderCreateIndex->getCreateBlock();
251  $this->assertItemsOrderedSectionContainsProducts->processAssert($this->orderCreateIndex, $products);
252  $this->assertCustomerWishlistOnBackendIsEmpty->processAssert($this->orderCreateIndex);
253  $this->assertCartSectionIsEmptyOnBackendOrderPage->processAssert($this->orderCreateIndex);
254  foreach ([$products[0], $products[2]] as $product) {
255  $createBlock->getItemsBlock()->selectItemAction($product, 'Move to Wish List');
256  }
257  $createBlock->updateItems();
258  $this->assertItemsOrderedSectionContainsProducts->processAssert($this->orderCreateIndex, [$products[1]]);
259  $this->assertProductsIsPresentInCustomerBackendWishlist
260  ->processAssert($customer, $this->customerIndexEdit, [$products[0], $products[2]]);
261  $this->assertCartSectionIsEmptyOnBackendOrderPage->processAssert($this->orderCreateIndex);
262  $this->orderCreateIndex->getSidebarWishlistBlock()->selectItemToAddToOrder($products[0], 1);
263  $this->orderCreateIndex->getSidebarWishlistBlock()->selectItemToAddToOrder($products[2], 1);
264  $this->orderCreateIndex->getBackendOrderSidebarBlock()->updateChangesClick();
265  $createBlock->waitOrderItemsGrid();
266  $this->assertItemsOrderedSectionContainsProducts->processAssert($this->orderCreateIndex, $products);
267  $this->assertProductsIsPresentInCustomerBackendWishlist
268  ->processAssert($customer, $this->customerIndexEdit, [$products[0], $products[2]]);
269  $this->assertCartSectionIsEmptyOnBackendOrderPage->processAssert($this->orderCreateIndex);
270  foreach ($products as $product) {
271  $createBlock->getItemsBlock()->selectItemAction($product, 'Move to Shopping Cart');
272  }
273  $createBlock->updateItems();
274  $this->assertItemsOrderedSectionOnBackendOrderIsEmpty->processAssert($this->orderCreateIndex);
275  $this->assertProductsIsPresentInCustomerBackendWishlist
276  ->processAssert($customer, $this->customerIndexEdit, [$products[0], $products[2]]);
277  $this->assertCartSectionWithProductsOnBackendOrderPage->processAssert($this->orderCreateIndex, $products);
278  foreach ([$products[0], $products[2]] as $product) {
279  $this->orderCreateIndex->getBackendOrderSidebarBlock()->selectItemToAddToOrder($product);
280  }
281  $this->orderCreateIndex->getBackendOrderSidebarBlock()->updateChangesClick();
282  $createBlock->waitOrderItemsGrid();
283  $this->assertItemsOrderedSectionContainsProducts->processAssert(
284  $this->orderCreateIndex,
285  [$products[0], $products[2]]
286  );
287  $this->assertProductsIsPresentInCustomerBackendWishlist
288  ->processAssert($customer, $this->customerIndexEdit, [$products[0], $products[2]]);
289  $this->assertCartSectionWithProductsOnBackendOrderPage->processAssert($this->orderCreateIndex, [$products[1]]);
290  $this->stepFactory->create(
291  \Magento\Sales\Test\TestStep\FillBillingAddressStep::class,
292  [
293  'orderCreateIndex' => $this->orderCreateIndex,
294  'billingAddress' => $billingAddress,
295  'setShippingAddress' => true
296  ]
297  )->run();
298  $this->stepFactory->create(
299  \Magento\Sales\Test\TestStep\SelectPaymentMethodForOrderStep::class,
300  ['payment' => $payment]
301  )->run();
302  $this->stepFactory->create(
303  \Magento\Sales\Test\TestStep\SelectShippingMethodForOrderStep::class,
304  ['shipping' => $shipping]
305  )->run();
306  $createBlock->submitOrder();
307  $orderId = trim($this->salesOrderView->getTitleBlock()->getTitle(), '#');
308  return [
309  'orderId' => $orderId,
310  'customer' => $customer,
311  'productsInCart' => [
312  $products[1]
313  ]
314  ];
315  }
316 
322  public function tearDown()
323  {
324  $this->stepFactory->create(
325  \Magento\Config\Test\TestStep\SetupConfigurationStep::class,
326  ['configData' => $this->configData, 'rollback' => true]
327  )->run();
328  }
329 }
test(Customer $customer, array $payment, Address $billingAddress, $configData=null, array $shipping=null, array $products=[])
$billingAddress
Definition: order.php:25
$customer
Definition: customers.php:11
__inject(TestStepFactory $stepFactory, CustomerIndex $customerIndex, CustomerIndexEdit $customerIndexEdit, Store $store, SalesOrderView $salesOrderView, OrderCreateIndex $orderCreateIndex, AssertItemsOrderedSectionContainsProducts $assertItemsOrderedSectionContainsProducts, AssertCustomerWishlistOnBackendIsEmpty $assertCustomerWishlistOnBackendIsEmpty, AssertCartSectionIsEmptyOnBackendOrderPage $assertCartSectionIsEmptyOnBackendOrderPage)
$payment
Definition: order.php:17
__prepare(AssertItemsOrderedSectionOnBackendOrderIsEmpty $assertItemsOrderedSectionOnBackendOrderIsEmpty, AssertCartSectionWithProductsOnBackendOrderPage $assertCartSectionWithProductsOnBackendOrderPage, AssertProductsIsPresentInCustomerBackendWishlist $assertProductsIsPresentInCustomerBackendWishlist)