Skip to content

Commit 98bd0d7

Browse files
committed
Merge branch 'develop' of github.com:magento/magento2ce into MAGETWO-63252
2 parents 106118e + 988f3a3 commit 98bd0d7

File tree

16 files changed

+217
-42
lines changed

16 files changed

+217
-42
lines changed

app/code/Magento/Braintree/Gateway/Response/VaultDetailsHandler.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,32 +42,33 @@ class VaultDetailsHandler implements HandlerInterface
4242
protected $config;
4343

4444
/**
45-
* @var \Magento\Framework\Serialize\SerializerInterface
45+
* @var \Magento\Framework\Serialize\Serializer\Json
4646
*/
4747
private $serializer;
4848

4949
/**
50-
* Constructor
50+
* VaultDetailsHandler constructor.
5151
*
5252
* @param PaymentTokenInterfaceFactory $paymentTokenFactory
5353
* @param OrderPaymentExtensionInterfaceFactory $paymentExtensionFactory
5454
* @param Config $config
5555
* @param SubjectReader $subjectReader
56-
* @param \Magento\Framework\Serialize\SerializerInterface $serializer
56+
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
57+
* @throws \RuntimeException
5758
*/
5859
public function __construct(
5960
PaymentTokenInterfaceFactory $paymentTokenFactory,
6061
OrderPaymentExtensionInterfaceFactory $paymentExtensionFactory,
6162
Config $config,
6263
SubjectReader $subjectReader,
63-
\Magento\Framework\Serialize\SerializerInterface $serializer = null
64+
\Magento\Framework\Serialize\Serializer\Json $serializer = null
6465
) {
6566
$this->paymentTokenFactory = $paymentTokenFactory;
6667
$this->paymentExtensionFactory = $paymentExtensionFactory;
6768
$this->config = $config;
6869
$this->subjectReader = $subjectReader;
6970
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
70-
->get(\Magento\Framework\Serialize\SerializerInterface::class);
71+
->get(\Magento\Framework\Serialize\Serializer\Json::class);
7172
}
7273

7374
/**

app/code/Magento/Braintree/Test/Unit/Gateway/Response/VaultDetailsHandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ protected function setUp()
123123
->willReturn($mapperArray);
124124

125125
$this->serializer = $this->getMock(
126-
\Magento\Framework\Serialize\SerializerInterface::class,
126+
\Magento\Framework\Serialize\Serializer\Json::class,
127127
[],
128128
[],
129129
'',

app/code/Magento/Captcha/Controller/Adminhtml/Refresh/Refresh.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,47 @@
1010

1111
class Refresh extends \Magento\Backend\App\Action
1212
{
13+
/**
14+
* @var \Magento\Framework\Serialize\Serializer\Json
15+
*/
16+
protected $serializer;
17+
18+
/**
19+
* @var \Magento\Captcha\Helper\Data
20+
*/
21+
protected $captchaHelper;
22+
23+
/**
24+
* Refresh constructor.
25+
* @param \Magento\Backend\App\Action\Context $context
26+
* @param \Magento\Captcha\Helper\Data $captchaHelper
27+
* @param \Magento\Framework\Serialize\Serializer\Json $serializer
28+
*/
29+
public function __construct(
30+
\Magento\Backend\App\Action\Context $context,
31+
\Magento\Captcha\Helper\Data $captchaHelper,
32+
\Magento\Framework\Serialize\Serializer\Json $serializer
33+
) {
34+
parent::__construct($context);
35+
$this->serializer = $serializer;
36+
$this->captchaHelper = $captchaHelper;
37+
}
38+
1339
/**
1440
* {@inheritdoc}
1541
*/
1642
public function execute()
1743
{
1844
$formId = $this->getRequest()->getPost('formId');
19-
$captchaModel = $this->_objectManager->get(\Magento\Captcha\Helper\Data::class)->getCaptcha($formId);
45+
$captchaModel = $this->captchaHelper->getCaptcha($formId);
2046
$this->_view->getLayout()->createBlock(
2147
$captchaModel->getBlockName()
2248
)->setFormId(
2349
$formId
2450
)->setIsAjax(
2551
true
2652
)->toHtml();
27-
$this->getResponse()->representJson(json_encode(['imgSrc' => $captchaModel->getImgSrc()]));
53+
$this->getResponse()->representJson($this->serializer->serialize(['imgSrc' => $captchaModel->getImgSrc()]));
2854
$this->_actionFlag->set('', self::FLAG_NO_POST_DISPATCH, true);
2955
}
3056

app/code/Magento/Captcha/Controller/Refresh/Index.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,25 @@ class Index extends \Magento\Framework\App\Action\Action
1717
*/
1818
protected $captchaHelper;
1919

20+
/**
21+
* @var \Magento\Framework\Serialize\Serializer\Json
22+
*/
23+
protected $serializer;
24+
2025
/**
2126
* @param Context $context
2227
* @param \Magento\Captcha\Helper\Data $captchaHelper
28+
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
29+
* @throws \RuntimeException
2330
*/
24-
public function __construct(Context $context, \Magento\Captcha\Helper\Data $captchaHelper)
25-
{
31+
public function __construct(
32+
Context $context,
33+
\Magento\Captcha\Helper\Data $captchaHelper,
34+
\Magento\Framework\Serialize\Serializer\Json $serializer = null
35+
) {
2636
$this->captchaHelper = $captchaHelper;
37+
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
38+
->get(\Magento\Framework\Serialize\Serializer\Json::class);
2739
parent::__construct($context);
2840
}
2941

@@ -34,23 +46,19 @@ public function execute()
3446
{
3547
$formId = $this->_request->getPost('formId');
3648
if (null === $formId) {
37-
try {
38-
$params = [];
39-
$content = $this->_request->getContent();
40-
if ($content) {
41-
$params = \Zend_Json::decode($content);
42-
}
43-
$formId = isset($params['formId']) ? $params['formId'] : null;
44-
} catch (\Zend_Json_Exception $exception) {
45-
$formId = null;
49+
$params = [];
50+
$content = $this->_request->getContent();
51+
if ($content) {
52+
$params = $this->serializer->unserialize($content);
4653
}
54+
$formId = isset($params['formId']) ? $params['formId'] : null;
4755
}
4856
$captchaModel = $this->captchaHelper->getCaptcha($formId);
4957
$captchaModel->generate();
5058

5159
$block = $this->_view->getLayout()->createBlock($captchaModel->getBlockName());
5260
$block->setFormId($formId)->setIsAjax(true)->toHtml();
53-
$this->_response->representJson(json_encode(['imgSrc' => $captchaModel->getImgSrc()]));
61+
$this->_response->representJson($this->serializer->serialize(['imgSrc' => $captchaModel->getImgSrc()]));
5462
$this->_actionFlag->set('', self::FLAG_NO_POST_DISPATCH, true);
5563
}
5664
}

app/code/Magento/Captcha/Model/Customer/Plugin/AjaxLogin.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ class AjaxLogin
2626
*/
2727
protected $resultJsonFactory;
2828

29+
/**
30+
* @var \Magento\Framework\Serialize\Serializer\Json
31+
*/
32+
protected $serializer;
33+
2934
/**
3035
* @var array
3136
*/
@@ -36,24 +41,28 @@ class AjaxLogin
3641
* @param SessionManagerInterface $sessionManager
3742
* @param JsonFactory $resultJsonFactory
3843
* @param array $formIds
44+
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
45+
* @throws \RuntimeException
3946
*/
4047
public function __construct(
4148
CaptchaHelper $helper,
4249
SessionManagerInterface $sessionManager,
4350
JsonFactory $resultJsonFactory,
44-
array $formIds
51+
array $formIds,
52+
\Magento\Framework\Serialize\Serializer\Json $serializer = null
4553
) {
4654
$this->helper = $helper;
4755
$this->sessionManager = $sessionManager;
4856
$this->resultJsonFactory = $resultJsonFactory;
57+
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
58+
->get(\Magento\Framework\Serialize\Serializer\Json::class);
4959
$this->formIds = $formIds;
5060
}
5161

5262
/**
5363
* @param \Magento\Customer\Controller\Ajax\Login $subject
5464
* @param \Closure $proceed
5565
* @return $this
56-
* @throws \Zend_Json_Exception
5766
* @SuppressWarnings(PHPMD.NPathComplexity)
5867
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
5968
*/
@@ -70,7 +79,7 @@ public function aroundExecute(
7079
$loginParams = [];
7180
$content = $request->getContent();
7281
if ($content) {
73-
$loginParams = \Zend_Json::decode($content);
82+
$loginParams = $this->serializer->unserialize($content);
7483
}
7584
$username = isset($loginParams['username']) ? $loginParams['username'] : null;
7685
$captchaString = isset($loginParams[$captchaInputName]) ? $loginParams[$captchaInputName] : null;

app/code/Magento/Captcha/Model/ResourceModel/Log.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ protected function _construct()
6666
*
6767
* @param string|null $login
6868
* @return $this
69+
* @throws \Magento\Framework\Exception\LocalizedException
6970
*/
7071
public function logAttempt($login)
7172
{
@@ -78,7 +79,7 @@ public function logAttempt($login)
7879
'count' => 1,
7980
'updated_at' => $this->_coreDate->gmtDate()
8081
],
81-
['count' => new \Zend_Db_Expr('count+1'), 'updated_at']
82+
['count' => new \Zend\Db\Sql\Expression('count+1'), 'updated_at']
8283
);
8384
}
8485
$ip = $this->_remoteAddress->getRemoteAddress();
@@ -91,7 +92,7 @@ public function logAttempt($login)
9192
'count' => 1,
9293
'updated_at' => $this->_coreDate->gmtDate()
9394
],
94-
['count' => new \Zend_Db_Expr('count+1'), 'updated_at']
95+
['count' => new \Zend\Db\Sql\Expression('count+1'), 'updated_at']
9596
);
9697
}
9798
return $this;
@@ -102,6 +103,7 @@ public function logAttempt($login)
102103
*
103104
* @param string $login
104105
* @return $this
106+
* @throws \Magento\Framework\Exception\LocalizedException
105107
*/
106108
public function deleteUserAttempts($login)
107109
{
@@ -126,6 +128,7 @@ public function deleteUserAttempts($login)
126128
* Get count attempts by ip
127129
*
128130
* @return null|int
131+
* @throws \Magento\Framework\Exception\LocalizedException
129132
*/
130133
public function countAttemptsByRemoteAddress()
131134
{
@@ -152,6 +155,7 @@ public function countAttemptsByRemoteAddress()
152155
*
153156
* @param string $login
154157
* @return null|int
158+
* @throws \Magento\Framework\Exception\LocalizedException
155159
*/
156160
public function countAttemptsByUserLogin($login)
157161
{
@@ -176,6 +180,7 @@ public function countAttemptsByUserLogin($login)
176180
* Delete attempts with expired in update_at time
177181
*
178182
* @return void
183+
* @throws \Magento\Framework\Exception\LocalizedException
179184
*/
180185
public function deleteOldAttempts()
181186
{

app/code/Magento/Captcha/Test/Unit/Controller/Refresh/IndexTest.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ class IndexTest extends \PHPUnit_Framework_TestCase
4747
*/
4848
protected $flagMock;
4949

50+
/**
51+
* @var \PHPUnit_Framework_MockObject_MockObject
52+
*/
53+
protected $serializerMock;
54+
5055
/**
5156
* @var \Magento\Captcha\Controller\Refresh\Index
5257
*/
@@ -62,14 +67,25 @@ protected function setUp()
6267
$this->viewMock = $this->getMock(\Magento\Framework\App\ViewInterface::class);
6368
$this->layoutMock = $this->getMock(\Magento\Framework\View\LayoutInterface::class);
6469
$this->flagMock = $this->getMock(\Magento\Framework\App\ActionFlag::class, [], [], '', false);
70+
$this->serializerMock = $this->getMock(
71+
\Magento\Framework\Serialize\Serializer\Json::class,
72+
[],
73+
[],
74+
'',
75+
false
76+
);
6577

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

72-
$this->model = new \Magento\Captcha\Controller\Refresh\Index($this->contextMock, $this->captchaHelperMock);
84+
$this->model = new \Magento\Captcha\Controller\Refresh\Index(
85+
$this->contextMock,
86+
$this->captchaHelperMock,
87+
$this->serializerMock
88+
);
7389
}
7490

7591
/**
@@ -80,6 +96,7 @@ protected function setUp()
8096
public function testExecute($formId, $callsNumber)
8197
{
8298
$content = ['formId' => $formId];
99+
$imgSource = ['imgSrc' => 'source'];
83100

84101
$blockMethods = ['setFormId', 'setIsAjax', 'toHtml'];
85102
$blockMock = $this->getMock(\Magento\Captcha\Block\Captcha::class, $blockMethods, [], '', false);
@@ -97,8 +114,12 @@ public function testExecute($formId, $callsNumber)
97114
$blockMock->expects($this->any())->method('setFormId')->with($formId)->will($this->returnValue($blockMock));
98115
$blockMock->expects($this->any())->method('setIsAjax')->with(true)->will($this->returnValue($blockMock));
99116
$blockMock->expects($this->once())->method('toHtml');
100-
$this->responseMock->expects($this->once())->method('representJson')->with(json_encode(['imgSrc' => 'source']));
117+
$this->responseMock->expects($this->once())->method('representJson')->with(json_encode($imgSource));
101118
$this->flagMock->expects($this->once())->method('set')->with('', 'no-postDispatch', true);
119+
$this->serializerMock->expects($this->exactly($callsNumber))
120+
->method('unserialize')->will($this->returnValue($content));
121+
$this->serializerMock->expects($this->once())
122+
->method('serialize')->will($this->returnValue(json_encode($imgSource)));
102123

103124
$this->model->execute();
104125
}

0 commit comments

Comments
 (0)