Skip to content

Commit 1cb9476

Browse files
committed
Added integration test for checking customer login attempts captcha cleanup after account edit
1 parent 690b39f commit 1cb9476

File tree

4 files changed

+59
-8
lines changed

4 files changed

+59
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Captcha\Observer;
9+
10+
use Magento\Captcha\Model\ResourceModel\Log as CaptchaLog;
11+
use Magento\Captcha\Model\ResourceModel\LogFactory;
12+
use Magento\Framework\Event\ManagerInterface;
13+
use Magento\Framework\ObjectManagerInterface;
14+
15+
/**
16+
* Class ResetAttemptForFrontendAccountEditObserverTest
17+
*
18+
* Test for checking that the customer login attempts are removed after account details edit
19+
*/
20+
class ResetAttemptForFrontendAccountEditObserverTest extends \PHPUnit\Framework\TestCase
21+
{
22+
/**
23+
* @var ObjectManagerInterface
24+
*/
25+
private $objectManager;
26+
27+
public function setUp()
28+
{
29+
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
30+
}
31+
32+
/**
33+
* @magentoDataFixture Magento/Captcha/_files/failed_logins_frontend.php
34+
*/
35+
public function testAccountEditRemovesFailedAttempts()
36+
{
37+
$customerEmail = 'mageuser@dummy.com';
38+
$captchaLogFactory = $this->objectManager->get(LogFactory::class);
39+
$eventManager = $this->objectManager->get(ManagerInterface::class);
40+
41+
$eventManager->dispatch(
42+
'customer_account_edited',
43+
['email' => $customerEmail]
44+
);
45+
46+
/**
47+
* @var CaptchaLog $captchaLog
48+
*/
49+
$captchaLog = $captchaLogFactory->create();
50+
51+
self::assertEquals(0, $captchaLog->countAttemptsByUserLogin($customerEmail));
52+
}
53+
}

dev/tests/integration/testsuite/Magento/Captcha/Observer/ResetAttemptForFrontendObserverTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@
1515
use Magento\Framework\ObjectManagerInterface;
1616

1717
/**
18-
* Class ResetAttemptForBackendObserverTest
18+
* Class ResetAttemptForFrontendObserverTest
1919
*
2020
* Test for checking that the customer login attempts are removed after a successful login
2121
*/
2222
class ResetAttemptForFrontendObserverTest extends \PHPUnit\Framework\TestCase
2323
{
24-
const USER_EMAIL = 'mageuser@dummy.com';
2524
/**
2625
* @var ObjectManagerInterface
2726
*/
@@ -37,13 +36,14 @@ public function setUp()
3736
*/
3837
public function testSuccesfulLoginRemovesFailedAttempts()
3938
{
39+
$customerEmail = 'mageuser@dummy.com';
4040
$customerFactory = $this->objectManager->get(CustomerFactory::class);
4141
$captchaLogFactory = $this->objectManager->get(LogFactory::class);
4242
$eventManager = $this->objectManager->get(ManagerInterface::class);
4343

4444
/** @var Customer $customer */
4545
$customer = $customerFactory->create();
46-
$customer->setEmail(self::USER_EMAIL);
46+
$customer->setEmail($customerEmail);
4747

4848
$eventManager->dispatch(
4949
'customer_customer_authenticated',
@@ -55,6 +55,6 @@ public function testSuccesfulLoginRemovesFailedAttempts()
5555
*/
5656
$captchaLog = $captchaLogFactory->create();
5757

58-
self::assertEquals(0, $captchaLog->countAttemptsByUserLogin(self::USER_EMAIL));
58+
self::assertEquals(0, $captchaLog->countAttemptsByUserLogin($customerEmail));
5959
}
6060
}

dev/tests/integration/testsuite/Magento/Captcha/_files/failed_logins_frontend.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
use Magento\TestFramework\Helper\Bootstrap;
99
use Magento\Captcha\Model\ResourceModel\LogFactory;
1010
use Magento\Captcha\Model\ResourceModel\Log;
11-
use Magento\Captcha\Observer\ResetAttemptForFrontendObserverTest;
1211

1312
$objectManager = Bootstrap::getObjectManager();
1413
$logFactory = $objectManager->get(LogFactory::class);
1514

1615
/** @var Log $captchaLog */
1716
$captchaLog = $logFactory->create();
18-
$captchaLog->logAttempt(ResetAttemptForFrontendObserverTest::USER_EMAIL);
17+
$captchaLog->logAttempt('mageuser@dummy.com');

dev/tests/integration/testsuite/Magento/Captcha/_files/failed_logins_frontend_rollback.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
use Magento\TestFramework\Helper\Bootstrap;
99
use Magento\Captcha\Model\ResourceModel\LogFactory;
1010
use Magento\Captcha\Model\ResourceModel\Log;
11-
use Magento\Captcha\Observer\ResetAttemptForFrontendObserverTest;
1211

1312
$objectManager = Bootstrap::getObjectManager();
1413
$logFactory = $objectManager->get(LogFactory::class);
1514

1615
/** @var Log $captchaLog */
1716
$captchaLog = $logFactory->create();
18-
$captchaLog->deleteUserAttempts(ResetAttemptForFrontendObserverTest::USER_EMAIL);
17+
$captchaLog->deleteUserAttempts('mageuser@dummy.com');

0 commit comments

Comments
 (0)