Skip to content

Commit b233f52

Browse files
author
Magento CICD
authored
merge magento/2.3-develop into magento-borg/MAGETWO-91595-image-pdp
2 parents f968852 + e22b7a2 commit b233f52

File tree

31 files changed

+446
-47
lines changed

31 files changed

+446
-47
lines changed
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Captcha\Test\Unit\Observer;
9+
10+
use Magento\Captcha\Model\DefaultModel as CaptchaModel;
11+
use Magento\Captcha\Observer\CheckRegisterCheckoutObserver;
12+
use Magento\Captcha\Helper\Data as CaptchaDataHelper;
13+
use Magento\Framework\App\Action\Action;
14+
use Magento\Framework\App\ActionFlag;
15+
use Magento\Captcha\Observer\CaptchaStringResolver;
16+
use Magento\Checkout\Model\Type\Onepage;
17+
use Magento\Framework\App\Request\Http;
18+
use Magento\Framework\App\Response\Http as HttpResponse;
19+
use Magento\Framework\Event\Observer;
20+
use Magento\Framework\Json\Helper\Data as JsonHelper;
21+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
22+
use Magento\Quote\Model\Quote;
23+
24+
/**
25+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
26+
*/
27+
class CheckRegisterCheckoutObserverTest extends \PHPUnit\Framework\TestCase
28+
{
29+
const FORM_ID = 'register_during_checkout';
30+
31+
/**
32+
* @var CheckRegisterCheckoutObserver
33+
*/
34+
private $checkRegisterCheckoutObserver;
35+
36+
/**
37+
* @var ObjectManager
38+
*/
39+
private $objectManager;
40+
41+
/**
42+
* @var Observer
43+
*/
44+
private $observer;
45+
46+
/**
47+
* @var HttpResponse|\PHPUnit_Framework_MockObject_MockObject
48+
*/
49+
private $responseMock;
50+
51+
/**
52+
* @var HttpResponse|\PHPUnit_Framework_MockObject_MockObject
53+
*/
54+
private $requestMock;
55+
56+
/**
57+
* @var ActionFlag|\PHPUnit_Framework_MockObject_MockObject
58+
*/
59+
private $actionFlagMock;
60+
61+
/**
62+
* @var CaptchaStringResolver|\PHPUnit_Framework_MockObject_MockObject
63+
*/
64+
private $captchaStringResolverMock;
65+
66+
/**
67+
* @var JsonHelper|\PHPUnit_Framework_MockObject_MockObject
68+
*/
69+
private $jsonHelperMock;
70+
71+
/**
72+
* @var CaptchaModel|\PHPUnit_Framework_MockObject_MockObject
73+
*/
74+
private $captchaModelMock;
75+
76+
/**
77+
* @var Quote|\PHPUnit_Framework_MockObject_MockObject
78+
*/
79+
private $quoteModelMock;
80+
81+
/**
82+
* @var Action|\PHPUnit_Framework_MockObject_MockObject
83+
*/
84+
private $controllerMock;
85+
86+
protected function setUp()
87+
{
88+
$onepageModelTypeMock = $this->createMock(Onepage::class);
89+
$captchaHelperMock = $this->createMock(CaptchaDataHelper::class);
90+
$this->objectManager = new ObjectManager($this);
91+
$this->actionFlagMock = $this->createMock(ActionFlag::class);
92+
$this->captchaStringResolverMock = $this->createMock(CaptchaStringResolver::class);
93+
$this->captchaModelMock = $this->createMock(CaptchaModel::class);
94+
$this->quoteModelMock = $this->createMock(Quote::class);
95+
$this->controllerMock = $this->createMock(Action::class);
96+
$this->requestMock = $this->createMock(Http::class);
97+
$this->responseMock = $this->createMock(HttpResponse::class);
98+
$this->observer = new Observer(['controller_action' => $this->controllerMock]);
99+
$this->jsonHelperMock = $this->createMock(JsonHelper::class);
100+
101+
$this->checkRegisterCheckoutObserver = $this->objectManager->getObject(
102+
CheckRegisterCheckoutObserver::class,
103+
[
104+
'helper' => $captchaHelperMock,
105+
'actionFlag' => $this->actionFlagMock,
106+
'captchaStringResolver' => $this->captchaStringResolverMock,
107+
'typeOnepage' => $onepageModelTypeMock,
108+
'jsonHelper' => $this->jsonHelperMock
109+
]
110+
);
111+
112+
$captchaHelperMock->expects($this->once())
113+
->method('getCaptcha')
114+
->with(self::FORM_ID)
115+
->willReturn($this->captchaModelMock);
116+
$onepageModelTypeMock->expects($this->once())
117+
->method('getQuote')
118+
->willReturn($this->quoteModelMock);
119+
}
120+
121+
public function testCheckRegisterCheckoutForGuest()
122+
{
123+
$this->quoteModelMock->expects($this->once())
124+
->method('getCheckoutMethod')
125+
->willReturn(Onepage::METHOD_GUEST);
126+
$this->captchaModelMock->expects($this->never())
127+
->method('isRequired');
128+
129+
$this->checkRegisterCheckoutObserver->execute($this->observer);
130+
}
131+
132+
public function testCheckRegisterCheckoutWithNoCaptchaRequired()
133+
{
134+
$this->quoteModelMock->expects($this->once())
135+
->method('getCheckoutMethod')
136+
->willReturn(Onepage::METHOD_REGISTER);
137+
$this->captchaModelMock->expects($this->once())
138+
->method('isRequired')
139+
->willReturn(false);
140+
$this->captchaModelMock->expects($this->never())
141+
->method('isCorrect');
142+
143+
$this->checkRegisterCheckoutObserver->execute($this->observer);
144+
}
145+
146+
public function testCheckRegisterCheckoutWithIncorrectCaptcha()
147+
{
148+
$captchaValue = 'some_word';
149+
$encodedJsonValue = '{}';
150+
151+
$this->quoteModelMock->expects($this->once())
152+
->method('getCheckoutMethod')
153+
->willReturn(Onepage::METHOD_REGISTER);
154+
$this->captchaModelMock->expects($this->once())
155+
->method('isRequired')
156+
->willReturn(true);
157+
$this->controllerMock->expects($this->once())
158+
->method('getRequest')
159+
->willReturn($this->requestMock);
160+
$this->controllerMock->expects($this->once())
161+
->method('getResponse')
162+
->willReturn($this->responseMock);
163+
$this->controllerMock->expects($this->once())
164+
->method('getResponse')
165+
->willReturn($this->responseMock);
166+
$this->captchaStringResolverMock->expects($this->once())
167+
->method('resolve')
168+
->with($this->requestMock, self::FORM_ID)
169+
->willReturn($captchaValue);
170+
$this->captchaModelMock->expects($this->once())
171+
->method('isCorrect')
172+
->with($captchaValue)
173+
->willReturn(false);
174+
$this->actionFlagMock->expects($this->once())
175+
->method('set')
176+
->with('', Action::FLAG_NO_DISPATCH, true);
177+
$this->jsonHelperMock->expects($this->once())
178+
->method('jsonEncode')
179+
->willReturn($encodedJsonValue);
180+
$this->responseMock->expects($this->once())
181+
->method('representJson')
182+
->with($encodedJsonValue);
183+
184+
$this->checkRegisterCheckoutObserver->execute($this->observer);
185+
}
186+
187+
public function testCheckRegisterCheckoutWithCorrectCaptcha()
188+
{
189+
$this->quoteModelMock->expects($this->once())
190+
->method('getCheckoutMethod')
191+
->willReturn(Onepage::METHOD_REGISTER);
192+
$this->captchaModelMock->expects($this->once())
193+
->method('isRequired')
194+
->willReturn(true);
195+
$this->controllerMock->expects($this->once())
196+
->method('getRequest')
197+
->willReturn($this->requestMock);
198+
$this->captchaStringResolverMock->expects($this->once())
199+
->method('resolve')
200+
->with($this->requestMock, self::FORM_ID)
201+
->willReturn('some_word');
202+
$this->captchaModelMock->expects($this->once())
203+
->method('isCorrect')
204+
->with('some_word')
205+
->willReturn(true);
206+
$this->actionFlagMock->expects($this->never())
207+
->method('set');
208+
209+
$this->checkRegisterCheckoutObserver->execute($this->observer);
210+
}
211+
}

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Catalog\Controller\Adminhtml;
79

10+
use Magento\Store\Model\Store;
11+
812
/**
913
* Catalog category controller
1014
*/
@@ -44,7 +48,7 @@ public function __construct(
4448
protected function _initCategory($getRootInstead = false)
4549
{
4650
$categoryId = $this->resolveCategoryId();
47-
$storeId = (int)$this->getRequest()->getParam('store');
51+
$storeId = $this->resolveStoreId();
4852
$category = $this->_objectManager->create(\Magento\Catalog\Model\Category::class);
4953
$category->setStoreId($storeId);
5054

@@ -70,7 +74,7 @@ protected function _initCategory($getRootInstead = false)
7074
$this->_objectManager->get(\Magento\Framework\Registry::class)->register('category', $category);
7175
$this->_objectManager->get(\Magento\Framework\Registry::class)->register('current_category', $category);
7276
$this->_objectManager->get(\Magento\Cms\Model\Wysiwyg\Config::class)
73-
->setStoreId($this->getRequest()->getParam('store'));
77+
->setStoreId($storeId);
7478
return $category;
7579
}
7680

@@ -79,13 +83,28 @@ protected function _initCategory($getRootInstead = false)
7983
*
8084
* @return int
8185
*/
82-
private function resolveCategoryId()
86+
private function resolveCategoryId() : int
8387
{
8488
$categoryId = (int)$this->getRequest()->getParam('id', false);
8589

8690
return $categoryId ?: (int)$this->getRequest()->getParam('entity_id', false);
8791
}
8892

93+
/**
94+
* Resolve store id
95+
*
96+
* Tries to take store id from store HTTP parameter
97+
* @see Store
98+
*
99+
* @return int
100+
*/
101+
private function resolveStoreId() : int
102+
{
103+
$storeId = (int)$this->getRequest()->getParam('store', false);
104+
105+
return $storeId ?: (int)$this->getRequest()->getParam('store_id', Store::DEFAULT_STORE_ID);
106+
}
107+
89108
/**
90109
* Build response for ajax request
91110
*

app/code/Magento/Rule/Model/Action/AbstractAction.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,16 @@ public function __construct(
4949

5050
$this->loadAttributeOptions()->loadOperatorOptions()->loadValueOptions();
5151

52-
foreach (array_keys($this->getAttributeOption()) as $attr) {
53-
$this->setAttribute($attr);
54-
break;
52+
$attributes = $this->getAttributeOption();
53+
if ($attributes) {
54+
reset($attributes);
55+
$this->setAttribute(key($attributes));
5556
}
56-
foreach (array_keys($this->getOperatorOption()) as $operator) {
57-
$this->setOperator($operator);
58-
break;
57+
58+
$operators = $this->getOperatorOption();
59+
if ($operators) {
60+
reset($operators);
61+
$this->setOperator(key($operators));
5962
}
6063
}
6164

app/code/Magento/Rule/Model/Condition/Combine.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ public function __construct(Context $context, array $data = [])
4646
$this->loadAggregatorOptions();
4747
$options = $this->getAggregatorOptions();
4848
if ($options) {
49-
foreach (array_keys($options) as $aggregator) {
50-
$this->setAggregator($aggregator);
51-
break;
52-
}
49+
reset($options);
50+
$this->setAggregator(key($options));
5351
}
5452
}
5553

@@ -90,9 +88,10 @@ public function getAggregatorName()
9088
public function getAggregatorElement()
9189
{
9290
if ($this->getAggregator() === null) {
93-
foreach (array_keys($this->getAggregatorOption()) as $key) {
94-
$this->setAggregator($key);
95-
break;
91+
$options = $this->getAggregatorOption();
92+
if ($options) {
93+
reset($options);
94+
$this->setAggregator(key($options));
9695
}
9796
}
9897
return $this->getForm()->addField(

app/code/Magento/Rule/view/adminhtml/web/conditions-data-normalizer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ define([
1414
*/
1515
var ConditionsDataNormalizer = function () {
1616
this.patterns = {
17-
validate: /^[a-z0-9_-][a-z0-9_-]*(?:\[(?:\d*|[a-z0-9_-]+)\])*$/i,
18-
key: /[a-z0-9_-]+|(?=\[\])/gi,
17+
validate: /^[a-z0-9_.-][a-z0-9_.-]*(?:\[(?:\d*|[a-z0-9_.-]+)\])*$/i,
18+
key: /[a-z0-9_.-]+|(?=\[\])/gi,
1919
push: /^$/,
2020
fixed: /^\d+$/,
21-
named: /^[a-z0-9_-]+$/i
21+
named: /^[a-z0-9_.-]+$/i
2222
};
2323
};
2424

app/design/frontend/Magento/luma/Magento_Catalog/web/css/source/module/_listings.less

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,11 @@
167167
.column.main {
168168
.product {
169169
&-items {
170-
margin-left: -@indent__base;
170+
margin-left: 0;
171171
}
172172

173173
&-item {
174-
padding-left: @indent__base;
174+
padding-left: 0;
175175
}
176176
}
177177
}

dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Catalog/ActionGroup/AdminCategoryActionGroup.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,26 @@
190190
<see selector="{{AdminCategoryBasicFieldSection.FieldError('uid')}}" userInput="This is a required field." stepKey="seeErrorMessage"/>
191191
</actionGroup>
192192

193+
194+
<actionGroup name="switchCategoryStoreView">
195+
<arguments>
196+
<argument name="Store"/>
197+
<argument name="CatName"/>
198+
</arguments>
199+
<amOnPage url="{{AdminCategoryPage.page}}" stepKey="amOnCategoryPage"/>
200+
<waitForPageLoad stepKey="waitForPageLoad1"/>
201+
<click selector="{{AdminCategorySidebarTreeSection.categoryInTree(CatName)}}" stepKey="navigateToCreatedCategory" />
202+
<waitForPageLoad stepKey="waitForPageLoad2"/>
203+
<waitForLoadingMaskToDisappear stepKey="waitForSpinner"/>
204+
<scrollToTopOfPage stepKey="scrollToToggle"/>
205+
<click selector="{{AdminCategoryMainActionsSection.CategoryStoreViewDropdownToggle}}" stepKey="openStoreViewDropDown"/>
206+
<click selector="{{AdminCategoryMainActionsSection.CategoryStoreViewOption(Store)}}" stepKey="selectStoreView"/>
207+
<waitForPageLoad stepKey="waitForPageLoad3"/>
208+
<waitForLoadingMaskToDisappear stepKey="waitForSpinner2"/>
209+
<click selector="{{AdminCategoryMainActionsSection.CategoryStoreViewModalAccept}}" stepKey="selectStoreViewAccept"/>
210+
<waitForPageLoad stepKey="waitForStoreViewChangeLoad"/>
211+
</actionGroup>
212+
193213
<actionGroup name="navigateToCreatedCategory">
194214
<arguments>
195215
<argument name="Category"/>

dev/tests/acceptance/tests/functional/Magento/FunctionalTest/Catalog/Section/AdminCategoryBasicFieldSection.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111
<section name="AdminCategoryBasicFieldSection">
1212
<element name="IncludeInMenu" type="checkbox" selector="input[name='include_in_menu']"/>
1313
<element name="includeInMenuLabel" type="text" selector="input[name='include_in_menu']+label"/>
14+
<element name="includeInMenuUseDefault" type="checkbox" selector="input[name='use_default[include_in_menu]']"/>
1415
<element name="EnableCategory" type="checkbox" selector="input[name='is_active']"/>
1516
<element name="enableCategoryLabel" type="text" selector="input[name='is_active']+label"/>
17+
<element name="enableUseDefault" type="checkbox" selector="input[name='use_default[is_active]']"/>
1618
<element name="CategoryNameInput" type="input" selector="input[name='name']"/>
19+
<element name="categoryNameUseDefault" type="checkbox" selector="input[name='use_default[name]']"/>
1720
<element name="ContentTab" type="input" selector="input[name='name']"/>
1821
<element name="FieldError" type="text" selector=".admin__field-error[data-bind='attr: {for: {{field}}}, text: error']" parameterized="true"/>
1922
</section>

0 commit comments

Comments
 (0)