Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertProductInventoryMaxAllowedQty.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Catalog\Test\Page\Product\CatalogProductView;
10 use Magento\Checkout\Test\Page\CheckoutCart;
11 use Magento\Mtf\Client\BrowserInterface;
12 use Magento\Mtf\Constraint\AbstractConstraint;
13 use Magento\Mtf\Fixture\FixtureInterface;
14 
18 class AssertProductInventoryMaxAllowedQty extends AbstractConstraint
19 {
25  private $errorMessage = 'The most you may purchase is %s.';
26 
37  public function processAssert(
38  BrowserInterface $browser,
39  FixtureInterface $product,
40  CatalogProductView $catalogProductView,
41  CheckoutCart $checkoutCart,
42  $maxQty
43  ) {
44  // Ensure that shopping cart is empty
45  $checkoutCart->open()->getCartBlock()->clearShoppingCart();
46 
47  $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
48  $catalogProductView->getViewBlock()->waitLoader();
49  $catalogProductView->getViewBlock()->setQtyAndClickAddToCart($maxQty * 2);
50  \PHPUnit\Framework\Assert::assertEquals(
51  $catalogProductView->getMessagesBlock()->getErrorMessage(),
52  sprintf($this->errorMessage, $maxQty),
53  'The maximum purchase warning message is not appears.'
54  );
55 
56  $catalogProductView->getViewBlock()->setQtyAndClickAddToCart($maxQty);
57  \PHPUnit\Framework\Assert::assertTrue(
58  $catalogProductView->getMessagesBlock()->waitSuccessMessage(),
59  'Limiting max qty is not working correctly.'
60  );
61  }
62 
68  public function toString()
69  {
70  return 'Limiting max qty is working correctly.';
71  }
72 }
processAssert(BrowserInterface $browser, FixtureInterface $product, CatalogProductView $catalogProductView, CheckoutCart $checkoutCart, $maxQty)