Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CaptchaEditCustomerTest.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\Customer\Test\Page\CustomerAccountEdit;
11 use Magento\Mtf\Fixture\FixtureFactory;
12 use Magento\Mtf\TestCase\Injectable;
13 use Magento\Mtf\TestStep\TestStepFactory;
14 
33 class CaptchaEditCustomerTest extends Injectable
34 {
40  private $stepFactory;
41 
47  private $fixtureFactory;
48 
54  private $customerAccountEdit;
55 
61  private $configData;
62 
71  public function __inject(
72  TestStepFactory $stepFactory,
73  FixtureFactory $fixtureFactory,
74  CustomerAccountEdit $customerAccountEdit
75  ) {
76  $this->stepFactory = $stepFactory;
77  $this->fixtureFactory = $fixtureFactory;
78  $this->customerAccountEdit = $customerAccountEdit;
79  }
80 
91  public function test(
93  Customer $initCustomer,
94  $configData,
95  $captcha,
96  $attempts
97  ) {
98  $this->configData = $configData;
99 
100  // Preconditions
101  $customer->persist();
102  $this->stepFactory->create(
103  \Magento\Config\Test\TestStep\SetupConfigurationStep::class,
104  ['configData' => $this->configData]
105  )->run();
106  $this->stepFactory->create(
107  \Magento\Customer\Test\TestStep\LoginCustomerOnFrontendStep::class,
108  ['customer' => $customer]
109  )->run();
110 
111  // Steps
112  $this->customerAccountEdit->getAccountMenuBlock()->openMenuItem('Account Information');
113 
114  // Update email with incorrect password $attempts times.
115  $this->customerEdit($initCustomer, $attempts);
116 
117  // Update email with incorrect password and captcha $attempts + 1 times.
118  $data = $initCustomer->getData();
119  $data['captcha'] = $captcha;
120  $data['group_id'] = [];
121 
123  $initCustomer = $this->fixtureFactory->createByCode('customer', ['data' => $data]);
124  //Add + 1 to attempts to get over maximum attempts count.
125  $this->customerEdit($initCustomer, $attempts + 1);
126  }
127 
135  private function customerEdit(Customer $customer, $attempts)
136  {
137  $accountInfoForm = $this->customerAccountEdit->getAccountInfoForm();
138  for ($i = 0; $i < $attempts; $i++) {
139  $accountInfoForm->setChangeEmail(true);
140  $accountInfoForm->fill($customer);
141  $accountInfoForm->submit();
142  }
143  }
144 
150  public function tearDown()
151  {
152  $this->stepFactory->create(
153  \Magento\Config\Test\TestStep\SetupConfigurationStep::class,
154  ['configData' => $this->configData, 'rollback' => true]
155  )->run();
156  }
157 }
$customer
Definition: customers.php:11
$captcha
Definition: default.phtml:12
__inject(TestStepFactory $stepFactory, FixtureFactory $fixtureFactory, CustomerAccountEdit $customerAccountEdit)
$i
Definition: gallery.phtml:31