Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RemoveProductsFromTheCartStep.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Mtf\Fixture\FixtureFactory;
10 use Magento\Mtf\TestStep\TestStepInterface;
11 use Magento\Checkout\Test\Page\CheckoutCart;
12 
16 class RemoveProductsFromTheCartStep implements TestStepInterface
17 {
23  private $products;
24 
30  private $cartPage;
31 
37  private $itemsToRemove;
38 
44  private $fixtureFactory;
45 
52  public function __construct(
53  CheckoutCart $cartPage,
54  FixtureFactory $fixtureFactory,
55  array $products,
56  $itemsToRemove = null
57  ) {
58  $this->cartPage = $cartPage;
59  $this->fixtureFactory = $fixtureFactory;
60  $this->products = $products;
61  $this->itemsToRemove = $itemsToRemove;
62  }
63 
69  public function run()
70  {
71  if ($this->itemsToRemove !== null) {
72  $this->cartPage->open();
73  $productsToRemove = array_slice($this->products, 1, $this->itemsToRemove);
74  foreach ($productsToRemove as $product) {
75  $this->cartPage->getCartBlock()->getCartItem($product)->removeItem();
76  }
77  $this->products = array_slice($this->products, $this->itemsToRemove + 1);
78  }
79  $cart['data']['items'] = ['products' => $this->products];
80 
81  return ['cart' => $this->fixtureFactory->createByCode('cart', $cart)];
82  }
83 }
__construct(CheckoutCart $cartPage, FixtureFactory $fixtureFactory, array $products, $itemsToRemove=null)