Skip to content

Commit

Permalink
Merge pull request #817 from magento-engcom/develop-prs
Browse files Browse the repository at this point in the history
[EngCom] Public Pull Requests

Public Pull Requests

#8456
#8405
#8331
#8446
#8252
#8402
#8463
  • Loading branch information
Oleksii Korshenko authored Feb 9, 2017
2 parents 24cd0c3 + 79b4c53 commit 988f3a3
Show file tree
Hide file tree
Showing 16 changed files with 217 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,33 @@ class VaultDetailsHandler implements HandlerInterface
protected $config;

/**
* @var \Magento\Framework\Serialize\SerializerInterface
* @var \Magento\Framework\Serialize\Serializer\Json
*/
private $serializer;

/**
* Constructor
* VaultDetailsHandler constructor.
*
* @param PaymentTokenInterfaceFactory $paymentTokenFactory
* @param OrderPaymentExtensionInterfaceFactory $paymentExtensionFactory
* @param Config $config
* @param SubjectReader $subjectReader
* @param \Magento\Framework\Serialize\SerializerInterface $serializer
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
* @throws \RuntimeException
*/
public function __construct(
PaymentTokenInterfaceFactory $paymentTokenFactory,
OrderPaymentExtensionInterfaceFactory $paymentExtensionFactory,
Config $config,
SubjectReader $subjectReader,
\Magento\Framework\Serialize\SerializerInterface $serializer = null
\Magento\Framework\Serialize\Serializer\Json $serializer = null
) {
$this->paymentTokenFactory = $paymentTokenFactory;
$this->paymentExtensionFactory = $paymentExtensionFactory;
$this->config = $config;
$this->subjectReader = $subjectReader;
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\Serialize\SerializerInterface::class);
->get(\Magento\Framework\Serialize\Serializer\Json::class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ protected function setUp()
->willReturn($mapperArray);

$this->serializer = $this->getMock(
\Magento\Framework\Serialize\SerializerInterface::class,
\Magento\Framework\Serialize\Serializer\Json::class,
[],
[],
'',
Expand Down
30 changes: 28 additions & 2 deletions app/code/Magento/Captcha/Controller/Adminhtml/Refresh/Refresh.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,47 @@

class Refresh extends \Magento\Backend\App\Action
{
/**
* @var \Magento\Framework\Serialize\Serializer\Json
*/
protected $serializer;

/**
* @var \Magento\Captcha\Helper\Data
*/
protected $captchaHelper;

/**
* Refresh constructor.
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Captcha\Helper\Data $captchaHelper
* @param \Magento\Framework\Serialize\Serializer\Json $serializer
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Captcha\Helper\Data $captchaHelper,
\Magento\Framework\Serialize\Serializer\Json $serializer
) {
parent::__construct($context);
$this->serializer = $serializer;
$this->captchaHelper = $captchaHelper;
}

/**
* {@inheritdoc}
*/
public function execute()
{
$formId = $this->getRequest()->getPost('formId');
$captchaModel = $this->_objectManager->get(\Magento\Captcha\Helper\Data::class)->getCaptcha($formId);
$captchaModel = $this->captchaHelper->getCaptcha($formId);
$this->_view->getLayout()->createBlock(
$captchaModel->getBlockName()
)->setFormId(
$formId
)->setIsAjax(
true
)->toHtml();
$this->getResponse()->representJson(json_encode(['imgSrc' => $captchaModel->getImgSrc()]));
$this->getResponse()->representJson($this->serializer->serialize(['imgSrc' => $captchaModel->getImgSrc()]));
$this->_actionFlag->set('', self::FLAG_NO_POST_DISPATCH, true);
}

Expand Down
32 changes: 20 additions & 12 deletions app/code/Magento/Captcha/Controller/Refresh/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,25 @@ class Index extends \Magento\Framework\App\Action\Action
*/
protected $captchaHelper;

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

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

Expand All @@ -34,23 +46,19 @@ public function execute()
{
$formId = $this->_request->getPost('formId');
if (null === $formId) {
try {
$params = [];
$content = $this->_request->getContent();
if ($content) {
$params = \Zend_Json::decode($content);
}
$formId = isset($params['formId']) ? $params['formId'] : null;
} catch (\Zend_Json_Exception $exception) {
$formId = null;
$params = [];
$content = $this->_request->getContent();
if ($content) {
$params = $this->serializer->unserialize($content);
}
$formId = isset($params['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(json_encode(['imgSrc' => $captchaModel->getImgSrc()]));
$this->_response->representJson($this->serializer->serialize(['imgSrc' => $captchaModel->getImgSrc()]));
$this->_actionFlag->set('', self::FLAG_NO_POST_DISPATCH, true);
}
}
15 changes: 12 additions & 3 deletions app/code/Magento/Captcha/Model/Customer/Plugin/AjaxLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class AjaxLogin
*/
protected $resultJsonFactory;

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

/**
* @var array
*/
Expand All @@ -36,24 +41,28 @@ class AjaxLogin
* @param SessionManagerInterface $sessionManager
* @param JsonFactory $resultJsonFactory
* @param array $formIds
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
* @throws \RuntimeException
*/
public function __construct(
CaptchaHelper $helper,
SessionManagerInterface $sessionManager,
JsonFactory $resultJsonFactory,
array $formIds
array $formIds,
\Magento\Framework\Serialize\Serializer\Json $serializer = null
) {
$this->helper = $helper;
$this->sessionManager = $sessionManager;
$this->resultJsonFactory = $resultJsonFactory;
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\Serialize\Serializer\Json::class);
$this->formIds = $formIds;
}

/**
* @param \Magento\Customer\Controller\Ajax\Login $subject
* @param \Closure $proceed
* @return $this
* @throws \Zend_Json_Exception
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
Expand All @@ -70,7 +79,7 @@ public function aroundExecute(
$loginParams = [];
$content = $request->getContent();
if ($content) {
$loginParams = \Zend_Json::decode($content);
$loginParams = $this->serializer->unserialize($content);
}
$username = isset($loginParams['username']) ? $loginParams['username'] : null;
$captchaString = isset($loginParams[$captchaInputName]) ? $loginParams[$captchaInputName] : null;
Expand Down
9 changes: 7 additions & 2 deletions app/code/Magento/Captcha/Model/ResourceModel/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ protected function _construct()
*
* @param string|null $login
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function logAttempt($login)
{
Expand All @@ -78,7 +79,7 @@ public function logAttempt($login)
'count' => 1,
'updated_at' => $this->_coreDate->gmtDate()
],
['count' => new \Zend_Db_Expr('count+1'), 'updated_at']
['count' => new \Zend\Db\Sql\Expression('count+1'), 'updated_at']
);
}
$ip = $this->_remoteAddress->getRemoteAddress();
Expand All @@ -91,7 +92,7 @@ public function logAttempt($login)
'count' => 1,
'updated_at' => $this->_coreDate->gmtDate()
],
['count' => new \Zend_Db_Expr('count+1'), 'updated_at']
['count' => new \Zend\Db\Sql\Expression('count+1'), 'updated_at']
);
}
return $this;
Expand All @@ -102,6 +103,7 @@ public function logAttempt($login)
*
* @param string $login
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function deleteUserAttempts($login)
{
Expand All @@ -126,6 +128,7 @@ public function deleteUserAttempts($login)
* Get count attempts by ip
*
* @return null|int
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function countAttemptsByRemoteAddress()
{
Expand All @@ -152,6 +155,7 @@ public function countAttemptsByRemoteAddress()
*
* @param string $login
* @return null|int
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function countAttemptsByUserLogin($login)
{
Expand All @@ -176,6 +180,7 @@ public function countAttemptsByUserLogin($login)
* Delete attempts with expired in update_at time
*
* @return void
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function deleteOldAttempts()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ class IndexTest extends \PHPUnit_Framework_TestCase
*/
protected $flagMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $serializerMock;

/**
* @var \Magento\Captcha\Controller\Refresh\Index
*/
Expand All @@ -62,14 +67,25 @@ protected function setUp()
$this->viewMock = $this->getMock(\Magento\Framework\App\ViewInterface::class);
$this->layoutMock = $this->getMock(\Magento\Framework\View\LayoutInterface::class);
$this->flagMock = $this->getMock(\Magento\Framework\App\ActionFlag::class, [], [], '', false);
$this->serializerMock = $this->getMock(
\Magento\Framework\Serialize\Serializer\Json::class,
[],
[],
'',
false
);

$this->contextMock->expects($this->any())->method('getRequest')->will($this->returnValue($this->requestMock));
$this->contextMock->expects($this->any())->method('getView')->will($this->returnValue($this->viewMock));
$this->contextMock->expects($this->any())->method('getResponse')->will($this->returnValue($this->responseMock));
$this->contextMock->expects($this->any())->method('getActionFlag')->will($this->returnValue($this->flagMock));
$this->viewMock->expects($this->any())->method('getLayout')->will($this->returnValue($this->layoutMock));

$this->model = new \Magento\Captcha\Controller\Refresh\Index($this->contextMock, $this->captchaHelperMock);
$this->model = new \Magento\Captcha\Controller\Refresh\Index(
$this->contextMock,
$this->captchaHelperMock,
$this->serializerMock
);
}

/**
Expand All @@ -80,6 +96,7 @@ protected function setUp()
public function testExecute($formId, $callsNumber)
{
$content = ['formId' => $formId];
$imgSource = ['imgSrc' => 'source'];

$blockMethods = ['setFormId', 'setIsAjax', 'toHtml'];
$blockMock = $this->getMock(\Magento\Captcha\Block\Captcha::class, $blockMethods, [], '', false);
Expand All @@ -97,8 +114,12 @@ public function testExecute($formId, $callsNumber)
$blockMock->expects($this->any())->method('setFormId')->with($formId)->will($this->returnValue($blockMock));
$blockMock->expects($this->any())->method('setIsAjax')->with(true)->will($this->returnValue($blockMock));
$blockMock->expects($this->once())->method('toHtml');
$this->responseMock->expects($this->once())->method('representJson')->with(json_encode(['imgSrc' => 'source']));
$this->responseMock->expects($this->once())->method('representJson')->with(json_encode($imgSource));
$this->flagMock->expects($this->once())->method('set')->with('', 'no-postDispatch', true);
$this->serializerMock->expects($this->exactly($callsNumber))
->method('unserialize')->will($this->returnValue($content));
$this->serializerMock->expects($this->once())
->method('serialize')->will($this->returnValue(json_encode($imgSource)));

$this->model->execute();
}
Expand Down
Loading

0 comments on commit 988f3a3

Please sign in to comment.