Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertProductInGrid.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Catalog\Test\Page\Adminhtml\CatalogProductIndex;
10 use Magento\Mtf\Constraint\AbstractConstraint;
11 use Magento\Mtf\Fixture\FixtureInterface;
12 
16 class AssertProductInGrid extends AbstractConstraint
17 {
23  protected $product;
24 
32  public function processAssert(FixtureInterface $product, CatalogProductIndex $productIndex)
33  {
34  $this->product = $product;
35  $productIndex->open();
36  $productIndex->getProductGrid()->resetFilter();
37  \PHPUnit\Framework\Assert::assertTrue(
38  $productIndex->getProductGrid()->isRowVisible($this->prepareFilter()),
39  'Product \'' . $this->product->getName() . '\' is absent in Products grid.'
40  );
41  }
42 
48  protected function prepareFilter()
49  {
50  $productStatus = ($this->product->getStatus() === null || $this->product->getStatus() === 'Yes')
51  ? 'Enabled'
52  : 'Disabled';
53  $filter = [
54  'type' => $this->getProductType(),
55  'sku' => $this->product->getSku(),
56  'status' => $productStatus,
57  ];
58  if ($this->product->hasData('attribute_set_id')) {
59  $filter['set_name'] = $this->product->getAttributeSetId();
60  }
61 
62  return $filter;
63  }
64 
70  protected function getProductType()
71  {
72  $config = $this->product->getDataConfig();
73 
74  return ucfirst($config['type_id']) . ' Product';
75  }
76 
82  public function toString()
83  {
84  return 'Product is present in products grid.';
85  }
86 }
processAssert(FixtureInterface $product, CatalogProductIndex $productIndex)