Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertCmsBlockInGrid.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\Cms\Test\Page\Adminhtml\CmsBlockIndex;
11 use Magento\Mtf\Constraint\AbstractConstraint;
12 
16 class AssertCmsBlockInGrid extends AbstractConstraint
17 {
28  public function processAssert(CmsBlock $cmsBlock, CmsBlockIndex $cmsBlockIndex)
29  {
30  $cmsBlockIndex->open();
31  $data = $cmsBlock->getData();
32  $data['is_active'] = $data['is_active'] == 'Yes' ? 'Enabled' : 'Disabled';
33  $filter = [
34  'title' => $data['title'],
35  'identifier' => $data['identifier'],
36  'is_active' => $data['is_active'],
37  ];
38 
39  if (isset($data['stores'])) {
40  $filter['store_id'] = is_array($data['stores']) ? reset($data['stores']) : $data['stores'];
41  }
42  // add creation_time & update_time to filter if there are ones
43  if (isset($data['creation_time'])) {
44  $filter['creation_time_from'] = date("M j, Y", strtotime($cmsBlock->getCreationTime()));
45  }
46  if (isset($data['update_time'])) {
47  $filter['update_time_from'] = date("M j, Y", strtotime($cmsBlock->getUpdateTime()));
48  }
49 
50  $cmsBlockIndex->getCmsBlockGrid()->search($filter);
51 
52  if (isset($filter['store_id'])) {
53  $pieces = explode('/', $filter['store_id']);
54  $filter['store_id'] = end($pieces);
55  }
56  \PHPUnit\Framework\Assert::assertTrue(
57  $cmsBlockIndex->getCmsBlockGrid()->isRowVisible($filter, false, false),
58  'CMS Block with '
59  . 'title \'' . $filter['title'] . '\', '
60  . 'identifier \'' . $filter['identifier'] . '\', '
61  . 'store view \'' . $filter['store_id'] . '\', '
62  . 'status \'' . $filter['is_active'] . '\', '
63  . (isset($filter['creation_time_from'])
64  ? ('creation_time \'' . $filter['creation_time_from'] . '\', ')
65  : '')
66  . (isset($filter['update_time_from']) ? ('update_time \'' . $filter['update_time_from'] . '\'') : '')
67  . 'is absent in CMS Block grid.'
68  );
69  }
70 
76  public function toString()
77  {
78  return 'CMS Block is present in grid.';
79  }
80 }
processAssert(CmsBlock $cmsBlock, CmsBlockIndex $cmsBlockIndex)