Skip to content

Commit 83e8dae

Browse files
committed
Merge remote-tracking branch 'mainline/2.2-develop' into MAGETWO-89238-2.2
2 parents fdfa5c6 + 38d7977 commit 83e8dae

File tree

47 files changed

+1355
-291
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1355
-291
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: 53 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

@@ -72,8 +73,12 @@ protected function setUp()
7273

7374
$this->loginControllerMock->expects($this->any())->method('getRequest')
7475
->will($this->returnValue($this->requestMock));
75-
$this->captchaHelperMock->expects($this->once())->method('getCaptcha')
76-
->with('user_login')->will($this->returnValue($this->captchaMock));
76+
77+
$this->captchaHelperMock
78+
->expects($this->exactly(1))
79+
->method('getCaptcha')
80+
->will($this->returnValue($this->captchaMock));
81+
7782
$this->formIds = ['user_login'];
7883
$this->serializerMock = $this->createMock(\Magento\Framework\Serialize\Serializer\Json::class);
7984

@@ -103,11 +108,18 @@ public function testAroundExecute()
103108
$this->captchaMock->expects($this->once())->method('logAttempt')->with($username);
104109
$this->captchaMock->expects($this->once())->method('isCorrect')->with($captchaString)
105110
->will($this->returnValue(true));
106-
$this->serializerMock->expects(($this->once()))->method('unserialize')->will($this->returnValue($requestData));
111+
$this->serializerMock->expects($this->once())->method('unserialize')->will($this->returnValue($requestData));
107112

108113
$closure = function () {
109114
return 'result';
110115
};
116+
117+
$this->captchaHelperMock
118+
->expects($this->exactly(1))
119+
->method('getCaptcha')
120+
->with('user_login')
121+
->will($this->returnValue($this->captchaMock));
122+
111123
$this->assertEquals('result', $this->model->aroundExecute($this->loginControllerMock, $closure));
112124
}
113125

@@ -128,18 +140,21 @@ public function testAroundExecuteIncorrectCaptcha()
128140
$this->captchaMock->expects($this->once())->method('logAttempt')->with($username);
129141
$this->captchaMock->expects($this->once())->method('isCorrect')
130142
->with($captchaString)->will($this->returnValue(false));
131-
$this->serializerMock->expects(($this->once()))->method('unserialize')->will($this->returnValue($requestData));
143+
$this->serializerMock->expects($this->once())->method('unserialize')->will($this->returnValue($requestData));
132144

133145
$this->sessionManagerMock->expects($this->once())->method('setUsername')->with($username);
134146
$this->jsonFactoryMock->expects($this->once())->method('create')
135147
->will($this->returnValue($this->resultJsonMock));
136148

137-
$this->resultJsonMock->expects($this->once())->method('setData')
138-
->with(['errors' => true, 'message' => __('Incorrect CAPTCHA')])->will($this->returnValue('response'));
149+
$this->resultJsonMock
150+
->expects($this->once())
151+
->method('setData')
152+
->with(['errors' => true, 'message' => __('Incorrect CAPTCHA')])
153+
->will($this->returnSelf());
139154

140155
$closure = function () {
141156
};
142-
$this->assertEquals('response', $this->model->aroundExecute($this->loginControllerMock, $closure));
157+
$this->assertEquals($this->resultJsonMock, $this->model->aroundExecute($this->loginControllerMock, $closure));
143158
}
144159

145160
/**
@@ -151,7 +166,7 @@ public function testAroundExecuteCaptchaIsNotRequired($username, $requestContent
151166
{
152167
$this->requestMock->expects($this->once())->method('getContent')
153168
->will($this->returnValue(json_encode($requestContent)));
154-
$this->serializerMock->expects(($this->once()))->method('unserialize')
169+
$this->serializerMock->expects($this->once())->method('unserialize')
155170
->will($this->returnValue($requestContent));
156171

157172
$this->captchaMock->expects($this->once())->method('isRequired')->with($username)
@@ -168,16 +183,39 @@ public function testAroundExecuteCaptchaIsNotRequired($username, $requestContent
168183
/**
169184
* @return array
170185
*/
171-
public function aroundExecuteCaptchaIsNotRequired()
186+
public function aroundExecuteCaptchaIsNotRequired(): array
172187
{
173188
return [
174189
[
175190
'username' => 'name',
176191
'requestData' => ['username' => 'name', 'captcha_string' => 'string'],
177192
],
193+
[
194+
'username' => 'name',
195+
'requestData' =>
196+
[
197+
'username' => 'name',
198+
'captcha_string' => 'string',
199+
'captcha_form_id' => $this->formIds[0]
200+
],
201+
],
178202
[
179203
'username' => null,
180-
'requestData' => ['captcha_string' => 'string'],
204+
'requestData' =>
205+
[
206+
'username' => null,
207+
'captcha_string' => 'string',
208+
'captcha_form_id' => $this->formIds[0]
209+
],
210+
],
211+
[
212+
'username' => 'name',
213+
'requestData' =>
214+
[
215+
'username' => 'name',
216+
'captcha_string' => 'string',
217+
'captcha_form_id' => null
218+
],
181219
],
182220
];
183221
}

app/code/Magento/Catalog/Controller/Product/Compare/Add.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ public function execute()
3636
$productName = $this->_objectManager->get(
3737
\Magento\Framework\Escaper::class
3838
)->escapeHtml($product->getName());
39-
$this->messageManager->addSuccess(__('You added product %1 to the comparison list.', $productName));
39+
$this->messageManager->addComplexSuccessMessage(
40+
'addCompareSuccessMessage',
41+
[
42+
'product_name' => $productName,
43+
'compare_list_url' => $this->_url->getUrl('catalog/product_compare')
44+
]
45+
);
46+
4047
$this->_eventManager->dispatch('catalog_product_compare_add_product', ['product' => $product]);
4148
}
4249

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Price/DefaultPrice.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ protected function prepareFinalPriceDataForType($entityIds, $type)
307307
$query = $select->insertFromSelect($finalPriceTable->getTableName(), [], false);
308308
$this->getConnection()->query($query);
309309

310-
$this->applyDiscountPrices($finalPriceTable);
310+
$this->modifyPriceIndex($finalPriceTable);
311311

312312
return $this;
313313
}
@@ -512,12 +512,12 @@ protected function _prepareCustomOptionPriceTable()
512512
}
513513

514514
/**
515-
* Apply discount prices to final price index table.
515+
* Modify data in price index table.
516516
*
517517
* @param IndexTableStructure $finalPriceTable
518518
* @return void
519519
*/
520-
private function applyDiscountPrices(IndexTableStructure $finalPriceTable)
520+
private function modifyPriceIndex(IndexTableStructure $finalPriceTable)
521521
{
522522
foreach ($this->priceModifiers as $priceModifier) {
523523
$priceModifier->modifyPrice($finalPriceTable);

app/code/Magento/Catalog/etc/frontend/di.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@
7979
<argument name="typeId" xsi:type="string">recently_compared_product</argument>
8080
</arguments>
8181
</virtualType>
82+
<type name="Magento\Framework\View\Element\Message\MessageConfigurationsPool">
83+
<arguments>
84+
<argument name="configurationsMap" xsi:type="array">
85+
<item name="addCompareSuccessMessage" xsi:type="array">
86+
<item name="renderer" xsi:type="const">\Magento\Framework\View\Element\Message\Renderer\BlockRenderer::CODE</item>
87+
<item name="data" xsi:type="array">
88+
<item name="template" xsi:type="string">Magento_Catalog::messages/addCompareSuccessMessage.phtml</item>
89+
</item>
90+
</item>
91+
</argument>
92+
</arguments>
93+
</type>
8294
<type name="Magento\Framework\App\ResourceConnection">
8395
<plugin name="get_catalog_category_product_index_table_name" type="Magento\Catalog\Model\Indexer\Category\Product\Plugin\TableResolver"/>
8496
</type>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
// @codingStandardsIgnoreFile
7+
/** @var \Magento\Framework\View\Element\Template $block */
8+
?>
9+
<?= $block->escapeHtml(__(
10+
'You added product %1 to the <a href="%2">comparison list</a>.',
11+
$block->getData('product_name'),
12+
$block->getData('compare_list_url')),
13+
['a']
14+
);

app/code/Magento/Catalog/view/frontend/web/js/storage-manager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ define([
129129
},
130130

131131
/**
132-
* Prepare storages congfig.
132+
* Prepare storages config.
133133
*
134134
* @returns {Object} Chainable.
135135
*/

0 commit comments

Comments
 (0)