Skip to content

Commit c8eff78

Browse files
committed
Merge branch '2.3-develop' into team3-delivery
2 parents 8ccf2be + 827d2d4 commit c8eff78

File tree

23 files changed

+929
-135
lines changed

23 files changed

+929
-135
lines changed

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

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Captcha\Model\Customer\Plugin;
78

89
use Magento\Captcha\Helper\Data as CaptchaHelper;
@@ -81,27 +82,37 @@ public function aroundExecute(
8182
if ($content) {
8283
$loginParams = $this->serializer->unserialize($content);
8384
}
84-
$username = isset($loginParams['username']) ? $loginParams['username'] : null;
85-
$captchaString = isset($loginParams[$captchaInputName]) ? $loginParams[$captchaInputName] : null;
86-
$loginFormId = isset($loginParams[$captchaFormIdField]) ? $loginParams[$captchaFormIdField] : null;
85+
$username = $loginParams['username'] ?? null;
86+
$captchaString = $loginParams[$captchaInputName] ?? null;
87+
$loginFormId = $loginParams[$captchaFormIdField] ?? null;
8788

88-
foreach ($this->formIds as $formId) {
89-
$captchaModel = $this->helper->getCaptcha($formId);
90-
if ($captchaModel->isRequired($username) && !in_array($loginFormId, $this->formIds)) {
91-
$resultJson = $this->resultJsonFactory->create();
92-
return $resultJson->setData(['errors' => true, 'message' => __('Provided form does not exist')]);
93-
}
89+
if (!in_array($loginFormId, $this->formIds) && $this->helper->getCaptcha($loginFormId)->isRequired($username)) {
90+
return $this->returnJsonError(__('Provided form does not exist'));
91+
}
9492

95-
if ($formId == $loginFormId) {
96-
$captchaModel->logAttempt($username);
97-
if (!$captchaModel->isCorrect($captchaString)) {
98-
$this->sessionManager->setUsername($username);
99-
/** @var \Magento\Framework\Controller\Result\Json $resultJson */
100-
$resultJson = $this->resultJsonFactory->create();
101-
return $resultJson->setData(['errors' => true, 'message' => __('Incorrect CAPTCHA')]);
93+
foreach ($this->formIds as $formId) {
94+
if ($formId === $loginFormId) {
95+
$captchaModel = $this->helper->getCaptcha($formId);
96+
if ($captchaModel->isRequired($username)) {
97+
$captchaModel->logAttempt($username);
98+
if (!$captchaModel->isCorrect($captchaString)) {
99+
$this->sessionManager->setUsername($username);
100+
return $this->returnJsonError(__('Incorrect CAPTCHA'));
101+
}
102102
}
103103
}
104104
}
105105
return $proceed();
106106
}
107+
108+
/**
109+
*
110+
* @param \Magento\Framework\Phrase $phrase
111+
* @return \Magento\Framework\Controller\Result\Json
112+
*/
113+
private function returnJsonError(\Magento\Framework\Phrase $phrase): \Magento\Framework\Controller\Result\Json
114+
{
115+
$resultJson = $this->resultJsonFactory->create();
116+
return $resultJson->setData(['errors' => true, 'message' => $phrase]);
117+
}
107118
}

app/code/Magento/Captcha/Model/DefaultModel.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Captcha\Model;
77

8+
use Magento\Captcha\Helper\Data;
9+
810
/**
911
* Implementation of \Zend\Captcha\Image
1012
*
@@ -29,7 +31,7 @@ class DefaultModel extends \Zend\Captcha\Image implements \Magento\Captcha\Model
2931
const DEFAULT_WORD_LENGTH_TO = 5;
3032

3133
/**
32-
* @var \Magento\Captcha\Helper\Data
34+
* @var Data
3335
* @since 100.2.0
3436
*/
3537
protected $captchaData;
@@ -125,8 +127,8 @@ public function getBlockName()
125127
*/
126128
public function isRequired($login = null)
127129
{
128-
if ($this->isUserAuth()
129-
&& !$this->isShownToLoggedInUser()
130+
if (($this->isUserAuth()
131+
&& !$this->isShownToLoggedInUser())
130132
|| !$this->isEnabled()
131133
|| !in_array(
132134
$this->formId,
@@ -431,12 +433,14 @@ public function getWordLen()
431433
*/
432434
private function isShowAlways()
433435
{
434-
if ((string)$this->captchaData->getConfig('mode') == \Magento\Captcha\Helper\Data::MODE_ALWAYS) {
436+
$captchaMode = (string)$this->captchaData->getConfig('mode');
437+
438+
if ($captchaMode === Data::MODE_ALWAYS) {
435439
return true;
436440
}
437441

438-
if ((string)$this->captchaData->getConfig('mode') == \Magento\Captcha\Helper\Data::MODE_AFTER_FAIL
439-
&& $this->getAllowedAttemptsForSameLogin() == 0
442+
if ($captchaMode === Data::MODE_AFTER_FAIL
443+
&& $this->getAllowedAttemptsForSameLogin() === 0
440444
) {
441445
return true;
442446
}

app/code/Magento/Captcha/Test/Unit/Model/Customer/Plugin/AjaxLoginTest.php

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Captcha\Test\Unit\Model\Customer\Plugin;
78

89
class AjaxLoginTest extends \PHPUnit\Framework\TestCase
910
{
1011
/**
11-
* @var \PHPUnit_Framework_MockObject_MockObject
12+
* @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Checkout\Model\Session
1213
*/
1314
protected $sessionManagerMock;
1415

1516
/**
16-
* @var \PHPUnit_Framework_MockObject_MockObject
17+
* @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Captcha\Helper\Data
1718
*/
1819
protected $captchaHelperMock;
1920

2021
/**
21-
* @var \PHPUnit_Framework_MockObject_MockObject
22+
* @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\Controller\Result\JsonFactory
2223
*/
2324
protected $jsonFactoryMock;
2425

@@ -38,12 +39,12 @@ class AjaxLoginTest extends \PHPUnit\Framework\TestCase
3839
protected $requestMock;
3940

4041
/**
41-
* @var \PHPUnit_Framework_MockObject_MockObject
42+
* @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Customer\Controller\Ajax\Login
4243
*/
4344
protected $loginControllerMock;
4445

4546
/**
46-
* @var \PHPUnit_Framework_MockObject_MockObject
47+
* @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\Serialize\Serializer\Json
4748
*/
4849
protected $serializerMock;
4950

@@ -57,6 +58,9 @@ class AjaxLoginTest extends \PHPUnit\Framework\TestCase
5758
*/
5859
protected $model;
5960

61+
/**
62+
* @inheritdoc
63+
*/
6064
protected function setUp()
6165
{
6266
$this->sessionManagerMock = $this->createPartialMock(\Magento\Checkout\Model\Session::class, ['setUsername']);
@@ -72,8 +76,12 @@ protected function setUp()
7276

7377
$this->loginControllerMock->expects($this->any())->method('getRequest')
7478
->will($this->returnValue($this->requestMock));
75-
$this->captchaHelperMock->expects($this->once())->method('getCaptcha')
76-
->with('user_login')->will($this->returnValue($this->captchaMock));
79+
80+
$this->captchaHelperMock
81+
->expects($this->exactly(1))
82+
->method('getCaptcha')
83+
->will($this->returnValue($this->captchaMock));
84+
7785
$this->formIds = ['user_login'];
7886
$this->serializerMock = $this->createMock(\Magento\Framework\Serialize\Serializer\Json::class);
7987

@@ -86,6 +94,9 @@ protected function setUp()
8694
);
8795
}
8896

97+
/**
98+
* Test aroundExecute.
99+
*/
89100
public function testAroundExecute()
90101
{
91102
$username = 'name';
@@ -103,14 +114,24 @@ public function testAroundExecute()
103114
$this->captchaMock->expects($this->once())->method('logAttempt')->with($username);
104115
$this->captchaMock->expects($this->once())->method('isCorrect')->with($captchaString)
105116
->will($this->returnValue(true));
106-
$this->serializerMock->expects(($this->once()))->method('unserialize')->will($this->returnValue($requestData));
117+
$this->serializerMock->expects($this->once())->method('unserialize')->will($this->returnValue($requestData));
107118

108119
$closure = function () {
109120
return 'result';
110121
};
122+
123+
$this->captchaHelperMock
124+
->expects($this->exactly(1))
125+
->method('getCaptcha')
126+
->with('user_login')
127+
->will($this->returnValue($this->captchaMock));
128+
111129
$this->assertEquals('result', $this->model->aroundExecute($this->loginControllerMock, $closure));
112130
}
113131

132+
/**
133+
* Test aroundExecuteIncorrectCaptcha.
134+
*/
114135
public function testAroundExecuteIncorrectCaptcha()
115136
{
116137
$username = 'name';
@@ -128,18 +149,21 @@ public function testAroundExecuteIncorrectCaptcha()
128149
$this->captchaMock->expects($this->once())->method('logAttempt')->with($username);
129150
$this->captchaMock->expects($this->once())->method('isCorrect')
130151
->with($captchaString)->will($this->returnValue(false));
131-
$this->serializerMock->expects(($this->once()))->method('unserialize')->will($this->returnValue($requestData));
152+
$this->serializerMock->expects($this->once())->method('unserialize')->will($this->returnValue($requestData));
132153

133154
$this->sessionManagerMock->expects($this->once())->method('setUsername')->with($username);
134155
$this->jsonFactoryMock->expects($this->once())->method('create')
135156
->will($this->returnValue($this->resultJsonMock));
136157

137-
$this->resultJsonMock->expects($this->once())->method('setData')
138-
->with(['errors' => true, 'message' => __('Incorrect CAPTCHA')])->will($this->returnValue('response'));
158+
$this->resultJsonMock
159+
->expects($this->once())
160+
->method('setData')
161+
->with(['errors' => true, 'message' => __('Incorrect CAPTCHA')])
162+
->will($this->returnSelf());
139163

140164
$closure = function () {
141165
};
142-
$this->assertEquals('response', $this->model->aroundExecute($this->loginControllerMock, $closure));
166+
$this->assertEquals($this->resultJsonMock, $this->model->aroundExecute($this->loginControllerMock, $closure));
143167
}
144168

145169
/**
@@ -151,7 +175,7 @@ public function testAroundExecuteCaptchaIsNotRequired($username, $requestContent
151175
{
152176
$this->requestMock->expects($this->once())->method('getContent')
153177
->will($this->returnValue(json_encode($requestContent)));
154-
$this->serializerMock->expects(($this->once()))->method('unserialize')
178+
$this->serializerMock->expects($this->once())->method('unserialize')
155179
->will($this->returnValue($requestContent));
156180

157181
$this->captchaMock->expects($this->once())->method('isRequired')->with($username)
@@ -168,16 +192,39 @@ public function testAroundExecuteCaptchaIsNotRequired($username, $requestContent
168192
/**
169193
* @return array
170194
*/
171-
public function aroundExecuteCaptchaIsNotRequired()
195+
public function aroundExecuteCaptchaIsNotRequired(): array
172196
{
173197
return [
174198
[
175199
'username' => 'name',
176200
'requestData' => ['username' => 'name', 'captcha_string' => 'string'],
177201
],
202+
[
203+
'username' => 'name',
204+
'requestData' =>
205+
[
206+
'username' => 'name',
207+
'captcha_string' => 'string',
208+
'captcha_form_id' => $this->formIds[0]
209+
],
210+
],
178211
[
179212
'username' => null,
180-
'requestData' => ['captcha_string' => 'string'],
213+
'requestData' =>
214+
[
215+
'username' => null,
216+
'captcha_string' => 'string',
217+
'captcha_form_id' => $this->formIds[0]
218+
],
219+
],
220+
[
221+
'username' => 'name',
222+
'requestData' =>
223+
[
224+
'username' => 'name',
225+
'captcha_string' => 'string',
226+
'captcha_form_id' => null
227+
],
181228
],
182229
];
183230
}

app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public function imagePreprocessing($data)
280280
continue;
281281
}
282282

283-
$data[$attributeCode] = false;
283+
$data[$attributeCode] = '';
284284
}
285285

286286
return $data;

app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class Helper
104104
* @param \Magento\Backend\Helper\Js $jsHelper
105105
* @param \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter
106106
* @param CustomOptionFactory|null $customOptionFactory
107-
* @param ProductLinkFactory |null $productLinkFactory
107+
* @param ProductLinkFactory|null $productLinkFactory
108108
* @param ProductRepositoryInterface|null $productRepository
109109
* @param LinkTypeProvider|null $linkTypeProvider
110110
* @param AttributeFilter|null $attributeFilter
@@ -159,6 +159,7 @@ public function initializeFromData(\Magento\Catalog\Model\Product $product, arra
159159
}
160160

161161
$productData = $this->normalize($productData);
162+
$productData = $this->convertSpecialFromDateStringToObject($productData);
162163

163164
if (!empty($productData['is_downloadable'])) {
164165
$productData['product_has_weight'] = 0;
@@ -452,4 +453,19 @@ private function fillProductOptions(Product $product, array $productOptions)
452453

453454
return $product->setOptions($customOptions);
454455
}
456+
457+
/**
458+
* Convert string date presentation into object
459+
*
460+
* @param array $productData
461+
* @return array
462+
*/
463+
private function convertSpecialFromDateStringToObject($productData)
464+
{
465+
if (isset($productData['special_from_date']) && $productData['special_from_date'] != '') {
466+
$productData['special_from_date'] = new \DateTime($productData['special_from_date']);
467+
}
468+
469+
return $productData;
470+
}
455471
}

app/code/Magento/Catalog/Model/Category/Attribute/Backend/Image.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function beforeSave($object)
106106
$object->setData($this->additionalData . $attributeName, $value);
107107
$object->setData($attributeName, $imageName);
108108
} elseif (!is_string($value)) {
109-
$object->setData($attributeName, '');
109+
$object->setData($attributeName, null);
110110
}
111111

112112
return parent::beforeSave($object);

0 commit comments

Comments
 (0)