5
5
*/
6
6
namespace Magento \Captcha \Observer ;
7
7
8
- use Magento \Framework \App \ Request \ Http as HttpRequest ;
8
+ use Magento \Framework \Data \ Form \ FormKey ;
9
9
use Magento \Framework \Message \MessageInterface ;
10
10
use Magento \TestFramework \Request ;
11
11
use Magento \TestFramework \TestCase \AbstractController ;
@@ -28,8 +28,8 @@ class CaseCheckOnFrontendUnsuccessfulMessageWhenCaptchaFailedTest extends Abstra
28
28
*/
29
29
public function testLoginCheckUnsuccessfulMessageWhenCaptchaFailed ()
30
30
{
31
- /** @var \Magento\Framework\Data\Form\ FormKey $formKey */
32
- $ formKey = $ this ->_objectManager ->get (\ Magento \ Framework \ Data \ Form \ FormKey::class);
31
+ /** @var FormKey $formKey */
32
+ $ formKey = $ this ->_objectManager ->get (FormKey::class);
33
33
$ post = [
34
34
'login ' => [
35
35
'username ' => 'dummy@dummy.com ' ,
@@ -39,8 +39,7 @@ public function testLoginCheckUnsuccessfulMessageWhenCaptchaFailed()
39
39
'form_key ' => $ formKey ->getFormKey (),
40
40
];
41
41
42
- $ this ->getRequest ()->setMethod (Request::METHOD_POST );
43
- $ this ->getRequest ()->setPostValue ($ post );
42
+ $ this ->prepareRequestData ($ post );
44
43
45
44
$ this ->dispatch ('customer/account/loginPost ' );
46
45
@@ -62,10 +61,8 @@ public function testLoginCheckUnsuccessfulMessageWhenCaptchaFailed()
62
61
*/
63
62
public function testForgotPasswordCheckUnsuccessfulMessageWhenCaptchaFailed ()
64
63
{
65
- $ email = 'dummy@dummy.com ' ;
66
-
67
- $ this ->getRequest ()->setPostValue (['email ' => $ email ]);
68
- $ this ->getRequest ()->setMethod (HttpRequest::METHOD_POST );
64
+ $ post = ['email ' => 'dummy@dummy.com ' ];
65
+ $ this ->prepareRequestData ($ post );
69
66
70
67
$ this ->dispatch ('customer/account/forgotPasswordPost ' );
71
68
@@ -75,4 +72,47 @@ public function testForgotPasswordCheckUnsuccessfulMessageWhenCaptchaFailed()
75
72
MessageInterface::TYPE_ERROR
76
73
);
77
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
+ }
78
118
}
0 commit comments