Skip to content

Commit eb9042c

Browse files
committed
Merge branch '2.2-develop' of https://github.com/magento/magento2ce into MAGETWO-86125
2 parents d325d84 + 1ff3ca5 commit eb9042c

File tree

73 files changed

+974
-123
lines changed

Some content is hidden

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

73 files changed

+974
-123
lines changed

app/code/Magento/Backend/App/AbstractAction.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ public function dispatch(\Magento\Framework\App\RequestInterface $request)
217217
$this->_view->loadLayout(['default', 'adminhtml_denied'], true, true, false);
218218
$this->_view->renderLayout();
219219
$this->_request->setDispatched(true);
220+
220221
return $this->_response;
221222
}
222223

@@ -226,6 +227,11 @@ public function dispatch(\Magento\Framework\App\RequestInterface $request)
226227

227228
$this->_processLocaleSettings();
228229

230+
// Need to preload isFirstPageAfterLogin (see https://github.com/magento/magento2/issues/15510)
231+
if ($this->_auth->isLoggedIn()) {
232+
$this->_auth->getAuthStorage()->isFirstPageAfterLogin();
233+
}
234+
229235
return parent::dispatch($request);
230236
}
231237

app/code/Magento/Backend/Block/Widget/Grid/Column/Renderer/Currency.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,7 @@ public function __construct(
6868
$this->_storeManager = $storeManager;
6969
$this->_currencyLocator = $currencyLocator;
7070
$this->_localeCurrency = $localeCurrency;
71-
$defaultBaseCurrencyCode = $this->_scopeConfig->getValue(
72-
\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_BASE,
73-
'default'
74-
);
71+
$defaultBaseCurrencyCode = $currencyLocator->getDefaultCurrency($this->_request);
7572
$this->_defaultBaseCurrency = $currencyFactory->create()->load($defaultBaseCurrencyCode);
7673
}
7774

app/code/Magento/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Options/Type/Checkbox.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Checkbox extends \Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Op
1717
/**
1818
* @var string
1919
*/
20-
protected $_template = 'product/composite/fieldset/options/type/checkbox.phtml';
20+
protected $_template = 'Magento_Bundle::product/composite/fieldset/options/type/checkbox.phtml';
2121

2222
/**
2323
* @param string $elementId

app/code/Magento/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Options/Type/Multi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Multi extends \Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Optio
1717
/**
1818
* @var string
1919
*/
20-
protected $_template = 'product/composite/fieldset/options/type/multi.phtml';
20+
protected $_template = 'Magento_Bundle::product/composite/fieldset/options/type/multi.phtml';
2121

2222
/**
2323
* @param string $elementId

app/code/Magento/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Options/Type/Radio.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Radio extends \Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Optio
1717
/**
1818
* @var string
1919
*/
20-
protected $_template = 'product/composite/fieldset/options/type/radio.phtml';
20+
protected $_template = 'Magento_Bundle::product/composite/fieldset/options/type/radio.phtml';
2121

2222
/**
2323
* @param string $elementId

app/code/Magento/Bundle/Block/Adminhtml/Catalog/Product/Composite/Fieldset/Options/Type/Select.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Select extends \Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Opti
1717
/**
1818
* @var string
1919
*/
20-
protected $_template = 'product/composite/fieldset/options/type/select.phtml';
20+
protected $_template = 'Magento_Bundle::product/composite/fieldset/options/type/select.phtml';
2121

2222
/**
2323
* @param string $elementId

app/code/Magento/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Bundle extends \Magento\Backend\Block\Widget implements \Magento\Backend\B
2020
/**
2121
* @var string
2222
*/
23-
protected $_template = 'product/edit/bundle.phtml';
23+
protected $_template = 'Magento_Bundle::product/edit/bundle.phtml';
2424

2525
/**
2626
* Core registry

app/code/Magento/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/Option.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Option extends \Magento\Backend\Block\Widget
2626
/**
2727
* @var string
2828
*/
29-
protected $_template = 'product/edit/bundle/option.phtml';
29+
protected $_template = 'Magento_Bundle::product/edit/bundle/option.phtml';
3030

3131
/**
3232
* Core registry

app/code/Magento/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/Option/Search.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Search extends \Magento\Backend\Block\Widget
1515
/**
1616
* @var string
1717
*/
18-
protected $_template = 'product/edit/bundle/option/search.phtml';
18+
protected $_template = 'Magento_Bundle::product/edit/bundle/option/search.phtml';
1919

2020
/**
2121
* @return void

app/code/Magento/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/Option/Selection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Selection extends \Magento\Backend\Block\Widget
1515
/**
1616
* @var string
1717
*/
18-
protected $_template = 'product/edit/bundle/option/selection.phtml';
18+
protected $_template = 'Magento_Bundle::product/edit/bundle/option/selection.phtml';
1919

2020
/**
2121
* Catalog data

app/code/Magento/Bundle/Block/Catalog/Product/View/Type/Bundle/Option/Checkbox.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ class Checkbox extends \Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Op
1616
/**
1717
* @var string
1818
*/
19-
protected $_template = 'catalog/product/view/type/bundle/option/checkbox.phtml';
19+
protected $_template = 'Magento_Bundle::catalog/product/view/type/bundle/option/checkbox.phtml';
2020
}

app/code/Magento/Bundle/Block/Catalog/Product/View/Type/Bundle/Option/Multi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Multi extends \Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Optio
1616
/**
1717
* @var string
1818
*/
19-
protected $_template = 'catalog/product/view/type/bundle/option/multi.phtml';
19+
protected $_template = 'Magento_Bundle::catalog/product/view/type/bundle/option/multi.phtml';
2020

2121
/**
2222
* @inheritdoc

app/code/Magento/Bundle/Block/Catalog/Product/View/Type/Bundle/Option/Radio.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ class Radio extends \Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Optio
1616
/**
1717
* @var string
1818
*/
19-
protected $_template = 'catalog/product/view/type/bundle/option/radio.phtml';
19+
protected $_template = 'Magento_Bundle::catalog/product/view/type/bundle/option/radio.phtml';
2020
}

app/code/Magento/Bundle/Block/Catalog/Product/View/Type/Bundle/Option/Select.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ class Select extends \Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Opti
1616
/**
1717
* @var string
1818
*/
19-
protected $_template = 'catalog/product/view/type/bundle/option/select.phtml';
19+
protected $_template = 'Magento_Bundle::catalog/product/view/type/bundle/option/select.phtml';
2020
}

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
}

0 commit comments

Comments
 (0)