Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertCustomerDefaultAddresses.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Customer\Test\Fixture\Address;
10 use Magento\Customer\Test\Page\CustomerAccountIndex;
11 use Magento\Mtf\Constraint\AbstractConstraint;
12 
16 class AssertCustomerDefaultAddresses extends AbstractConstraint
17 {
25  public function processAssert(CustomerAccountIndex $customerAccountIndex, Address $address)
26  {
27  $customerAccountIndex->getAccountMenuBlock()->openMenuItem('My Account');
28  sleep(6);
29  $defaultBillingAddress = explode(
30  "\n",
31  $customerAccountIndex->getDashboardAddress()->getDefaultBillingAddressText()
32  );
33  $defaultShippingAddress = explode(
34  "\n",
35  $customerAccountIndex->getDashboardAddress()->getDefaultShippingAddressText()
36  );
37  $pattern = $this->makeAddressPattern($address);
38  $billingDataDiff = $this->verifyForm($pattern, $defaultBillingAddress);
39  $shippingDataDiff = $this->verifyForm($pattern, $defaultShippingAddress);
40  $dataDiff = array_merge($billingDataDiff, $shippingDataDiff);
41 
42  \PHPUnit\Framework\Assert::assertEmpty(
43  $dataDiff,
44  'Billing or shipping form was filled incorrectly.'
45  . "\nLog:\n" . implode(";\n", $dataDiff)
46  );
47  }
48 
54  public function toString()
55  {
56  return 'Default billing and shipping address form is correct.';
57  }
58 
66  protected function verifyForm(array $pattern, array $address)
67  {
68  $errorMessages = [];
69  foreach ($pattern as $value) {
70  if (!in_array($value, $address)) {
71  $errorMessages[] = "Data '$value' in fields is not found.";
72  }
73  }
74  return $errorMessages;
75  }
76 
83  protected function makeAddressPattern(Address $address)
84  {
85  $pattern = [];
86  $regionId = $address->getRegionId();
87  $region = $regionId ? $regionId : $address->getRegion();
88 
89  $pattern[] = $address->getFirstname() . " " . $address->getLastname();
90  $pattern[] = $address->getCompany();
91  $pattern[] = $address->getStreet();
92  $pattern[] = $address->getCity() . ", " . $region . ", " . $address->getPostcode();
93  $pattern[] = $address->getCountryId();
94  $pattern[] = "T: " . $address->getTelephone();
95  if ($address->hasData('fax')) {
96  $pattern[] = "F: " . $address->getFax();
97  }
98  return $pattern;
99  }
100 }
$pattern
Definition: website.php:22
$address
Definition: customer.php:38
$value
Definition: gender.phtml:16
processAssert(CustomerAccountIndex $customerAccountIndex, Address $address)