Skip to content

Commit 8c7398e

Browse files
ENGCOM-3580: [Backport] Adding integration tests for wrong captcha #19427
- Merge Pull Request #19427 from eduard13/magento2:2.2-develop-19183-bp - Merged commits: 1. 21cf0d5
2 parents 653d533 + 21cf0d5 commit 8c7398e

File tree

1 file changed

+118
-0
lines changed

1 file changed

+118
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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\Data\Form\FormKey;
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 FormKey $formKey */
32+
$formKey = $this->_objectManager->get(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->prepareRequestData($post);
43+
44+
$this->dispatch('customer/account/loginPost');
45+
46+
$this->assertRedirect($this->stringContains('customer/account/login'));
47+
$this->assertSessionMessages(
48+
$this->equalTo(['Incorrect CAPTCHA']),
49+
MessageInterface::TYPE_ERROR
50+
);
51+
}
52+
53+
/**
54+
* Test incorrect captcha on customer forgot password page
55+
*
56+
* @codingStandardsIgnoreStart
57+
* @magentoConfigFixture current_store customer/password/limit_password_reset_requests_method 0
58+
* @magentoConfigFixture default_store customer/captcha/enable 1
59+
* @magentoConfigFixture default_store customer/captcha/forms user_forgotpassword
60+
* @magentoConfigFixture default_store customer/captcha/mode always
61+
*/
62+
public function testForgotPasswordCheckUnsuccessfulMessageWhenCaptchaFailed()
63+
{
64+
$post = ['email' => 'dummy@dummy.com'];
65+
$this->prepareRequestData($post);
66+
67+
$this->dispatch('customer/account/forgotPasswordPost');
68+
69+
$this->assertRedirect($this->stringContains('customer/account/forgotpassword'));
70+
$this->assertSessionMessages(
71+
$this->equalTo(['Incorrect CAPTCHA']),
72+
MessageInterface::TYPE_ERROR
73+
);
74+
}
75+
76+
/**
77+
* Test incorrect captcha on customer create account page
78+
*
79+
* @codingStandardsIgnoreStart
80+
* @magentoConfigFixture current_store customer/password/limit_password_reset_requests_method 0
81+
* @magentoConfigFixture default_store customer/captcha/enable 1
82+
* @magentoConfigFixture default_store customer/captcha/forms user_create
83+
* @magentoConfigFixture default_store customer/captcha/mode always
84+
*/
85+
public function testCreateAccountCheckUnsuccessfulMessageWhenCaptchaFailed()
86+
{
87+
/** @var FormKey $formKey */
88+
$formKey = $this->_objectManager->get(FormKey::class);
89+
$post = [
90+
'firstname' => 'Firstname',
91+
'lastname' => 'Lastname',
92+
'email' => 'dummy@dummy.com',
93+
'password' => 'TestPassword123',
94+
'password_confirmation' => 'TestPassword123',
95+
'captcha' => ['user_create' => 'wrong_captcha'],
96+
'form_key' => $formKey->getFormKey(),
97+
];
98+
$this->prepareRequestData($post);
99+
100+
$this->dispatch('customer/account/createPost');
101+
102+
$this->assertRedirect($this->stringContains('customer/account/create'));
103+
$this->assertSessionMessages(
104+
$this->equalTo(['Incorrect CAPTCHA']),
105+
MessageInterface::TYPE_ERROR
106+
);
107+
}
108+
109+
/**
110+
* @param array $postData
111+
* @return void
112+
*/
113+
private function prepareRequestData($postData)
114+
{
115+
$this->getRequest()->setMethod(Request::METHOD_POST);
116+
$this->getRequest()->setPostValue($postData);
117+
}
118+
}

0 commit comments

Comments
 (0)