Skip to content

Commit a9255f5

Browse files
MTO-144: [Test] Captcha and lockout for Storefront login page
- Defects fixed
1 parent 1d16050 commit a9255f5

File tree

5 files changed

+36
-33
lines changed

5 files changed

+36
-33
lines changed

dev/tests/functional/tests/app/Magento/Captcha/Test/Fixture/Customer.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/fixture.xsd">
99
<fixture name="customer">
1010
<field name="captcha" is_required="0" />
11-
<field name="comment" is_required="0" />
1211
</fixture>
1312
</config>

dev/tests/functional/tests/app/Magento/Captcha/Test/TestCase/CaptchaAndLockoutCustomerTest.php

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Captcha\Test\TestCase;
88

99
use Magento\Customer\Test\Block\Form\Login;
10+
use Magento\Mtf\Fixture\FixtureInterface;
1011
use Magento\Mtf\TestCase\Injectable;
1112
use Magento\Mtf\TestStep\TestStepFactory;
1213
use Magento\Customer\Test\Fixture\Customer;
@@ -54,7 +55,7 @@ class CaptchaAndLockoutCustomerTest extends Injectable
5455
private $customerAccountLogin;
5556

5657
/**
57-
* Customer Edit page
58+
* CustomerIndexEdit page.
5859
*
5960
* @var CustomerIndexEdit
6061
*/
@@ -119,51 +120,58 @@ public function test(
119120
$correctData['group_id'] = [
120121
'customerGroup' => $customer->getDataFieldConfig('group_id')['source']->getCustomerGroup()
121122
];
122-
$incorrectData = $correctData;
123-
$incorrectData['password'] = $incorrectPassword;
124123

125-
$customer = $this->fixtureFactory->createByCode('customer', ['data' => $incorrectData]);
124+
$newData = $customer->getData();
125+
$newData['captcha'] = $captcha;
126+
$newData['group_id'] = [
127+
'customerGroup' => $customer->getDataFieldConfig('group_id')['source']->getCustomerGroup()
128+
];
129+
$newData['password'] = $incorrectPassword;
130+
131+
$incorrectCustomer = $this->fixtureFactory->createByCode('customer', ['data' => $newData]);
126132

127133
// Steps
128134
$this->customerAccountLogin->open();
129135

130-
// Fill incorrect password 3 or more times.
131-
$this->customerLogin($customer, $this->customerAccountLogin->getLoginBlock(), $attempts);
136+
// Fill incorrect password $attempts times.
137+
$this->customerLogin($incorrectCustomer,
138+
$this->customerAccountLogin->getLoginBlock(), $attempts);
132139

133-
// Fill correct captcha and incorrect password 3 or more times.
134-
$this->customerLogin($customer, $this->customerAccountLogin->getLoginBlockWithCaptcha(), $attempts);
140+
// Fill correct captcha and incorrect password $attempts times.
141+
$this->customerLogin($incorrectCustomer,
142+
$this->customerAccountLogin->getLoginBlockWithCaptcha(), $attempts);
135143

136144
// Log in customer with correct captcha and correct password.
137145
$customer = $this->fixtureFactory->createByCode('customer', ['data' => $correctData]);
138146
$this->customerLogin($customer, $this->customerAccountLogin->getLoginBlockWithCaptcha(), 1);
139147
}
140148

141-
/**
142-
* Set default configuration.
143-
*
144-
* @return void
145-
*/
146-
public function tearDown()
147-
{
148-
$this->stepFactory->create(
149-
\Magento\Config\Test\TestStep\SetupConfigurationStep::class,
150-
['configData' => $this->configData, 'rollback' => true]
151-
)->run();
152-
}
153-
154149
/**
155150
* Log in customer $attempts times.
156151
*
157-
* @param Customer $customer
152+
* @param FixtureInterface $customer
158153
* @param Login $loginForm
159154
* @param int $attempts
160155
* @return void
161156
*/
162-
private function customerLogin(Customer $customer, Login $loginForm, $attempts)
157+
private function customerLogin(FixtureInterface $customer, Login $loginForm, $attempts)
163158
{
164159
for ($i = 0; $i < $attempts; $i++) {
165160
$loginForm->fill($customer);
166161
$loginForm->submit();
167162
}
168163
}
164+
165+
/**
166+
* Set default configuration.
167+
*
168+
* @return void
169+
*/
170+
public function tearDown()
171+
{
172+
$this->stepFactory->create(
173+
\Magento\Config\Test\TestStep\SetupConfigurationStep::class,
174+
['configData' => $this->configData, 'rollback' => true]
175+
)->run();
176+
}
169177
}

dev/tests/functional/tests/app/Magento/Captcha/Test/TestCase/CaptchaAndLockoutCustomerTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<data name="attempts" xsi:type="number">3</data>
1414
<data name="captcha" xsi:type="string">111</data>
1515
<data name="configData" xsi:type="string">captcha_storefront_login_failures_number, customer_max_login_failures_number</data>
16-
<constraint name="Magento\Customer\Test\Constraint\AssertCustomerIsLockedOnBackend"/>
16+
<constraint name="Magento\Customer\Test\Constraint\AssertCustomerIsLockedOnBackend" />
1717
</variation>
1818
</testCase>
1919
</config>

dev/tests/functional/tests/app/Magento/Customer/Test/Block/Adminhtml/Edit/CustomerForm.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public function getJsErrors()
173173

174174

175175
/**
176-
* Return personal information.
176+
* Get personal information.
177177
*
178178
* @param string $title
179179
* @return string

dev/tests/functional/tests/app/Magento/Customer/Test/Constraint/AssertCustomerIsLockedOnBackend.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88

99
use Magento\Customer\Test\Fixture\Customer;
1010
use Magento\Customer\Test\Page\Adminhtml\CustomerIndexEdit;
11-
use Magento\Customer\Test\Page\Adminhtml\CustomerIndex;
1211
use Magento\Mtf\Constraint\AbstractConstraint;
1312

1413
/**
15-
* Class AssertCustomerIsLocked
14+
* Assert that customer account is locked on backend.
1615
*/
1716
class AssertCustomerIsLockedOnBackend extends AbstractConstraint
1817
{
@@ -25,17 +24,14 @@ class AssertCustomerIsLockedOnBackend extends AbstractConstraint
2524
* Assert customer account status on the backend.
2625
*
2726
* @param CustomerIndexEdit $customerIndexEdit
28-
* @param CustomerIndex $customerIndex
2927
* @param Customer $customer
3028
* @return void
3129
*/
3230
public function processAssert(
3331
CustomerIndexEdit $customerIndexEdit,
34-
CustomerIndex $customerIndex,
3532
Customer $customer
3633
) {
37-
$customerIndex->open();
38-
$customerIndex->getCustomerGridBlock()->searchAndOpen(['email' => $customer->getEmail()]);
34+
$customerIndexEdit->open(['id' => $customer->getId()]);
3935
\PHPUnit_Framework_Assert::assertEquals(
4036
self::CUSTOMER_LOCKED_ACCOUNT,
4137
$customerIndexEdit->getCustomerForm()->getPersonalInformation('Account Lock'),
@@ -44,7 +40,7 @@ public function processAssert(
4440
}
4541

4642
/**
47-
* Assert that displayed error message is correct.
43+
* Assert that displayed customer account status is correct.
4844
*
4945
* @return string
5046
*/

0 commit comments

Comments
 (0)