Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertCustomerInGrid.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\Customer\Test\Page\Adminhtml\CustomerIndex;
11 use Magento\Mtf\Constraint\AbstractConstraint;
12 
17 class AssertCustomerInGrid extends AbstractConstraint
18 {
19  /* tags */
20  const SEVERITY = 'middle';
21  /* end tags */
22 
31  public function processAssert(
32  Customer $customer,
33  CustomerIndex $pageCustomerIndex
34  ) {
35  $customerData = $customer->getData();
36  $name = (isset($customerData['prefix']) ? $customerData['prefix'] . ' ' : '')
37  . $customerData['firstname']
38  . (isset($customerData['middlename']) ? ' ' . $customerData['middlename'] : '')
39  . ' ' . $customerData['lastname']
40  . (isset($customerData['suffix']) ? ' ' . $customerData['suffix'] : '');
41  $filter = [
42  'name' => $name,
43  'email' => $customerData['email'],
44  ];
45  $errorMessage = 'Customer with '
46  . 'name \'' . $filter['name'] . '\', '
47  . 'email \'' . $filter['email'] . '\'';
48 
49  if ($customer->hasData('dob')) {
50  $filter['dob_from'] = $customer->getData('dob');
51  $filter['dob_to'] = $customer->getData('dob');
52  }
53 
54  $pageCustomerIndex->open();
55  $pageCustomerIndex->getCustomerGridBlock()->isRowVisible($filter);
56  if ($customer->hasData('dob')) {
57  unset($filter['dob_from']);
58  unset($filter['dob_to']);
59  $filter['dob'] = $this->prepareDob($customer->getData('dob'));
60  $errorMessage .= ', dob \'' . $filter['dob'] . '\' ';
61  }
62 
63  $errorMessage .= 'is absent in Customer grid.';
64 
65  \PHPUnit\Framework\Assert::assertTrue(
66  $pageCustomerIndex->getCustomerGridBlock()->isRowVisible($filter, false),
67  $errorMessage
68  );
69  }
70 
77  private function prepareDob($date)
78  {
79  return date('M d, Y', strtotime($date));
80  }
81 
87  public function toString()
88  {
89  return 'Customer is present in Customer grid.';
90  }
91 }
$customerData
$customer
Definition: customers.php:11
processAssert(Customer $customer, CustomerIndex $pageCustomerIndex)
if(!isset($_GET['name'])) $name
Definition: log.php:14