Skip to content

Commit

Permalink
🔃 [Magento Community Engineering] Community Contributions - 2.4-devel…
Browse files Browse the repository at this point in the history
…op 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
  • Loading branch information
magento-engcom-team authored Mar 27, 2020
2 parents 2130fe0 + 79bc637 commit 715d9de
Show file tree
Hide file tree
Showing 21 changed files with 682 additions and 430 deletions.
102 changes: 72 additions & 30 deletions app/code/Magento/Captcha/Controller/Refresh/Index.php
Original file line number Diff line number Diff line change
@@ -1,65 +1,107 @@
<?php
/**
* Refreshes captcha and returns JSON encoded URL to image (AJAX action)
* Example: {'imgSrc': 'http://example.com/media/captcha/67842gh187612ngf8s.png'}
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Captcha\Controller\Refresh;

use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
use Magento\Framework\App\Action\Context;
use Magento\Captcha\Helper\Data as CaptchaHelper;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Controller\Result\JsonFactory as JsonResultFactory;
use Magento\Framework\Serialize\Serializer\Json as JsonSerializer;
use Magento\Framework\View\LayoutInterface;

class Index extends \Magento\Framework\App\Action\Action implements HttpPostActionInterface
/**
* Refreshes captcha and returns JSON encoded URL to image (AJAX action)
* Example: {'imgSrc': 'http://example.com/media/captcha/67842gh187612ngf8s.png'}
*/
class Index implements HttpPostActionInterface
{
/**
* @var \Magento\Captcha\Helper\Data
* @var CaptchaHelper
*/
private $captchaHelper;

/**
* @var JsonSerializer
*/
private $serializer;

/**
* @var RequestInterface
*/
private $request;

/**
* @var LayoutInterface
*/
protected $captchaHelper;
private $layout;

/**
* @var \Magento\Framework\Serialize\Serializer\Json
* @var JsonResultFactory
*/
protected $serializer;
private $jsonResultFactory;

/**
* @param Context $context
* @param \Magento\Captcha\Helper\Data $captchaHelper
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
* @throws \RuntimeException
* @param RequestInterface $request
* @param JsonResultFactory $jsonFactory
* @param CaptchaHelper $captchaHelper
* @param LayoutInterface $layout
* @param JsonSerializer $serializer
*/
public function __construct(
Context $context,
\Magento\Captcha\Helper\Data $captchaHelper,
\Magento\Framework\Serialize\Serializer\Json $serializer = null
RequestInterface $request,
JsonResultFactory $jsonFactory,
CaptchaHelper $captchaHelper,
LayoutInterface $layout,
JsonSerializer $serializer
) {
$this->request = $request;
$this->jsonResultFactory = $jsonFactory;
$this->captchaHelper = $captchaHelper;
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\Serialize\Serializer\Json::class);
parent::__construct($context);
$this->layout = $layout;
$this->serializer = $serializer;
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function execute()
{
$formId = $this->_request->getPost('formId');
$formId = $this->getRequestFormId();

$captchaModel = $this->captchaHelper->getCaptcha($formId);
$captchaModel->generate();

$block = $this->layout->createBlock($captchaModel->getBlockName());
$block->setFormId($formId)->setIsAjax(true)->toHtml();

$result = $this->jsonResultFactory->create();

return $result->setData(['imgSrc' => $captchaModel->getImgSrc()]);
}

/**
* Returns requested Form ID
*
* @return string|null
*/
private function getRequestFormId(): ?string
{
$formId = $this->request->getPost('formId');
if (null === $formId) {
$params = [];
$content = $this->_request->getContent();
$content = $this->request->getContent();
if ($content) {
$params = $this->serializer->unserialize($content);
}
$formId = isset($params['formId']) ? $params['formId'] : null;

$formId = $params['formId'] ?? null;
}
$captchaModel = $this->captchaHelper->getCaptcha($formId);
$captchaModel->generate();

$block = $this->_view->getLayout()->createBlock($captchaModel->getBlockName());
$block->setFormId($formId)->setIsAjax(true)->toHtml();
$this->_response->representJson($this->serializer->serialize(['imgSrc' => $captchaModel->getImgSrc()]));
$this->_actionFlag->set('', self::FLAG_NO_POST_DISPATCH, true);
return $formId !== null ? (string)$formId : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,53 +65,4 @@
<scrollToTopOfPage stepKey="ScrollToTop"/>
<click selector="{{CaptchaFormsDisplayingSection.captcha}}" stepKey="ClickToCloseCaptcha"/>
</test>
<test name="CaptchaWithDisabledGuestCheckoutTest">
<annotations>
<features value="Captcha"/>
<stories value="MC-5602 - CAPTCHA doesn't appear in login popup after refreshing page."/>
<title value="Captcha is displaying on login form with disabled guest checkout"/>
<description value="Captcha is displaying on login form with disabled guest checkout"/>
<severity value="MAJOR"/>
<testCaseId value="MAGETWO-96691"/>
<group value="captcha"/>
</annotations>
<before>
<magentoCLI command="config:set checkout/options/guest_checkout 0" stepKey="disableGuestCheckout"/>
<magentoCLI command="config:set customer/captcha/failed_attempts_login 1" stepKey="decreaseLoginAttempt"/>
<createData entity="ApiCategory" stepKey="createCategory"/>
<createData entity="ApiSimpleProduct" stepKey="createSimpleProduct">
<requiredEntity createDataKey="createCategory"/>
</createData>
</before>
<after>
<magentoCLI command="config:set checkout/options/guest_checkout 1" stepKey="enableGuestCheckout"/>
<magentoCLI command="config:set customer/captcha/failed_attempts_login 3" stepKey="increaseLoginAttempt"/>
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
<deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct1"/>
</after>
<amOnPage url="{{StorefrontProductPage.url($$createSimpleProduct.sku$$)}}" stepKey="openProductPage"/>
<waitForPageLoad stepKey="waitForPageLoad"/>
<click selector="{{StorefrontProductActionSection.addToCart}}" stepKey="addToCart" />
<waitForPageLoad stepKey="waitForAddToCart"/>
<waitForElementVisible selector="{{StorefrontMessagesSection.success}}" stepKey="waitForSuccessMessage"/>
<waitForText userInput="You added $$createSimpleProduct.name$$ to your shopping cart." stepKey="waitForText"/>
<click selector="{{StorefrontMinicartSection.showCart}}" stepKey="clickCart"/>
<click selector="{{StorefrontMinicartSection.goToCheckout}}" stepKey="goToCheckout"/>
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.email}}" stepKey="waitEmailFieldVisible"/>
<fillField selector="{{StorefrontCustomerSignInPopupFormSection.email}}" userInput="{{Simple_US_Customer.email}}" stepKey="fillCustomerEmail"/>
<fillField selector="{{StorefrontCustomerSignInPopupFormSection.password}}" userInput="incorrectPassword" stepKey="fillIncorrectCustomerPassword"/>
<click selector="{{StorefrontCustomerSignInPopupFormSection.signIn}}" stepKey="clickSignIn"/>
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.errorMessage}}" stepKey="seeErrorMessage"/>
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.captchaField}}" stepKey="seeCaptchaField"/>
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.captchaImg}}" stepKey="seeCaptchaImage"/>
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.captchaReload}}" stepKey="seeCaptchaReloadButton"/>
<reloadPage stepKey="refreshPage"/>
<waitForPageLoad stepKey="waitForPageLoad2"/>
<click selector="{{StorefrontMinicartSection.showCart}}" stepKey="clickCart2"/>
<click selector="{{StorefrontMinicartSection.goToCheckout}}" stepKey="goToCheckout2"/>
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.email}}" stepKey="waitEmailFieldVisible2"/>
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.captchaField}}" stepKey="seeCaptchaField2"/>
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.captchaImg}}" stepKey="seeCaptchaImage2"/>
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.captchaReload}}" stepKey="seeCaptchaReloadButton2"/>
</test>
</tests>
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="CaptchaWithDisabledGuestCheckoutTest">
<annotations>
<features value="Captcha"/>
<stories value="MC-5602 - CAPTCHA doesn't appear in login popup after refreshing page."/>
<title value="Captcha is displaying on login form with disabled guest checkout"/>
<description value="Captcha is displaying on login form with disabled guest checkout"/>
<severity value="MAJOR"/>
<testCaseId value="MAGETWO-96691"/>
<group value="captcha"/>
</annotations>
<before>
<magentoCLI command="config:set checkout/options/guest_checkout 0" stepKey="disableGuestCheckout"/>
<magentoCLI command="config:set customer/captcha/failed_attempts_login 1" stepKey="decreaseLoginAttempt"/>
<createData entity="ApiCategory" stepKey="createCategory"/>
<createData entity="ApiSimpleProduct" stepKey="createSimpleProduct">
<requiredEntity createDataKey="createCategory"/>
</createData>
<magentoCron stepKey="runCronIndex" groups="index"/>
</before>
<after>
<magentoCLI command="config:set checkout/options/guest_checkout 1" stepKey="enableGuestCheckout"/>
<magentoCLI command="config:set customer/captcha/failed_attempts_login 3" stepKey="increaseLoginAttempt"/>
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
<deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct1"/>
</after>
<amOnPage url="{{StorefrontProductPage.url($$createSimpleProduct.sku$$)}}" stepKey="openProductPage"/>
<waitForPageLoad stepKey="waitForPageLoad"/>
<click selector="{{StorefrontProductActionSection.addToCart}}" stepKey="addToCart"/>
<waitForPageLoad stepKey="waitForAddToCart"/>
<waitForElementVisible selector="{{StorefrontMessagesSection.success}}" stepKey="waitForSuccessMessage"/>
<waitForText userInput="You added $$createSimpleProduct.name$$ to your shopping cart." stepKey="waitForText"/>
<click selector="{{StorefrontMinicartSection.showCart}}" stepKey="clickCart"/>
<click selector="{{StorefrontMinicartSection.goToCheckout}}" stepKey="goToCheckout"/>
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.email}}" stepKey="waitEmailFieldVisible"/>
<fillField selector="{{StorefrontCustomerSignInPopupFormSection.email}}" userInput="{{Simple_US_Customer.email}}" stepKey="fillCustomerEmail"/>
<fillField selector="{{StorefrontCustomerSignInPopupFormSection.password}}" userInput="incorrectPassword" stepKey="fillIncorrectCustomerPassword"/>
<click selector="{{StorefrontCustomerSignInPopupFormSection.signIn}}" stepKey="clickSignIn"/>
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.errorMessage}}" stepKey="seeErrorMessage"/>
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.captchaField}}" stepKey="seeCaptchaField"/>
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.captchaImg}}" stepKey="seeCaptchaImage"/>
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.captchaReload}}" stepKey="seeCaptchaReloadButton"/>
<reloadPage stepKey="refreshPage"/>
<waitForPageLoad stepKey="waitForPageLoad2"/>
<click selector="{{StorefrontMinicartSection.showCart}}" stepKey="clickCart2"/>
<click selector="{{StorefrontMinicartSection.goToCheckout}}" stepKey="goToCheckout2"/>
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.email}}" stepKey="waitEmailFieldVisible2"/>
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.captchaField}}" stepKey="seeCaptchaField2"/>
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.captchaImg}}" stepKey="seeCaptchaImage2"/>
<waitForElementVisible selector="{{StorefrontCustomerSignInPopupFormSection.captchaReload}}" stepKey="seeCaptchaReloadButton2"/>
</test>
</tests>
Loading

0 comments on commit 715d9de

Please sign in to comment.