Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UpdateShoppingCartTest.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\Catalog\Test\Page\Product\CatalogProductView;
12 use Magento\Checkout\Test\Page\CheckoutCart;
13 use Magento\Mtf\Client\BrowserInterface;
14 use Magento\Mtf\Fixture\FixtureFactory;
15 use Magento\Mtf\TestCase\Injectable;
16 
32 class UpdateShoppingCartTest extends Injectable
33 {
34  /* tags */
35  const MVP = 'yes';
36  const SEVERITY = 'S0';
37  /* end tags */
38 
44  protected $browser;
45 
51  protected $fixtureFactory;
52 
59 
65  protected $checkoutCart;
66 
74  public function __prepare(BrowserInterface $browser, FixtureFactory $fixtureFactory)
75  {
76  $this->browser = $browser;
77  $this->fixtureFactory = $fixtureFactory;
78  }
79 
87  public function __inject(
88  CatalogProductView $catalogProductView,
90  ) {
91  $this->catalogProductView = $catalogProductView;
92  $this->checkoutCart = $checkoutCart;
93  }
94 
101  public function test(CatalogProductSimple $product)
102  {
103  // Preconditions
104  $product->persist();
105  $this->checkoutCart->open();
106  $this->checkoutCart->getCartBlock()->clearShoppingCart();
107 
108  // Steps
109  $this->browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
110  $productView = $this->catalogProductView->getViewBlock();
111  $productView->fillOptions($product);
112  $productView->setQty($product->getCheckoutData()['qty']);
113  $productView->clickAddToCart();
114  $this->catalogProductView->getMessagesBlock()->waitSuccessMessage();
115 
116  $qty = $product->getCheckoutData()['qty'];
117  $this->checkoutCart->open();
118  $this->checkoutCart->getCartBlock()->getCartItem($product)->setQty($qty);
119  $this->checkoutCart->getCartBlock()->updateShoppingCart();
120 
121  $cart['data']['items'] = ['products' => [$product]];
122  return ['cart' => $this->fixtureFactory->createByCode('cart', $cart)];
123  }
124 }
__inject(CatalogProductView $catalogProductView, CheckoutCart $checkoutCart)
__prepare(BrowserInterface $browser, FixtureFactory $fixtureFactory)