ResetAttemptForFrontendObserverTest.php 1.8 KB

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