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\Mtf\Block\Form;
11 use Magento\Mtf\Client\Element\SimpleElement;
12 use Magento\Mtf\Client\Locator;
13 use Magento\Mtf\Fixture\FixtureInterface;
14 
18 class CustomerForm extends Form
19 {
25  protected $saveButton = '[type="submit"]';
26 
32  protected $customerAttribute = "[name='%s[]']";
33 
39  protected $validationText = '.mage-error[for="%s"]';
40 
48  protected function dataMapping(array $fields = null, $parent = null)
49  {
50  if (isset($fields['website_id'])) {
51  unset($fields['website_id']);
52  }
53  return parent::dataMapping($fields, $parent);
54  }
55 
61  public function submit()
62  {
63  $this->_rootElement->find($this->saveButton)->click();
64  }
65 
73  public function fill(FixtureInterface $customer, SimpleElement $element = null)
74  {
76  if ($customer->hasData()) {
77  parent::fill($customer, $element);
78  }
79  return $this;
80  }
81 
88  public function getValidationMessages(Customer $customer)
89  {
90  $messages = [];
91  foreach (array_keys($customer->getData()) as $field) {
92  $element = $this->_rootElement->find(sprintf($this->validationText, str_replace('_', '-', $field)));
93  if ($element->isVisible()) {
94  $messages[$field] = $element->getText();
95  }
96  }
97 
98  return $messages;
99  }
100 
106  public function getFirstName()
107  {
108  $mapping = $this->dataMapping();
109  return $this->_rootElement->find(
110  $mapping['customer']['value']['firstname']['selector']
111  )->getValue();
112  }
113 
119  public function getLastName()
120  {
121  $mapping = $this->dataMapping();
122  return $this->_rootElement->find(
123  $mapping['customer']['value']['lastname']['selector']
124  )->getValue();
125  }
126 
133  public function setChangeEmail($value)
134  {
135  $mapping = $this->dataMapping();
136  $this->_rootElement->find(
137  $mapping['change_email']['selector'],
138  $mapping['change_email']['strategy'],
139  'checkbox'
140  )->setValue($value ? "Yes" : "No");
141  }
142 
149  public function setChangePassword($value)
150  {
151  $mapping = $this->dataMapping();
152  $this->_rootElement->find(
153  $mapping['change_password']['selector'],
154  $mapping['change_password']['strategy'],
155  'checkbox'
156  )->setValue($value ? "Yes" : "No");
157  }
158 
164  public function isCurrentPasswordVisible()
165  {
166  $mapping = $this->dataMapping();
167  return $this->_rootElement->find(
168  $mapping['customer']['value']['current_password']['selector']
169  )->isVisible();
170  }
171 
177  public function isPasswordVisible()
178  {
179  $mapping = $this->dataMapping();
180  return $this->_rootElement->find(
181  $mapping['customer']['value']['password']['selector']
182  )->isVisible();
183  }
184 
190  public function isConfirmPasswordVisible()
191  {
192  $mapping = $this->dataMapping();
193  return $this->_rootElement->find(
194  $mapping['confirmation']['selector'],
195  $mapping['confirmation']['strategy']
196  )->isVisible();
197  }
198 
204  public function isEmailVisible()
205  {
206  $mapping = $this->dataMapping();
207  return $this->_rootElement->find(
208  $mapping['customer']['value']['email']['selector']
209  )->isVisible();
210  }
211 }
$customer
Definition: customers.php:11
$fields
Definition: details.phtml:14
dataMapping(array $fields=null, $parent=null)
$value
Definition: gender.phtml:16
$element
Definition: element.phtml:12