Skip to content

Commit 809e8d9

Browse files
#222: Add validation for error message - test fix.
1 parent 1cc2dfc commit 809e8d9

File tree

17 files changed

+36
-23
lines changed

17 files changed

+36
-23
lines changed

ReCaptchaAdminUi/composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"php": "~7.3.0||~7.4.0",
66
"magento/framework": "*",
77
"magento/module-config": "*",
8-
"magento/module-re-captcha-ui": "*"
8+
"magento/module-re-captcha-ui": "*",
9+
"magento/module-store": "*"
910
},
1011
"type": "magento2-module",
1112
"license": "OSL-3.0",

ReCaptchaAdminUi/etc/config.xml

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
<recaptcha_backend>
1212
<failure_messages>
1313
<validation_failure_message>reCAPTCHA verification failed.</validation_failure_message>
14-
<technical_failure_message>Something went wrong with reCAPTCHA, please contact Store owner.
15-
</technical_failure_message>
14+
<technical_failure_message>Something went wrong with reCAPTCHA. Please contact the store owner.</technical_failure_message>
1615
</failure_messages>
1716
</recaptcha_backend>
1817
</default>

ReCaptchaContact/Test/Integration/ContactFormTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ private function checkFailedPostResponse(array $postValues = []): void
210210
$this->makePostRequest($postValues);
211211

212212
$this->assertSessionMessages(
213-
$this->equalTo(['reCAPTCHA verification failed']),
213+
$this->equalTo(['Something went wrong with reCAPTCHA. Please contact the store owner.']),
214214
MessageInterface::TYPE_ERROR
215215
);
216216
}

ReCaptchaCustomer/Model/AjaxLogin/ErrorProcessor.php

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class ErrorProcessor
5151
/**
5252
* @param ActionFlag $actionFlag
5353
* @param SerializerInterface $serializer
54+
* @param LoggerInterface|null $logger
5455
* @param ErrorMessageConfigInterface|null $errorMessageConfig
5556
* @param ValidationErrorMessagesProvider|null $validationErrorMessagesProvider
5657
*/

ReCaptchaCustomer/Observer/AjaxLoginObserver.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use Psr\Log\LoggerInterface;
2121

2222
/**
23-
* AjaxLoginObserver
23+
* Observer of ajax login.
2424
*/
2525
class AjaxLoginObserver implements ObserverInterface
2626
{
@@ -79,8 +79,7 @@ public function __construct(
7979
}
8080

8181
/**
82-
* @param Observer $observer
83-
* @return void
82+
* @inheritdoc
8483
* @throws LocalizedException
8584
*/
8685
public function execute(Observer $observer): void

ReCaptchaCustomer/Test/Integration/AjaxLoginFormTest.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,12 @@ private function checkFailedPostResponse(array $postValues = []): void
218218
{
219219
$this->makePostRequest($postValues);
220220

221-
$expected = json_encode(['errors' => true, 'message' => 'reCAPTCHA verification failed']);
221+
$expected = json_encode(
222+
[
223+
'errors' => true,
224+
'message' => 'Something went wrong with reCAPTCHA. Please contact the store owner.'
225+
]
226+
);
222227

223228
$this->assertEquals(
224229
$expected,

ReCaptchaCustomer/Test/Integration/CreateCustomerFormTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ private function checkFailedPostResponse(array $postValues = []): void
238238
// Customer should not be created
239239
}
240240
$this->assertSessionMessages(
241-
self::equalTo(['reCAPTCHA verification failed']),
241+
self::equalTo(['Something went wrong with reCAPTCHA. Please contact the store owner.']),
242242
MessageInterface::TYPE_ERROR
243243
);
244244
}

ReCaptchaCustomer/Test/Integration/ForgotPasswordFormTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ private function checkFailedPostResponse(array $postValues = []): void
227227

228228
$this->assertRedirect(self::equalTo($this->url->getRouteUrl('customer/account/forgotpassword')));
229229
$this->assertSessionMessages(
230-
self::equalTo(['reCAPTCHA verification failed']),
230+
self::equalTo(['Something went wrong with reCAPTCHA. Please contact the store owner.']),
231231
MessageInterface::TYPE_ERROR
232232
);
233233

ReCaptchaCustomer/Test/Integration/LoginFromTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ private function checkFailedPostResponse(array $postValues = []): void
227227

228228
$this->assertRedirect(self::stringStartsWith($this->url->getRouteUrl('customer/account/login')));
229229
$this->assertSessionMessages(
230-
self::equalTo(['reCAPTCHA verification failed']),
230+
self::equalTo(['Something went wrong with reCAPTCHA. Please contact the store owner.']),
231231
MessageInterface::TYPE_ERROR
232232
);
233233

ReCaptchaFrontendUi/etc/config.xml

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
<recaptcha_frontend>
1212
<failure_messages>
1313
<validation_failure_message>reCAPTCHA verification failed.</validation_failure_message>
14-
<technical_failure_message>Something went wrong with reCAPTCHA, please contact Store owner.
15-
</technical_failure_message>
14+
<technical_failure_message>Something went wrong with reCAPTCHA. Please contact the store owner.</technical_failure_message>
1615
</failure_messages>
1716
</recaptcha_frontend>
1817
</default>

ReCaptchaNewsletter/Test/Integration/NewsletterFormTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ private function checkFailedPostResponse(array $postValues = []): void
227227
$this->makePostRequest($postValues);
228228

229229
$this->assertSessionMessages(
230-
self::equalTo(['reCAPTCHA verification failed']),
230+
self::equalTo(['Something went wrong with reCAPTCHA. Please contact the store owner.']),
231231
MessageInterface::TYPE_ERROR
232232
);
233233
self::assertEmpty(

ReCaptchaReview/Test/Integration/ReviewFormTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ private function checkFailedPostResponse(array $postValues = []): void
221221
$this->makePostRequest($postValues);
222222

223223
$this->assertSessionMessages(
224-
self::equalTo(['reCAPTCHA verification failed']),
224+
self::equalTo(['Something went wrong with reCAPTCHA. Please contact the store owner.']),
225225
MessageInterface::TYPE_ERROR
226226
);
227227
self::assertEquals(0, $this->reviewResourceModel->getTotalReviews(1));

ReCaptchaSendFriend/Test/Integration/SendFriendFormTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ private function checkFailedPostResponse(array $postValues = []): void
247247
$this->makePostRequest($postValues);
248248

249249
$this->assertSessionMessages(
250-
self::equalTo(['reCAPTCHA verification failed']),
250+
self::equalTo(['Something went wrong with reCAPTCHA. Please contact the store owner.']),
251251
MessageInterface::TYPE_ERROR
252252
);
253253
self::assertEmpty($this->transportMock->getSentMessage());

ReCaptchaUi/Model/RequestHandler.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
/**
2222
* @inheritdoc
23+
*
24+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2325
*/
2426
class RequestHandler implements RequestHandlerInterface
2527
{
@@ -129,8 +131,12 @@ public function execute(
129131
* @param string $sourceKey
130132
* @return void
131133
*/
132-
private function processError(HttpResponseInterface $response, array $errorMessages, string $redirectOnFailureUrl, string $sourceKey): void
133-
{
134+
private function processError(
135+
HttpResponseInterface $response,
136+
array $errorMessages,
137+
string $redirectOnFailureUrl,
138+
string $sourceKey
139+
): void {
134140
$validationErrorText = $this->errorMessageConfig->getValidationFailureMessage();
135141
$technicalErrorText = $this->errorMessageConfig->getTechnicalFailureMessage();
136142

ReCaptchaUser/Observer/LoginObserver.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
use Psr\Log\LoggerInterface;
2424

2525
/**
26-
* LoginObserver
26+
* Observer of login.
27+
*
28+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2729
*/
2830
class LoginObserver implements ObserverInterface
2931
{
@@ -80,6 +82,8 @@ class LoginObserver implements ObserverInterface
8082
* @param RequestInterface $request
8183
* @param LoggerInterface $logger
8284
* @param string $loginActionName
85+
* @param ErrorMessageConfigInterface|null $errorMessageConfig
86+
* @param ValidationErrorMessagesProvider|null $validationErrorMessagesProvider
8387
*/
8488
public function __construct(
8589
CaptchaResponseResolverInterface $captchaResponseResolver,
@@ -106,8 +110,7 @@ public function __construct(
106110
}
107111

108112
/**
109-
* @param Observer $observer
110-
* @return void
113+
* @inheritdoc
111114
* @throws AuthenticationException
112115
* @throws LocalizedException
113116
*/

ReCaptchaUser/Test/Integration/ForgotPasswordFormTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ private function checkFailedPostResponse(array $postValues = []): void
203203
$this->makePostRequest($postValues);
204204

205205
$this->assertSessionMessages(
206-
self::equalTo(['reCAPTCHA verification failed']),
206+
self::equalTo(['Something went wrong with reCAPTCHA. Please contact the store owner.']),
207207
MessageInterface::TYPE_ERROR
208208
);
209209
self::assertEmpty($this->transportMock->getSentMessage());

ReCaptchaUser/Test/Integration/LoginFormTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ private function checkFailedPostResponse(array $postValues = []): void
214214
// Location header is different than in the successful case
215215
$this->assertRedirect(self::equalTo($this->backendUrl->getUrl('admin')));
216216
$this->assertSessionMessages(
217-
self::equalTo(['reCAPTCHA verification failed']),
217+
self::equalTo(['Something went wrong with reCAPTCHA. Please contact the store owner.']),
218218
MessageInterface::TYPE_ERROR
219219
);
220220
self::assertFalse($this->auth->isLoggedIn());

0 commit comments

Comments
 (0)