Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CustomerForm.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\Customer\Test\Fixture\Address;
11 use Magento\Mtf\Client\Locator;
12 use Magento\Mtf\Fixture\FixtureInterface;
13 use Magento\Mtf\Fixture\InjectableFixture;
14 
18 class CustomerForm extends FormTabs
19 {
25  protected $spinner = '#container [data-role="spinner"]';
26 
32  protected $activeFormTab = '#container [data-area-active="true"]';
33 
39  protected $fieldLabel = './/*[contains(@class, "admin__field")]/*[contains(@class,"label")]';
40 
46  protected $fieldWrapperControl = './/*[contains(@class, "admin__field")]/*[contains(@class,"control")]';
47 
53  protected $tabReadiness = '.admin__page-nav-item._active._loading';
54 
60  protected $information = './/th[contains(text(), "%s")]/following-sibling::td[1]';
61 
69  public function fillCustomer(FixtureInterface $customer, $address = null)
70  {
71  $this->waitForm();
72 
73  $isHasData = ($customer instanceof InjectableFixture) ? $customer->hasData() : true;
74  if ($isHasData) {
75  parent::fill($customer);
76  }
77  if (null !== $address) {
78  $this->openTab('addresses');
79  $this->getTab('addresses')->fillAddresses($address);
80  }
81 
82  return $this;
83  }
84 
93  public function updateCustomer(FixtureInterface $customer, $address = null, Address $addressToDelete = null)
94  {
95  $this->waitForm();
96 
97  $isHasData = ($customer instanceof InjectableFixture) ? $customer->hasData() : true;
98  if ($isHasData) {
99  parent::fill($customer);
100  }
101  if ($addressToDelete !== null) {
102  $this->openTab('addresses');
103  $this->getTab('addresses')->deleteCustomerAddress($addressToDelete);
104  }
105  if ($address !== null) {
106  $this->openTab('addresses');
107  $this->getTab('addresses')->updateAddresses($address);
108  }
109 
110  return $this;
111  }
112 
120  public function getDataCustomer(FixtureInterface $customer, $address = null)
121  {
122  $this->waitForm();
123 
124  $data = ['customer' => $customer->hasData() ? parent::getData($customer) : parent::getData()];
125  if (null !== $address) {
126  $this->openTab('addresses');
127  $data['addresses'] = $this->getTab('addresses')->getDataAddresses($address);
128  }
129 
130  return $data;
131  }
132 
138  protected function waitForm()
139  {
140  $this->waitForElementNotVisible($this->spinner);
141  }
142 
149  public function openTab($tabName)
150  {
151  parent::openTab($tabName);
152  $this->waitForElementNotVisible($this->tabReadiness);
153 
154  return $this;
155  }
156 
162  public function getJsErrors()
163  {
164  $tabs = ['account_information', 'addresses'];
165  $jsErrors = [];
166  foreach ($tabs as $tabName) {
167  $tab = $this->getTab($tabName);
168  $this->openTab($tabName);
169  $jsErrors = array_merge($jsErrors, $tab->getJsErrors());
170  }
171  return $jsErrors;
172  }
173 
181  {
182  return $this->_rootElement
183  ->find(sprintf($this->information, $title), Locator::SELECTOR_XPATH)
184  ->getText();
185  }
186 }
$title
Definition: default.phtml:14
$customer
Definition: customers.php:11
fillCustomer(FixtureInterface $customer, $address=null)
updateCustomer(FixtureInterface $customer, $address=null, Address $addressToDelete=null)
$address
Definition: customer.php:38
getDataCustomer(FixtureInterface $customer, $address=null)