Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertProductInventoryMinAllowedQty.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 AssertProductInventoryMinAllowedQty extends AbstractConstraint
19 {
25  private $errorMessage = 'The fewest you may purchase is %s.';
26 
37  public function processAssert(
38  BrowserInterface $browser,
39  FixtureInterface $product,
40  CatalogProductView $catalogProductView,
41  CheckoutCart $checkoutCart,
42  $minQty
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(1);
50  \PHPUnit\Framework\Assert::assertEquals(
51  $catalogProductView->getMessagesBlock()->getErrorMessage(),
52  sprintf($this->errorMessage, $minQty),
53  'The minimum purchase warning message is not appears.'
54  );
55 
56  $catalogProductView->getViewBlock()->setQtyAndClickAddToCart($minQty);
57  \PHPUnit\Framework\Assert::assertTrue(
58  $catalogProductView->getMessagesBlock()->waitSuccessMessage(),
59  'Limiting min qty is not working correctly.'
60  );
61  }
62 
68  public function toString()
69  {
70  return 'Limiting min qty is working correctly.';
71  }
72 }
processAssert(BrowserInterface $browser, FixtureInterface $product, CatalogProductView $catalogProductView, CheckoutCart $checkoutCart, $minQty)