Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertAddToCartButtonAbsent.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\Catalog\Test\Page\Category\CatalogCategoryView;
11 use Magento\Catalog\Test\Page\Product\CatalogProductView;
12 use Magento\Cms\Test\Page\CmsIndex;
13 use Magento\Mtf\Constraint\AbstractConstraint;
14 use Magento\Mtf\Fixture\InjectableFixture;
15 
19 class AssertAddToCartButtonAbsent extends AbstractConstraint
20 {
32  public function processAssert(
33  InjectableFixture $product,
34  CmsIndex $cmsIndex,
35  CatalogCategoryView $catalogCategoryView,
36  CatalogProductView $catalogProductView,
37  Category $category = null
38  ) {
39  $cmsIndex->open();
40  $categoryName = $category === null ? $product->getCategoryIds()[0] : $category->getName();
41  $cmsIndex->getTopmenu()->selectCategoryByName($categoryName);
42 
43  $isProductVisible = $catalogCategoryView->getListProductBlock()->getProductItem($product)->isVisible();
44  while (!$isProductVisible && $catalogCategoryView->getBottomToolbar()->nextPage()) {
45  $isProductVisible = $catalogCategoryView->getListProductBlock()->getProductItem($product)->isVisible();
46  }
47  \PHPUnit\Framework\Assert::assertTrue($isProductVisible, 'Product is absent on category page.');
48 
49  \PHPUnit\Framework\Assert::assertFalse(
50  $catalogCategoryView->getListProductBlock()->getProductItem($product)->isVisibleAddToCardButton(),
51  "Button 'Add to Card' is present on Category page."
52  );
53 
54  $catalogCategoryView->getListProductBlock()->getProductItem($product)->open();
55  \PHPUnit\Framework\Assert::assertFalse(
56  $catalogProductView->getViewBlock()->isVisibleAddToCardButton(),
57  "Button 'Add to Card' is present on Product page."
58  );
59  }
60 
66  public function toString()
67  {
68  return "Button 'Add to Card' is absent on Category page and Product Page.";
69  }
70 }
processAssert(InjectableFixture $product, CmsIndex $cmsIndex, CatalogCategoryView $catalogCategoryView, CatalogProductView $catalogProductView, Category $category=null)