Skip to content

Commit c9d1bec

Browse files
author
Stanislav Idolov
authored
🔃 [EngCom] Public Pull Requests - 2.2-develop
Accepted Public Pull Requests: - #18559: [Backport] Covering the AssignOrderToCustomerObserver by Unit Test (by @gelanivishal) - #18564: [Backport] Empty option Label should always be blank even if attribute is required (by @gelanivishal) - #18556: [Backport] Fixed typo from filed to field (by @gelanivishal) - #18554: [Backport] throw exception InvalidArgumentException during validate scheme (by @gelanivishal) - #18552: [Backport] Added validation on maximum quantity allowed in shopping cart (by @gelanivishal) - #18495: [Backport] Checkout - Fix "Cannot read property 'code' on undefined" issue (by @ihor-sviziev) Fixed GitHub Issues: - #14555: Communication's component validator does not propagate exceptions, obscuring the cause of the error (reported by @nikita2206) has been fixed in #18554 by @gelanivishal in 2.2-develop branch Related commits: 1. 3109909 2. 9afdfee 3. 791609c 4. beeecaf 5. 7e38326 6. a20968d 7. 2f2cafe 8. 72b31c9 9. a7cdae0 10. 74c6bfd - #18477: Set maximum Qty Allowed in Shopping Cart is 0 still allow adding to cart (reported by @duongdiep212) has been fixed in #18552 by @gelanivishal in 2.2-develop branch Related commits: 1. db4ac89 - #18164: Checkout - Cannot read property 'code' of undefined (reported by @bruno-serfe) has been fixed in #18495 by @ihor-sviziev in 2.2-develop branch Related commits: 1. e7f70ab 2. 25e3cfe
2 parents 4a6b81f + d9c3a92 commit c9d1bec

File tree

8 files changed

+199
-5
lines changed

8 files changed

+199
-5
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Category.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ public function changeParent(
920920
$childrenCount = $this->getChildrenCount($category->getId()) + 1;
921921
$table = $this->getEntityTable();
922922
$connection = $this->getConnection();
923-
$levelFiled = $connection->quoteIdentifier('level');
923+
$levelField = $connection->quoteIdentifier('level');
924924
$pathField = $connection->quoteIdentifier('path');
925925

926926
/**
@@ -960,7 +960,7 @@ public function changeParent(
960960
$newPath . '/'
961961
) . ')'
962962
),
963-
'level' => new \Zend_Db_Expr($levelFiled . ' + ' . $levelDisposition)
963+
'level' => new \Zend_Db_Expr($levelField . ' + ' . $levelDisposition)
964964
],
965965
[$pathField . ' LIKE ?' => $category->getPath() . '/%']
966966
);

app/code/Magento/CatalogInventory/view/adminhtml/ui_component/product_form.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@
285285
<settings>
286286
<scopeLabel>[GLOBAL]</scopeLabel>
287287
<validation>
288-
<rule name="validate-number" xsi:type="boolean">true</rule>
288+
<rule name="validate-greater-than-zero" xsi:type="boolean">true</rule>
289289
</validation>
290290
<label translate="true">Maximum Qty Allowed in Shopping Cart</label>
291291
<dataScope>max_sale_qty</dataScope>

app/code/Magento/Checkout/view/frontend/web/js/view/progress-bar.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@ define([
2424

2525
/** @inheritdoc */
2626
initialize: function () {
27+
var stepsValue;
28+
2729
this._super();
2830
$(window).hashchange(_.bind(stepNavigator.handleHash, stepNavigator));
2931

3032
if (!window.location.hash) {
31-
stepNavigator.setHash(stepNavigator.steps().sort(stepNavigator.sortItems)[0].code);
33+
stepsValue = stepNavigator.steps();
34+
35+
if (stepsValue.length) {
36+
stepNavigator.setHash(stepsValue.sort(stepNavigator.sortItems)[0].code);
37+
}
3238
}
3339

3440
stepNavigator.handleHash();

app/code/Magento/Eav/Model/Entity/Attribute/Source/Table.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Magento\Framework\Escaper;
1111

1212
/**
13+
* Eav attribute default source when values are coming from another table
14+
*
1315
* @api
1416
* @since 100.0.2
1517
*/
@@ -136,12 +138,14 @@ public function getSpecificOptions($ids, $withEmpty = true)
136138
}
137139

138140
/**
141+
* Add an empty option to the array
142+
*
139143
* @param array $options
140144
* @return array
141145
*/
142146
private function addEmptyOption(array $options)
143147
{
144-
array_unshift($options, ['label' => $this->getAttribute()->getIsRequired() ? '' : ' ', 'value' => '']);
148+
array_unshift($options, ['label' => ' ', 'value' => '']);
145149
return $options;
146150
}
147151

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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\Sales\Test\Unit\Observer;
9+
10+
use Magento\Customer\Api\Data\CustomerInterface;
11+
use Magento\Framework\Event;
12+
use Magento\Framework\Event\Observer;
13+
use Magento\Sales\Api\Data\OrderInterface;
14+
use Magento\Sales\Api\OrderRepositoryInterface;
15+
use Magento\Sales\Observer\AssignOrderToCustomerObserver;
16+
use PHPUnit\Framework\TestCase;
17+
use PHPUnit_Framework_MockObject_MockObject;
18+
19+
/**
20+
* Class AssignOrderToCustomerObserverTest
21+
*/
22+
class AssignOrderToCustomerObserverTest extends TestCase
23+
{
24+
/** @var AssignOrderToCustomerObserver */
25+
protected $sut;
26+
27+
/** @var OrderRepositoryInterface|PHPUnit_Framework_MockObject_MockObject */
28+
protected $orderRepositoryMock;
29+
30+
/**
31+
* Set Up
32+
*/
33+
protected function setUp()
34+
{
35+
$this->orderRepositoryMock = $this->getMockBuilder(OrderRepositoryInterface::class)
36+
->disableOriginalConstructor()
37+
->getMock();
38+
$this->sut = new AssignOrderToCustomerObserver($this->orderRepositoryMock);
39+
}
40+
41+
/**
42+
* Test assigning order to customer after issuing guest order
43+
*
44+
* @dataProvider getCustomerIds
45+
* @param null|int $customerId
46+
* @return void
47+
*/
48+
public function testAssignOrderToCustomerAfterGuestOrder($customerId)
49+
{
50+
$orderId = 1;
51+
/** @var Observer|PHPUnit_Framework_MockObject_MockObject $observerMock */
52+
$observerMock = $this->createMock(Observer::class);
53+
/** @var Event|PHPUnit_Framework_MockObject_MockObject $eventMock */
54+
$eventMock = $this->getMockBuilder(Event::class)->disableOriginalConstructor()
55+
->setMethods(['getData'])
56+
->getMock();
57+
/** @var CustomerInterface|PHPUnit_Framework_MockObject_MockObject $customerMock */
58+
$customerMock = $this->createMock(CustomerInterface::class);
59+
/** @var OrderInterface|PHPUnit_Framework_MockObject_MockObject $orderMock */
60+
$orderMock = $this->getMockBuilder(OrderInterface::class)
61+
->disableOriginalConstructor()
62+
->getMockForAbstractClass();
63+
$observerMock->expects($this->once())->method('getEvent')->willReturn($eventMock);
64+
$eventMock->expects($this->any())->method('getData')
65+
->willReturnMap([
66+
['delegate_data', null, ['__sales_assign_order_id' => $orderId]],
67+
['customer_data_object', null, $customerMock]
68+
]);
69+
$orderMock->expects($this->once())->method('getCustomerId')->willReturn($customerId);
70+
$this->orderRepositoryMock->expects($this->once())->method('get')->with($orderId)
71+
->willReturn($orderMock);
72+
if (!$customerId) {
73+
$this->orderRepositoryMock->expects($this->once())->method('save')->with($orderMock);
74+
$this->sut->execute($observerMock);
75+
return ;
76+
}
77+
78+
$this->orderRepositoryMock->expects($this->never())->method('save')->with($orderMock);
79+
$this->sut->execute($observerMock);
80+
}
81+
82+
/**
83+
* Customer id assigned to order
84+
*
85+
* @return array
86+
*/
87+
public function getCustomerIds()
88+
{
89+
return [[null, 1]];
90+
}
91+
}

lib/internal/Magento/Framework/Communication/Config/Validator.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public function __construct(
3838
}
3939

4040
/**
41+
* Validate response schema definition for topic
42+
*
4143
* @param string $responseSchema
4244
* @param string $topicName
4345
* @return void
@@ -46,6 +48,12 @@ public function validateResponseSchemaType($responseSchema, $topicName)
4648
{
4749
try {
4850
$this->validateType($responseSchema);
51+
} catch (\InvalidArgumentException $e) {
52+
throw new \LogicException(
53+
'Response schema definition has service class with wrong annotated methods',
54+
$e->getCode(),
55+
$e
56+
);
4957
} catch (\Exception $e) {
5058
throw new \LogicException(
5159
sprintf(
@@ -59,6 +67,8 @@ public function validateResponseSchemaType($responseSchema, $topicName)
5967
}
6068

6169
/**
70+
* Validate request schema definition for topic
71+
*
6272
* @param string $requestSchema
6373
* @param string $topicName
6474
* @return void
@@ -67,6 +77,12 @@ public function validateRequestSchemaType($requestSchema, $topicName)
6777
{
6878
try {
6979
$this->validateType($requestSchema);
80+
} catch (\InvalidArgumentException $e) {
81+
throw new \LogicException(
82+
'Request schema definition has service class with wrong annotated methods',
83+
$e->getCode(),
84+
$e
85+
);
7086
} catch (\Exception $e) {
7187
throw new \LogicException(
7288
sprintf(
@@ -80,6 +96,8 @@ public function validateRequestSchemaType($requestSchema, $topicName)
8096
}
8197

8298
/**
99+
* Validate service method specified in the definition of handler
100+
*
83101
* @param string $serviceName
84102
* @param string $methodName
85103
* @param string $handlerName
@@ -109,6 +127,7 @@ public function validateResponseHandlersType($serviceName, $methodName, $handler
109127
* @param string $typeName
110128
* @return $this
111129
* @throws \Exception In case when type is invalid
130+
* @throws \InvalidArgumentException if methods don't have annotation
112131
*/
113132
protected function validateType($typeName)
114133
{

lib/internal/Magento/Framework/Reflection/MethodsMap.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ public function getMethodReturnType($typeName, $methodName)
9494
* 'validatePassword' => 'boolean'
9595
* ]
9696
* </pre>
97+
* @throws \InvalidArgumentException if methods don't have annotation
98+
* @throws \ReflectionException for missing DocBock or invalid reflection class
9799
*/
98100
public function getMethodsMap($interfaceName)
99101
{
@@ -148,6 +150,8 @@ public function getMethodParams($serviceClassName, $serviceMethodName)
148150
*
149151
* @param string $interfaceName
150152
* @return array
153+
* @throws \ReflectionException for missing DocBock or invalid reflection class
154+
* @throws \InvalidArgumentException if methods don't have annotation
151155
*/
152156
private function getMethodMapViaReflection($interfaceName)
153157
{
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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\Framework\Test\Unit\Communication\Config;
9+
10+
use Magento\Framework\Communication\Config\Validator;
11+
use Magento\Framework\Reflection\MethodsMap;
12+
use Magento\Framework\Reflection\TypeProcessor;
13+
14+
/**
15+
* Unit test for \Magento\Framework\Communication\Config\Validator class
16+
*/
17+
class ValidatorTest extends \PHPUnit\Framework\TestCase
18+
{
19+
/**
20+
* @var TypeProcessor|\PHPUnit_Framework_MockObject_MockObject
21+
*/
22+
protected $typeProcessor;
23+
24+
/**
25+
* @var MethodsMap|\PHPUnit_Framework_MockObject_MockObject
26+
*/
27+
protected $methodsMap;
28+
29+
public function setUp()
30+
{
31+
$this->methodsMap = $this->createMock(MethodsMap::class);
32+
33+
$this->methodsMap->expects(static::any())
34+
->method('getMethodsMap')
35+
->will($this->throwException(new \InvalidArgumentException('message', 333)));
36+
37+
$this->typeProcessor = $this->createMock(TypeProcessor::class);
38+
$this->typeProcessor->expects(static::any())
39+
->method('isTypeSimple')
40+
->willReturn(false);
41+
42+
$this->typeProcessor->expects(static::any())
43+
->method('isTypeSimple')
44+
->willReturn(false);
45+
}
46+
47+
/**
48+
* @expectedException \LogicException
49+
* @expectedExceptionCode 333
50+
* @expectedExceptionMessage Response schema definition has service class with wrong annotated methods
51+
*/
52+
public function testValidateResponseSchemaType()
53+
{
54+
/** @var Validator $validator */
55+
$validator = new Validator($this->typeProcessor, $this->methodsMap);
56+
$validator->validateResponseSchemaType('123', '123');
57+
}
58+
59+
/**
60+
* @expectedException \LogicException
61+
* @expectedExceptionCode 333
62+
* @expectedExceptionMessage Request schema definition has service class with wrong annotated methods
63+
*/
64+
public function testValidateRequestSchemaType()
65+
{
66+
/** @var Validator $validator */
67+
$validator = new Validator($this->typeProcessor, $this->methodsMap);
68+
$validator->validateRequestSchemaType('123', '123');
69+
}
70+
}

0 commit comments

Comments
 (0)