Skip to content

Commit 715d9de

Browse files
🔃 [Magento Community Engineering] Community Contributions - 2.4-develop expedited
Accepted Community Pull Requests: - #27412: Added improvements to category url key validation logic (by @sergiy-v) - #27393: Implement ActionInterface for /robots/index/index (by @Bartlomiejsz) - #27383: #27370 Internet explorer issue:Default billing/shipping address not showing (by @vasilii-b) - #27385: Cleanup ObjectManager usage - Magento_SendFriend (by @Bartlomiejsz) - #27384: Cleanup ObjectManager usage - Magento_Sitemap (by @Bartlomiejsz) - #27381: Implement ActionInterface for /captcha/refresh (by @lbajsarowicz) - #27360: Move JS module initialization to separate tasks (by @krzksz) - #27088: Fix Report date doesn't matching in configuration setting (by @Priya-V-Panchal) Fixed GitHub Issues: - #27086: Report Value doesn't matching - "Year-To-Date Starts" (reported by @vishvesshah) has been fixed in #27088 by @Priya-V-Panchal in 2.4-develop branch Related commits: 1. d03d8e1 2. 2ec8bf5 3. 2410cbb 4. a2a865c
2 parents 2130fe0 + 79bc637 commit 715d9de

File tree

21 files changed

+682
-430
lines changed

21 files changed

+682
-430
lines changed
Lines changed: 72 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,107 @@
11
<?php
22
/**
3-
* Refreshes captcha and returns JSON encoded URL to image (AJAX action)
4-
* Example: {'imgSrc': 'http://example.com/media/captcha/67842gh187612ngf8s.png'}
5-
*
63
* Copyright © Magento, Inc. All rights reserved.
74
* See COPYING.txt for license details.
85
*/
6+
declare(strict_types=1);
7+
98
namespace Magento\Captcha\Controller\Refresh;
109

11-
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
12-
use Magento\Framework\App\Action\Context;
10+
use Magento\Captcha\Helper\Data as CaptchaHelper;
11+
use Magento\Framework\App\Action\HttpPostActionInterface;
12+
use Magento\Framework\App\RequestInterface;
13+
use Magento\Framework\Controller\Result\JsonFactory as JsonResultFactory;
14+
use Magento\Framework\Serialize\Serializer\Json as JsonSerializer;
15+
use Magento\Framework\View\LayoutInterface;
1316

14-
class Index extends \Magento\Framework\App\Action\Action implements HttpPostActionInterface
17+
/**
18+
* Refreshes captcha and returns JSON encoded URL to image (AJAX action)
19+
* Example: {'imgSrc': 'http://example.com/media/captcha/67842gh187612ngf8s.png'}
20+
*/
21+
class Index implements HttpPostActionInterface
1522
{
1623
/**
17-
* @var \Magento\Captcha\Helper\Data
24+
* @var CaptchaHelper
25+
*/
26+
private $captchaHelper;
27+
28+
/**
29+
* @var JsonSerializer
30+
*/
31+
private $serializer;
32+
33+
/**
34+
* @var RequestInterface
35+
*/
36+
private $request;
37+
38+
/**
39+
* @var LayoutInterface
1840
*/
19-
protected $captchaHelper;
41+
private $layout;
2042

2143
/**
22-
* @var \Magento\Framework\Serialize\Serializer\Json
44+
* @var JsonResultFactory
2345
*/
24-
protected $serializer;
46+
private $jsonResultFactory;
2547

2648
/**
27-
* @param Context $context
28-
* @param \Magento\Captcha\Helper\Data $captchaHelper
29-
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
30-
* @throws \RuntimeException
49+
* @param RequestInterface $request
50+
* @param JsonResultFactory $jsonFactory
51+
* @param CaptchaHelper $captchaHelper
52+
* @param LayoutInterface $layout
53+
* @param JsonSerializer $serializer
3154
*/
3255
public function __construct(
33-
Context $context,
34-
\Magento\Captcha\Helper\Data $captchaHelper,
35-
\Magento\Framework\Serialize\Serializer\Json $serializer = null
56+
RequestInterface $request,
57+
JsonResultFactory $jsonFactory,
58+
CaptchaHelper $captchaHelper,
59+
LayoutInterface $layout,
60+
JsonSerializer $serializer
3661
) {
62+
$this->request = $request;
63+
$this->jsonResultFactory = $jsonFactory;
3764
$this->captchaHelper = $captchaHelper;
38-
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
39-
->get(\Magento\Framework\Serialize\Serializer\Json::class);
40-
parent::__construct($context);
65+
$this->layout = $layout;
66+
$this->serializer = $serializer;
4167
}
4268

4369
/**
44-
* {@inheritdoc}
70+
* @inheritdoc
4571
*/
4672
public function execute()
4773
{
48-
$formId = $this->_request->getPost('formId');
74+
$formId = $this->getRequestFormId();
75+
76+
$captchaModel = $this->captchaHelper->getCaptcha($formId);
77+
$captchaModel->generate();
78+
79+
$block = $this->layout->createBlock($captchaModel->getBlockName());
80+
$block->setFormId($formId)->setIsAjax(true)->toHtml();
81+
82+
$result = $this->jsonResultFactory->create();
83+
84+
return $result->setData(['imgSrc' => $captchaModel->getImgSrc()]);
85+
}
86+
87+
/**
88+
* Returns requested Form ID
89+
*
90+
* @return string|null
91+
*/
92+
private function getRequestFormId(): ?string
93+
{
94+
$formId = $this->request->getPost('formId');
4995
if (null === $formId) {
5096
$params = [];
51-
$content = $this->_request->getContent();
97+
$content = $this->request->getContent();
5298
if ($content) {
5399
$params = $this->serializer->unserialize($content);
54100
}
55-
$formId = isset($params['formId']) ? $params['formId'] : null;
101+
102+
$formId = $params['formId'] ?? null;
56103
}
57-
$captchaModel = $this->captchaHelper->getCaptcha($formId);
58-
$captchaModel->generate();
59104

60-
$block = $this->_view->getLayout()->createBlock($captchaModel->getBlockName());
61-
$block->setFormId($formId)->setIsAjax(true)->toHtml();
62-
$this->_response->representJson($this->serializer->serialize(['imgSrc' => $captchaModel->getImgSrc()]));
63-
$this->_actionFlag->set('', self::FLAG_NO_POST_DISPATCH, true);
105+
return $formId !== null ? (string)$formId : null;
64106
}
65107
}

app/code/Magento/Captcha/Test/Mftf/Test/CaptchaFormsDisplayingTest.xml

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -65,53 +65,4 @@
6565
<scrollToTopOfPage stepKey="ScrollToTop"/>
6666
<click selector="{{CaptchaFormsDisplayingSection.captcha}}" stepKey="ClickToCloseCaptcha"/>
6767
</test>
68-
<test name="CaptchaWithDisabledGuestCheckoutTest">
69-
<annotations>
70-
<features value="Captcha"/>
71-
<stories value="MC-5602 - CAPTCHA doesn't appear in login popup after refreshing page."/>
72-
<title value="Captcha is displaying on login form with disabled guest checkout"/>
73-
<description value="Captcha is displaying on login form with disabled guest checkout"/>
74-
<severity value="MAJOR"/>
75-
<testCaseId value="MAGETWO-96691"/>
76-
<group value="captcha"/>
77-
</annotations>
78-
<before>
79-
<magentoCLI command="config:set checkout/options/guest_checkout 0" stepKey="disableGuestCheckout"/>
80-
<magentoCLI command="config:set customer/captcha/failed_attempts_login 1" stepKey="decreaseLoginAttempt"/>
81-
<createData entity="ApiCategory" stepKey="createCategory"/>
82-
<createData entity="ApiSimpleProduct" stepKey="createSimpleProduct">
83-
<requiredEntity createDataKey="createCategory"/>
84-
</createData>
85-
</before>
86-
<after>
87-
<magentoCLI command="config:set checkout/options/guest_checkout 1" stepKey="enableGuestCheckout"/>
88-
<magentoCLI command="config:set customer/captcha/failed_attempts_login 3" stepKey="increaseLoginAttempt"/>
89-
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
90-
<deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct1"/>
91-
</after>
92-
<amOnPage url="{{StorefrontProductPage.url($$createSimpleProduct.sku$$)}}" stepKey="openProductPage"/>
93-
<waitForPageLoad stepKey="waitForPageLoad"/>
94-
<click selector="{{StorefrontProductActionSection.addToCart}}" stepKey="addToCart" />
95-
<waitForPageLoad stepKey="waitForAddToCart"/>
96-
<waitForElementVisible selector="{{StorefrontMessagesSection.success}}" stepKey="waitForSuccessMessage"/>
97-
<waitForText userInput="You added $$createSimpleProduct.name$$ to your shopping cart." stepKey="waitForText"/>
98-
<click selector="{{StorefrontMinicartSection.showCart}}" stepKey="clickCart"/>
99-
<click selector="{{StorefrontMinicartSection.goToCheckout}}" stepKey="goToCheckout"/>
100-
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.email}}" stepKey="waitEmailFieldVisible"/>
101-
<fillField selector="{{StorefrontCustomerSignInPopupFormSection.email}}" userInput="{{Simple_US_Customer.email}}" stepKey="fillCustomerEmail"/>
102-
<fillField selector="{{StorefrontCustomerSignInPopupFormSection.password}}" userInput="incorrectPassword" stepKey="fillIncorrectCustomerPassword"/>
103-
<click selector="{{StorefrontCustomerSignInPopupFormSection.signIn}}" stepKey="clickSignIn"/>
104-
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.errorMessage}}" stepKey="seeErrorMessage"/>
105-
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.captchaField}}" stepKey="seeCaptchaField"/>
106-
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.captchaImg}}" stepKey="seeCaptchaImage"/>
107-
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.captchaReload}}" stepKey="seeCaptchaReloadButton"/>
108-
<reloadPage stepKey="refreshPage"/>
109-
<waitForPageLoad stepKey="waitForPageLoad2"/>
110-
<click selector="{{StorefrontMinicartSection.showCart}}" stepKey="clickCart2"/>
111-
<click selector="{{StorefrontMinicartSection.goToCheckout}}" stepKey="goToCheckout2"/>
112-
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.email}}" stepKey="waitEmailFieldVisible2"/>
113-
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.captchaField}}" stepKey="seeCaptchaField2"/>
114-
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.captchaImg}}" stepKey="seeCaptchaImage2"/>
115-
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.captchaReload}}" stepKey="seeCaptchaReloadButton2"/>
116-
</test>
11768
</tests>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="CaptchaWithDisabledGuestCheckoutTest">
12+
<annotations>
13+
<features value="Captcha"/>
14+
<stories value="MC-5602 - CAPTCHA doesn't appear in login popup after refreshing page."/>
15+
<title value="Captcha is displaying on login form with disabled guest checkout"/>
16+
<description value="Captcha is displaying on login form with disabled guest checkout"/>
17+
<severity value="MAJOR"/>
18+
<testCaseId value="MAGETWO-96691"/>
19+
<group value="captcha"/>
20+
</annotations>
21+
<before>
22+
<magentoCLI command="config:set checkout/options/guest_checkout 0" stepKey="disableGuestCheckout"/>
23+
<magentoCLI command="config:set customer/captcha/failed_attempts_login 1" stepKey="decreaseLoginAttempt"/>
24+
<createData entity="ApiCategory" stepKey="createCategory"/>
25+
<createData entity="ApiSimpleProduct" stepKey="createSimpleProduct">
26+
<requiredEntity createDataKey="createCategory"/>
27+
</createData>
28+
<magentoCron stepKey="runCronIndex" groups="index"/>
29+
</before>
30+
<after>
31+
<magentoCLI command="config:set checkout/options/guest_checkout 1" stepKey="enableGuestCheckout"/>
32+
<magentoCLI command="config:set customer/captcha/failed_attempts_login 3" stepKey="increaseLoginAttempt"/>
33+
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
34+
<deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct1"/>
35+
</after>
36+
<amOnPage url="{{StorefrontProductPage.url($$createSimpleProduct.sku$$)}}" stepKey="openProductPage"/>
37+
<waitForPageLoad stepKey="waitForPageLoad"/>
38+
<click selector="{{StorefrontProductActionSection.addToCart}}" stepKey="addToCart"/>
39+
<waitForPageLoad stepKey="waitForAddToCart"/>
40+
<waitForElementVisible selector="{{StorefrontMessagesSection.success}}" stepKey="waitForSuccessMessage"/>
41+
<waitForText userInput="You added $$createSimpleProduct.name$$ to your shopping cart." stepKey="waitForText"/>
42+
<click selector="{{StorefrontMinicartSection.showCart}}" stepKey="clickCart"/>
43+
<click selector="{{StorefrontMinicartSection.goToCheckout}}" stepKey="goToCheckout"/>
44+
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.email}}" stepKey="waitEmailFieldVisible"/>
45+
<fillField selector="{{StorefrontCustomerSignInPopupFormSection.email}}" userInput="{{Simple_US_Customer.email}}" stepKey="fillCustomerEmail"/>
46+
<fillField selector="{{StorefrontCustomerSignInPopupFormSection.password}}" userInput="incorrectPassword" stepKey="fillIncorrectCustomerPassword"/>
47+
<click selector="{{StorefrontCustomerSignInPopupFormSection.signIn}}" stepKey="clickSignIn"/>
48+
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.errorMessage}}" stepKey="seeErrorMessage"/>
49+
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.captchaField}}" stepKey="seeCaptchaField"/>
50+
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.captchaImg}}" stepKey="seeCaptchaImage"/>
51+
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.captchaReload}}" stepKey="seeCaptchaReloadButton"/>
52+
<reloadPage stepKey="refreshPage"/>
53+
<waitForPageLoad stepKey="waitForPageLoad2"/>
54+
<click selector="{{StorefrontMinicartSection.showCart}}" stepKey="clickCart2"/>
55+
<click selector="{{StorefrontMinicartSection.goToCheckout}}" stepKey="goToCheckout2"/>
56+
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.email}}" stepKey="waitEmailFieldVisible2"/>
57+
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.captchaField}}" stepKey="seeCaptchaField2"/>
58+
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.captchaImg}}" stepKey="seeCaptchaImage2"/>
59+
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.captchaReload}}" stepKey="seeCaptchaReloadButton2"/>
60+
</test>
61+
</tests>

0 commit comments

Comments
 (0)