Skip to content

Commit

Permalink
🔃 [EngCom] Public Pull Requests - 2.2-develop
Browse files Browse the repository at this point in the history
Accepted Public Pull Requests:
 - magento#18559: [Backport] Covering the AssignOrderToCustomerObserver by Unit Test (by @gelanivishal)
 - magento#18564: [Backport] Empty option Label should always be blank even if attribute is required (by @gelanivishal)
 - magento#18556: [Backport] Fixed typo from filed to field (by @gelanivishal)
 - magento#18554: [Backport] throw exception InvalidArgumentException during validate scheme (by @gelanivishal)
 - magento#18552: [Backport] Added validation on maximum quantity allowed in shopping cart (by @gelanivishal)
 - magento#18495: [Backport] Checkout - Fix "Cannot read property 'code' on undefined" issue (by @ihor-sviziev)


Fixed GitHub Issues:
 - magento#14555: Communication's component validator does not propagate exceptions, obscuring the cause of the error (reported by @nikita2206) has been fixed in magento#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

 - magento#18477: Set maximum Qty Allowed in Shopping Cart is 0 still allow adding to cart (reported by @duongdiep212) has been fixed in magento#18552 by @gelanivishal in 2.2-develop branch
   Related commits:
     1. db4ac89

 - magento#18164: Checkout - Cannot read property 'code' of undefined (reported by @bruno-serfe) has been fixed in magento#18495 by @ihor-sviziev in 2.2-develop branch
   Related commits:
     1. e7f70ab
     2. 25e3cfe
  • Loading branch information
Stanislav Idolov authored Oct 13, 2018
2 parents 4a6b81f + d9c3a92 commit c9d1bec
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/code/Magento/Catalog/Model/ResourceModel/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ public function changeParent(
$childrenCount = $this->getChildrenCount($category->getId()) + 1;
$table = $this->getEntityTable();
$connection = $this->getConnection();
$levelFiled = $connection->quoteIdentifier('level');
$levelField = $connection->quoteIdentifier('level');
$pathField = $connection->quoteIdentifier('path');

/**
Expand Down Expand Up @@ -960,7 +960,7 @@ public function changeParent(
$newPath . '/'
) . ')'
),
'level' => new \Zend_Db_Expr($levelFiled . ' + ' . $levelDisposition)
'level' => new \Zend_Db_Expr($levelField . ' + ' . $levelDisposition)
],
[$pathField . ' LIKE ?' => $category->getPath() . '/%']
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@
<settings>
<scopeLabel>[GLOBAL]</scopeLabel>
<validation>
<rule name="validate-number" xsi:type="boolean">true</rule>
<rule name="validate-greater-than-zero" xsi:type="boolean">true</rule>
</validation>
<label translate="true">Maximum Qty Allowed in Shopping Cart</label>
<dataScope>max_sale_qty</dataScope>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@ define([

/** @inheritdoc */
initialize: function () {
var stepsValue;

this._super();
$(window).hashchange(_.bind(stepNavigator.handleHash, stepNavigator));

if (!window.location.hash) {
stepNavigator.setHash(stepNavigator.steps().sort(stepNavigator.sortItems)[0].code);
stepsValue = stepNavigator.steps();

if (stepsValue.length) {
stepNavigator.setHash(stepsValue.sort(stepNavigator.sortItems)[0].code);
}
}

stepNavigator.handleHash();
Expand Down
6 changes: 5 additions & 1 deletion app/code/Magento/Eav/Model/Entity/Attribute/Source/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use Magento\Framework\Escaper;

/**
* Eav attribute default source when values are coming from another table
*
* @api
* @since 100.0.2
*/
Expand Down Expand Up @@ -136,12 +138,14 @@ public function getSpecificOptions($ids, $withEmpty = true)
}

/**
* Add an empty option to the array
*
* @param array $options
* @return array
*/
private function addEmptyOption(array $options)
{
array_unshift($options, ['label' => $this->getAttribute()->getIsRequired() ? '' : ' ', 'value' => '']);
array_unshift($options, ['label' => ' ', 'value' => '']);
return $options;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Sales\Test\Unit\Observer;

use Magento\Customer\Api\Data\CustomerInterface;
use Magento\Framework\Event;
use Magento\Framework\Event\Observer;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Observer\AssignOrderToCustomerObserver;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject;

/**
* Class AssignOrderToCustomerObserverTest
*/
class AssignOrderToCustomerObserverTest extends TestCase
{
/** @var AssignOrderToCustomerObserver */
protected $sut;

/** @var OrderRepositoryInterface|PHPUnit_Framework_MockObject_MockObject */
protected $orderRepositoryMock;

/**
* Set Up
*/
protected function setUp()
{
$this->orderRepositoryMock = $this->getMockBuilder(OrderRepositoryInterface::class)
->disableOriginalConstructor()
->getMock();
$this->sut = new AssignOrderToCustomerObserver($this->orderRepositoryMock);
}

/**
* Test assigning order to customer after issuing guest order
*
* @dataProvider getCustomerIds
* @param null|int $customerId
* @return void
*/
public function testAssignOrderToCustomerAfterGuestOrder($customerId)
{
$orderId = 1;
/** @var Observer|PHPUnit_Framework_MockObject_MockObject $observerMock */
$observerMock = $this->createMock(Observer::class);
/** @var Event|PHPUnit_Framework_MockObject_MockObject $eventMock */
$eventMock = $this->getMockBuilder(Event::class)->disableOriginalConstructor()
->setMethods(['getData'])
->getMock();
/** @var CustomerInterface|PHPUnit_Framework_MockObject_MockObject $customerMock */
$customerMock = $this->createMock(CustomerInterface::class);
/** @var OrderInterface|PHPUnit_Framework_MockObject_MockObject $orderMock */
$orderMock = $this->getMockBuilder(OrderInterface::class)
->disableOriginalConstructor()
->getMockForAbstractClass();
$observerMock->expects($this->once())->method('getEvent')->willReturn($eventMock);
$eventMock->expects($this->any())->method('getData')
->willReturnMap([
['delegate_data', null, ['__sales_assign_order_id' => $orderId]],
['customer_data_object', null, $customerMock]
]);
$orderMock->expects($this->once())->method('getCustomerId')->willReturn($customerId);
$this->orderRepositoryMock->expects($this->once())->method('get')->with($orderId)
->willReturn($orderMock);
if (!$customerId) {
$this->orderRepositoryMock->expects($this->once())->method('save')->with($orderMock);
$this->sut->execute($observerMock);
return ;
}

$this->orderRepositoryMock->expects($this->never())->method('save')->with($orderMock);
$this->sut->execute($observerMock);
}

/**
* Customer id assigned to order
*
* @return array
*/
public function getCustomerIds()
{
return [[null, 1]];
}
}
19 changes: 19 additions & 0 deletions lib/internal/Magento/Framework/Communication/Config/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public function __construct(
}

/**
* Validate response schema definition for topic
*
* @param string $responseSchema
* @param string $topicName
* @return void
Expand All @@ -46,6 +48,12 @@ public function validateResponseSchemaType($responseSchema, $topicName)
{
try {
$this->validateType($responseSchema);
} catch (\InvalidArgumentException $e) {
throw new \LogicException(
'Response schema definition has service class with wrong annotated methods',
$e->getCode(),
$e
);
} catch (\Exception $e) {
throw new \LogicException(
sprintf(
Expand All @@ -59,6 +67,8 @@ public function validateResponseSchemaType($responseSchema, $topicName)
}

/**
* Validate request schema definition for topic
*
* @param string $requestSchema
* @param string $topicName
* @return void
Expand All @@ -67,6 +77,12 @@ public function validateRequestSchemaType($requestSchema, $topicName)
{
try {
$this->validateType($requestSchema);
} catch (\InvalidArgumentException $e) {
throw new \LogicException(
'Request schema definition has service class with wrong annotated methods',
$e->getCode(),
$e
);
} catch (\Exception $e) {
throw new \LogicException(
sprintf(
Expand All @@ -80,6 +96,8 @@ public function validateRequestSchemaType($requestSchema, $topicName)
}

/**
* Validate service method specified in the definition of handler
*
* @param string $serviceName
* @param string $methodName
* @param string $handlerName
Expand Down Expand Up @@ -109,6 +127,7 @@ public function validateResponseHandlersType($serviceName, $methodName, $handler
* @param string $typeName
* @return $this
* @throws \Exception In case when type is invalid
* @throws \InvalidArgumentException if methods don't have annotation
*/
protected function validateType($typeName)
{
Expand Down
4 changes: 4 additions & 0 deletions lib/internal/Magento/Framework/Reflection/MethodsMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ public function getMethodReturnType($typeName, $methodName)
* 'validatePassword' => 'boolean'
* ]
* </pre>
* @throws \InvalidArgumentException if methods don't have annotation
* @throws \ReflectionException for missing DocBock or invalid reflection class
*/
public function getMethodsMap($interfaceName)
{
Expand Down Expand Up @@ -148,6 +150,8 @@ public function getMethodParams($serviceClassName, $serviceMethodName)
*
* @param string $interfaceName
* @return array
* @throws \ReflectionException for missing DocBock or invalid reflection class
* @throws \InvalidArgumentException if methods don't have annotation
*/
private function getMethodMapViaReflection($interfaceName)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Framework\Test\Unit\Communication\Config;

use Magento\Framework\Communication\Config\Validator;
use Magento\Framework\Reflection\MethodsMap;
use Magento\Framework\Reflection\TypeProcessor;

/**
* Unit test for \Magento\Framework\Communication\Config\Validator class
*/
class ValidatorTest extends \PHPUnit\Framework\TestCase
{
/**
* @var TypeProcessor|\PHPUnit_Framework_MockObject_MockObject
*/
protected $typeProcessor;

/**
* @var MethodsMap|\PHPUnit_Framework_MockObject_MockObject
*/
protected $methodsMap;

public function setUp()
{
$this->methodsMap = $this->createMock(MethodsMap::class);

$this->methodsMap->expects(static::any())
->method('getMethodsMap')
->will($this->throwException(new \InvalidArgumentException('message', 333)));

$this->typeProcessor = $this->createMock(TypeProcessor::class);
$this->typeProcessor->expects(static::any())
->method('isTypeSimple')
->willReturn(false);

$this->typeProcessor->expects(static::any())
->method('isTypeSimple')
->willReturn(false);
}

/**
* @expectedException \LogicException
* @expectedExceptionCode 333
* @expectedExceptionMessage Response schema definition has service class with wrong annotated methods
*/
public function testValidateResponseSchemaType()
{
/** @var Validator $validator */
$validator = new Validator($this->typeProcessor, $this->methodsMap);
$validator->validateResponseSchemaType('123', '123');
}

/**
* @expectedException \LogicException
* @expectedExceptionCode 333
* @expectedExceptionMessage Request schema definition has service class with wrong annotated methods
*/
public function testValidateRequestSchemaType()
{
/** @var Validator $validator */
$validator = new Validator($this->typeProcessor, $this->methodsMap);
$validator->validateRequestSchemaType('123', '123');
}
}

0 comments on commit c9d1bec

Please sign in to comment.