Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertCatalogPriceRuleInGrid.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\CatalogRule\Test\Fixture\CatalogRule;
10 use Magento\CatalogRule\Test\Page\Adminhtml\CatalogRuleIndex;
11 use Magento\Mtf\Constraint\AbstractConstraint;
12 
16 class AssertCatalogPriceRuleInGrid extends AbstractConstraint
17 {
22  protected $fieldsToFilter = ['name', 'is_active'];
23 
32  public function processAssert(
33  CatalogRule $catalogPriceRule,
34  CatalogRuleIndex $pageCatalogRuleIndex,
35  CatalogRule $catalogPriceRuleOriginal = null
36  ) {
37  $data = ($catalogPriceRuleOriginal === null)
38  ? $catalogPriceRule->getData()
39  : array_merge($catalogPriceRuleOriginal->getData(), $catalogPriceRule->getData());
40 
41  $filter = [];
42  foreach ($this->fieldsToFilter as $field) {
43  $filter[$field] = $data[$field];
44  }
45  //add ruleWebsite to filter if there is one
46  if ($catalogPriceRule->getWebsiteIds() != null) {
47  $ruleWebsite = $catalogPriceRule->getWebsiteIds();
48  $ruleWebsite = is_array($ruleWebsite) ? reset($ruleWebsite) : $ruleWebsite;
49  $filter['rule_website'] = $ruleWebsite;
50  }
51  //add from_date & to_date to filter if there are ones
52  if (isset($data['from_date']) && isset($data['to_date'])) {
53  $dateArray['from_date'] = date("M j, Y", strtotime($catalogPriceRule->getFromDate()));
54  $dateArray['to_date'] = date("M j, Y", strtotime($catalogPriceRule->getToDate()));
55  $filter = array_merge($filter, $dateArray);
56  }
57 
58  $pageCatalogRuleIndex->open();
59  $errorMessage = implode(', ', $filter);
60  \PHPUnit\Framework\Assert::assertTrue(
61  $pageCatalogRuleIndex->getCatalogRuleGrid()->isRowVisible($filter),
62  'Catalog Price Rule with following data: \'' . $errorMessage . '\' '
63  . 'is absent in Catalog Price Rule grid.'
64  );
65  }
66 
72  public function toString()
73  {
74  return 'Catalog Price Rule is present in Catalog Rule grid.';
75  }
76 }
processAssert(CatalogRule $catalogPriceRule, CatalogRuleIndex $pageCatalogRuleIndex, CatalogRule $catalogPriceRuleOriginal=null)