|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\Captcha\Observer; |
| 7 | + |
| 8 | +use Magento\Framework\App\Request\Http as HttpRequest; |
| 9 | +use Magento\Framework\Message\MessageInterface; |
| 10 | +use Magento\TestFramework\Request; |
| 11 | +use Magento\TestFramework\TestCase\AbstractController; |
| 12 | + |
| 13 | +/** |
| 14 | + * Test captcha observer behavior |
| 15 | + * |
| 16 | + * @magentoAppArea frontend |
| 17 | + */ |
| 18 | +class CaseCheckOnFrontendUnsuccessfulMessageWhenCaptchaFailedTest extends AbstractController |
| 19 | +{ |
| 20 | + /** |
| 21 | + * Test incorrect captcha on customer login page |
| 22 | + * |
| 23 | + * @magentoDbIsolation enabled |
| 24 | + * @magentoAppIsolation enabled |
| 25 | + * @magentoConfigFixture default_store customer/captcha/enable 1 |
| 26 | + * @magentoConfigFixture default_store customer/captcha/forms user_login |
| 27 | + * @magentoConfigFixture default_store customer/captcha/mode always |
| 28 | + */ |
| 29 | + public function testLoginCheckUnsuccessfulMessageWhenCaptchaFailed() |
| 30 | + { |
| 31 | + /** @var \Magento\Framework\Data\Form\FormKey $formKey */ |
| 32 | + $formKey = $this->_objectManager->get(\Magento\Framework\Data\Form\FormKey::class); |
| 33 | + $post = [ |
| 34 | + 'login' => [ |
| 35 | + 'username' => 'dummy@dummy.com', |
| 36 | + 'password' => 'dummy_password1', |
| 37 | + ], |
| 38 | + 'captcha' => ['user_login' => 'wrong_captcha'], |
| 39 | + 'form_key' => $formKey->getFormKey(), |
| 40 | + ]; |
| 41 | + |
| 42 | + $this->getRequest()->setMethod(Request::METHOD_POST); |
| 43 | + $this->getRequest()->setPostValue($post); |
| 44 | + |
| 45 | + $this->dispatch('customer/account/loginPost'); |
| 46 | + |
| 47 | + $this->assertRedirect($this->stringContains('customer/account/login')); |
| 48 | + $this->assertSessionMessages( |
| 49 | + $this->equalTo(['Incorrect CAPTCHA']), |
| 50 | + MessageInterface::TYPE_ERROR |
| 51 | + ); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Test incorrect captcha on customer forgot password page |
| 56 | + * |
| 57 | + * @codingStandardsIgnoreStart |
| 58 | + * @magentoConfigFixture current_store customer/password/limit_password_reset_requests_method 0 |
| 59 | + * @magentoConfigFixture default_store customer/captcha/enable 1 |
| 60 | + * @magentoConfigFixture default_store customer/captcha/forms user_forgotpassword |
| 61 | + * @magentoConfigFixture default_store customer/captcha/mode always |
| 62 | + */ |
| 63 | + public function testForgotPasswordCheckUnsuccessfulMessageWhenCaptchaFailed() |
| 64 | + { |
| 65 | + $email = 'dummy@dummy.com'; |
| 66 | + |
| 67 | + $this->getRequest()->setPostValue(['email' => $email]); |
| 68 | + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); |
| 69 | + |
| 70 | + $this->dispatch('customer/account/forgotPasswordPost'); |
| 71 | + |
| 72 | + $this->assertRedirect($this->stringContains('customer/account/forgotpassword')); |
| 73 | + $this->assertSessionMessages( |
| 74 | + $this->equalTo(['Incorrect CAPTCHA']), |
| 75 | + MessageInterface::TYPE_ERROR |
| 76 | + ); |
| 77 | + } |
| 78 | +} |
0 commit comments