From e7f70abdd40b9bb1f46c45230412dbda0b421246 Mon Sep 17 00:00:00 2001 From: Ihor Sviziev Date: Tue, 9 Oct 2018 17:05:33 +0300 Subject: [PATCH 01/16] magento/magento2#18164 Checkout - Fix "Cannot read property 'code' on undefined" issue --- .../Checkout/view/frontend/web/js/view/progress-bar.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Checkout/view/frontend/web/js/view/progress-bar.js b/app/code/Magento/Checkout/view/frontend/web/js/view/progress-bar.js index e4b1e464348b9..47ad45e192851 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/view/progress-bar.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/view/progress-bar.js @@ -24,11 +24,17 @@ define([ /** @inheritdoc */ initialize: function () { + var steps; + this._super(); $(window).hashchange(_.bind(stepNavigator.handleHash, stepNavigator)); if (!window.location.hash) { - stepNavigator.setHash(stepNavigator.steps().sort(stepNavigator.sortItems)[0].code); + steps = stepNavigator.steps(); + + if (steps.length) { + stepNavigator.setHash(steps.sort(stepNavigator.sortItems)[0].code); + } } stepNavigator.handleHash(); From 25e3cfe56545df3a4dc502f0fa0d96f63f2e5e88 Mon Sep 17 00:00:00 2001 From: Ihor Sviziev Date: Wed, 10 Oct 2018 11:56:31 +0300 Subject: [PATCH 02/16] magento/magento2#18164 Checkout - Fix "Cannot read property 'code' on undefined" issue --- .../Checkout/view/frontend/web/js/view/progress-bar.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Checkout/view/frontend/web/js/view/progress-bar.js b/app/code/Magento/Checkout/view/frontend/web/js/view/progress-bar.js index 47ad45e192851..db49683129f2b 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/view/progress-bar.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/view/progress-bar.js @@ -24,16 +24,16 @@ define([ /** @inheritdoc */ initialize: function () { - var steps; + var stepsValue; this._super(); $(window).hashchange(_.bind(stepNavigator.handleHash, stepNavigator)); if (!window.location.hash) { - steps = stepNavigator.steps(); + stepsValue = stepNavigator.steps(); - if (steps.length) { - stepNavigator.setHash(steps.sort(stepNavigator.sortItems)[0].code); + if (stepsValue.length) { + stepNavigator.setHash(stepsValue.sort(stepNavigator.sortItems)[0].code); } } From db4ac896b7827e73b7948f1744ab40d9c661468f Mon Sep 17 00:00:00 2001 From: vgelani Date: Tue, 9 Oct 2018 15:01:40 +0530 Subject: [PATCH 03/16] Added validation on maximum quantity allowed in shopping cart --- .../view/adminhtml/ui_component/product_form.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/CatalogInventory/view/adminhtml/ui_component/product_form.xml b/app/code/Magento/CatalogInventory/view/adminhtml/ui_component/product_form.xml index 3472f4368d617..ecdac1a28ed92 100644 --- a/app/code/Magento/CatalogInventory/view/adminhtml/ui_component/product_form.xml +++ b/app/code/Magento/CatalogInventory/view/adminhtml/ui_component/product_form.xml @@ -285,7 +285,7 @@ [GLOBAL] - true + true max_sale_qty From 3109909d76b0402a941518bc9306697e4431ef54 Mon Sep 17 00:00:00 2001 From: Artsiom Bruneuski Date: Sat, 6 Oct 2018 14:06:43 +0200 Subject: [PATCH 04/16] throw exception InvalidArgumentException during validate scheme --- .../Magento/Framework/Communication/Config/Validator.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/internal/Magento/Framework/Communication/Config/Validator.php b/lib/internal/Magento/Framework/Communication/Config/Validator.php index 5e2687c3b08c1..3bcc44bd44873 100644 --- a/lib/internal/Magento/Framework/Communication/Config/Validator.php +++ b/lib/internal/Magento/Framework/Communication/Config/Validator.php @@ -46,6 +46,8 @@ public function validateResponseSchemaType($responseSchema, $topicName) { try { $this->validateType($responseSchema); + } catch (\InvalidArgumentException $e) { + throw $e; } catch (\Exception $e) { throw new \LogicException( sprintf( @@ -67,6 +69,8 @@ public function validateRequestSchemaType($requestSchema, $topicName) { try { $this->validateType($requestSchema); + } catch (\InvalidArgumentException $e) { + throw $e; } catch (\Exception $e) { throw new \LogicException( sprintf( @@ -90,6 +94,8 @@ public function validateResponseHandlersType($serviceName, $methodName, $handler { try { $this->methodsMap->getMethodParams($serviceName, $methodName); + } catch (\InvalidArgumentException $e) { + throw $e; } catch (\Exception $e) { throw new \LogicException( sprintf( From 9afdfee251b7ef9098b3ae22e59cf0673c557bb3 Mon Sep 17 00:00:00 2001 From: Artsiom Bruneuski Date: Sat, 6 Oct 2018 15:20:07 +0200 Subject: [PATCH 05/16] catch InvalidArgumentException, throw correct message, unit test --- .../Communication/Config/Validator.php | 16 +++-- .../Communication/Config/ValidatorTest.php | 58 +++++++++++++++++++ 2 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 lib/internal/Magento/Framework/Test/Unit/Communication/Config/ValidatorTest.php diff --git a/lib/internal/Magento/Framework/Communication/Config/Validator.php b/lib/internal/Magento/Framework/Communication/Config/Validator.php index 3bcc44bd44873..c3b2d03089f49 100644 --- a/lib/internal/Magento/Framework/Communication/Config/Validator.php +++ b/lib/internal/Magento/Framework/Communication/Config/Validator.php @@ -13,6 +13,7 @@ */ class Validator { + const INVALID_ANNOTATIONS = 123; /** * @var TypeProcessor */ @@ -47,7 +48,11 @@ public function validateResponseSchemaType($responseSchema, $topicName) try { $this->validateType($responseSchema); } catch (\InvalidArgumentException $e) { - throw $e; + throw new \LogicException( + 'Response schema definition has wrong annotations', + self::INVALID_ANNOTATIONS, + $e + ); } catch (\Exception $e) { throw new \LogicException( sprintf( @@ -70,7 +75,11 @@ public function validateRequestSchemaType($requestSchema, $topicName) try { $this->validateType($requestSchema); } catch (\InvalidArgumentException $e) { - throw $e; + throw new \LogicException( + 'Response schema definition has wrong annotations', + self::INVALID_ANNOTATIONS, + $e + ); } catch (\Exception $e) { throw new \LogicException( sprintf( @@ -94,8 +103,6 @@ public function validateResponseHandlersType($serviceName, $methodName, $handler { try { $this->methodsMap->getMethodParams($serviceName, $methodName); - } catch (\InvalidArgumentException $e) { - throw $e; } catch (\Exception $e) { throw new \LogicException( sprintf( @@ -115,6 +122,7 @@ public function validateResponseHandlersType($serviceName, $methodName, $handler * @param string $typeName * @return $this * @throws \Exception In case when type is invalid + * @throws \InvalidArgumentException */ protected function validateType($typeName) { diff --git a/lib/internal/Magento/Framework/Test/Unit/Communication/Config/ValidatorTest.php b/lib/internal/Magento/Framework/Test/Unit/Communication/Config/ValidatorTest.php new file mode 100644 index 0000000000000..0f54ae015a08b --- /dev/null +++ b/lib/internal/Magento/Framework/Test/Unit/Communication/Config/ValidatorTest.php @@ -0,0 +1,58 @@ +methodsMap = $this->createMock(MethodsMap::class); + + $this->methodsMap->expects(static::any()) + ->method('getMethodsMap') + ->will($this->throwException(new \InvalidArgumentException())); + + + $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 123 + */ + public function testValidateResponseSchemaType() + { + /** @var Validator $validator */ + $validator = new Validator($this->typeProcessor, $this->methodsMap); + $validator->validateResponseSchemaType('123', '123'); + } + + /** + * @expectedException \LogicException + * @expectedExceptionCode 123 + */ + public function testValidateRequestSchemaType() + { + /** @var Validator $validator */ + $validator = new Validator($this->typeProcessor, $this->methodsMap); + $validator->validateRequestSchemaType('123', '123'); + } +} \ No newline at end of file From 791609c7ec59700694609937deeecd1916fda2b6 Mon Sep 17 00:00:00 2001 From: Artsiom Bruneuski Date: Sat, 6 Oct 2018 15:22:37 +0200 Subject: [PATCH 06/16] annotations --- lib/internal/Magento/Framework/Reflection/MethodsMap.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/internal/Magento/Framework/Reflection/MethodsMap.php b/lib/internal/Magento/Framework/Reflection/MethodsMap.php index 944cd8771ee33..77015be8437a0 100644 --- a/lib/internal/Magento/Framework/Reflection/MethodsMap.php +++ b/lib/internal/Magento/Framework/Reflection/MethodsMap.php @@ -94,6 +94,8 @@ public function getMethodReturnType($typeName, $methodName) * 'validatePassword' => 'boolean' * ] * + * @throws \InvalidArgumentException + * @throws \ReflectionException */ public function getMethodsMap($interfaceName) { @@ -148,6 +150,8 @@ public function getMethodParams($serviceClassName, $serviceMethodName) * * @param string $interfaceName * @return array + * @throws \ReflectionException + * @throws \InvalidArgumentException */ private function getMethodMapViaReflection($interfaceName) { From beeecafdb28a20b39e06c17554e49bbffa1f7632 Mon Sep 17 00:00:00 2001 From: Artsiom Bruneuski Date: Sat, 6 Oct 2018 15:25:04 +0200 Subject: [PATCH 07/16] remove annotations --- .../Test/Unit/Communication/Config/ValidatorTest.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/internal/Magento/Framework/Test/Unit/Communication/Config/ValidatorTest.php b/lib/internal/Magento/Framework/Test/Unit/Communication/Config/ValidatorTest.php index 0f54ae015a08b..633cf7b6abbf3 100644 --- a/lib/internal/Magento/Framework/Test/Unit/Communication/Config/ValidatorTest.php +++ b/lib/internal/Magento/Framework/Test/Unit/Communication/Config/ValidatorTest.php @@ -1,8 +1,4 @@ Date: Sat, 6 Oct 2018 16:02:05 +0200 Subject: [PATCH 08/16] throw exception code from previous exception --- .../Magento/Framework/Communication/Config/Validator.php | 5 ++--- .../Test/Unit/Communication/Config/ValidatorTest.php | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/internal/Magento/Framework/Communication/Config/Validator.php b/lib/internal/Magento/Framework/Communication/Config/Validator.php index c3b2d03089f49..0bd3763028def 100644 --- a/lib/internal/Magento/Framework/Communication/Config/Validator.php +++ b/lib/internal/Magento/Framework/Communication/Config/Validator.php @@ -13,7 +13,6 @@ */ class Validator { - const INVALID_ANNOTATIONS = 123; /** * @var TypeProcessor */ @@ -50,7 +49,7 @@ public function validateResponseSchemaType($responseSchema, $topicName) } catch (\InvalidArgumentException $e) { throw new \LogicException( 'Response schema definition has wrong annotations', - self::INVALID_ANNOTATIONS, + $e->getCode(), $e ); } catch (\Exception $e) { @@ -77,7 +76,7 @@ public function validateRequestSchemaType($requestSchema, $topicName) } catch (\InvalidArgumentException $e) { throw new \LogicException( 'Response schema definition has wrong annotations', - self::INVALID_ANNOTATIONS, + $e->getCode(), $e ); } catch (\Exception $e) { diff --git a/lib/internal/Magento/Framework/Test/Unit/Communication/Config/ValidatorTest.php b/lib/internal/Magento/Framework/Test/Unit/Communication/Config/ValidatorTest.php index 633cf7b6abbf3..c440d39f0188b 100644 --- a/lib/internal/Magento/Framework/Test/Unit/Communication/Config/ValidatorTest.php +++ b/lib/internal/Magento/Framework/Test/Unit/Communication/Config/ValidatorTest.php @@ -17,7 +17,7 @@ public function setUp() $this->methodsMap->expects(static::any()) ->method('getMethodsMap') - ->will($this->throwException(new \InvalidArgumentException())); + ->will($this->throwException(new \InvalidArgumentException('message', 333))); $this->typeProcessor = $this->createMock(TypeProcessor::class); @@ -32,7 +32,7 @@ public function setUp() /** * @expectedException \LogicException - * @expectedExceptionCode 123 + * @expectedExceptionCode 333 */ public function testValidateResponseSchemaType() { @@ -43,7 +43,7 @@ public function testValidateResponseSchemaType() /** * @expectedException \LogicException - * @expectedExceptionCode 123 + * @expectedExceptionCode 333 */ public function testValidateRequestSchemaType() { From a20968db7a29a3b6f26a46979179851121eea336 Mon Sep 17 00:00:00 2001 From: Artsiom Bruneuski Date: Sat, 6 Oct 2018 16:09:56 +0200 Subject: [PATCH 09/16] modified exception message --- .../Magento/Framework/Communication/Config/Validator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/Communication/Config/Validator.php b/lib/internal/Magento/Framework/Communication/Config/Validator.php index 0bd3763028def..73d245d79e111 100644 --- a/lib/internal/Magento/Framework/Communication/Config/Validator.php +++ b/lib/internal/Magento/Framework/Communication/Config/Validator.php @@ -48,7 +48,7 @@ public function validateResponseSchemaType($responseSchema, $topicName) $this->validateType($responseSchema); } catch (\InvalidArgumentException $e) { throw new \LogicException( - 'Response schema definition has wrong annotations', + 'Response schema definition has service class with wrong annotated methods', $e->getCode(), $e ); @@ -75,7 +75,7 @@ public function validateRequestSchemaType($requestSchema, $topicName) $this->validateType($requestSchema); } catch (\InvalidArgumentException $e) { throw new \LogicException( - 'Response schema definition has wrong annotations', + 'Request schema definition has service class with wrong annotated methods', $e->getCode(), $e ); From 2f2cafee687d81d95854b1629ef8eec7c5a4e548 Mon Sep 17 00:00:00 2001 From: Artsiom Bruneuski Date: Sat, 6 Oct 2018 17:26:58 +0200 Subject: [PATCH 10/16] Was added description to exceptions, annotations to properties and classes. Implemented validation of exception message in unit test --- .../Communication/Config/Validator.php | 2 +- .../Framework/Reflection/MethodsMap.php | 8 ++++---- .../Communication/Config/ValidatorTest.php | 18 ++++++++++++++++-- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/internal/Magento/Framework/Communication/Config/Validator.php b/lib/internal/Magento/Framework/Communication/Config/Validator.php index 73d245d79e111..f08c3700a33ba 100644 --- a/lib/internal/Magento/Framework/Communication/Config/Validator.php +++ b/lib/internal/Magento/Framework/Communication/Config/Validator.php @@ -121,7 +121,7 @@ public function validateResponseHandlersType($serviceName, $methodName, $handler * @param string $typeName * @return $this * @throws \Exception In case when type is invalid - * @throws \InvalidArgumentException +` * @throws \InvalidArgumentException if methods don't have annotation */ protected function validateType($typeName) { diff --git a/lib/internal/Magento/Framework/Reflection/MethodsMap.php b/lib/internal/Magento/Framework/Reflection/MethodsMap.php index 77015be8437a0..6b0ddfbfc2127 100644 --- a/lib/internal/Magento/Framework/Reflection/MethodsMap.php +++ b/lib/internal/Magento/Framework/Reflection/MethodsMap.php @@ -94,8 +94,8 @@ public function getMethodReturnType($typeName, $methodName) * 'validatePassword' => 'boolean' * ] * - * @throws \InvalidArgumentException - * @throws \ReflectionException + * @throws \InvalidArgumentException if methods don't have annotation + * @throws \ReflectionException for missing DocBock or invalid reflection class */ public function getMethodsMap($interfaceName) { @@ -150,8 +150,8 @@ public function getMethodParams($serviceClassName, $serviceMethodName) * * @param string $interfaceName * @return array - * @throws \ReflectionException - * @throws \InvalidArgumentException + * @throws \ReflectionException for missing DocBock or invalid reflection class + * @throws \InvalidArgumentException if methods don't have annotation */ private function getMethodMapViaReflection($interfaceName) { diff --git a/lib/internal/Magento/Framework/Test/Unit/Communication/Config/ValidatorTest.php b/lib/internal/Magento/Framework/Test/Unit/Communication/Config/ValidatorTest.php index c440d39f0188b..36e43de928019 100644 --- a/lib/internal/Magento/Framework/Test/Unit/Communication/Config/ValidatorTest.php +++ b/lib/internal/Magento/Framework/Test/Unit/Communication/Config/ValidatorTest.php @@ -1,14 +1,27 @@ method('getMethodsMap') ->will($this->throwException(new \InvalidArgumentException('message', 333))); - $this->typeProcessor = $this->createMock(TypeProcessor::class); $this->typeProcessor->expects(static::any()) ->method('isTypeSimple') @@ -33,6 +45,7 @@ public function setUp() /** * @expectedException \LogicException * @expectedExceptionCode 333 + * @expectedExceptionMessage Response schema definition has service class with wrong annotated methods */ public function testValidateResponseSchemaType() { @@ -44,6 +57,7 @@ public function testValidateResponseSchemaType() /** * @expectedException \LogicException * @expectedExceptionCode 333 + * @expectedExceptionMessage Request schema definition has service class with wrong annotated methods */ public function testValidateRequestSchemaType() { From 72b31c952619104e1b176fe9c03074437c8a58b9 Mon Sep 17 00:00:00 2001 From: Artsiom Bruneuski Date: Sun, 7 Oct 2018 11:01:25 +0200 Subject: [PATCH 11/16] short descriptions was added --- .../Magento/Framework/Communication/Config/Validator.php | 6 ++++++ .../Test/Unit/Communication/Config/ValidatorTest.php | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/Communication/Config/Validator.php b/lib/internal/Magento/Framework/Communication/Config/Validator.php index f08c3700a33ba..bf21b3dcf95e1 100644 --- a/lib/internal/Magento/Framework/Communication/Config/Validator.php +++ b/lib/internal/Magento/Framework/Communication/Config/Validator.php @@ -38,6 +38,8 @@ public function __construct( } /** + * Validate response schema definition for topic + * * @param string $responseSchema * @param string $topicName * @return void @@ -65,6 +67,8 @@ public function validateResponseSchemaType($responseSchema, $topicName) } /** + * Validate request schema definition for topic + * * @param string $requestSchema * @param string $topicName * @return void @@ -92,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 diff --git a/lib/internal/Magento/Framework/Test/Unit/Communication/Config/ValidatorTest.php b/lib/internal/Magento/Framework/Test/Unit/Communication/Config/ValidatorTest.php index 36e43de928019..6829bdab59253 100644 --- a/lib/internal/Magento/Framework/Test/Unit/Communication/Config/ValidatorTest.php +++ b/lib/internal/Magento/Framework/Test/Unit/Communication/Config/ValidatorTest.php @@ -1,4 +1,4 @@ -typeProcessor, $this->methodsMap); $validator->validateRequestSchemaType('123', '123'); } -} \ No newline at end of file +} From a7cdae0e4f80aa8596d4b3a3b958ae2b9938a346 Mon Sep 17 00:00:00 2001 From: Artsiom Bruneuski Date: Sun, 7 Oct 2018 12:04:19 +0200 Subject: [PATCH 12/16] moved strict_types block --- .../Test/Unit/Communication/Config/ValidatorTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Test/Unit/Communication/Config/ValidatorTest.php b/lib/internal/Magento/Framework/Test/Unit/Communication/Config/ValidatorTest.php index 6829bdab59253..55410af176af0 100644 --- a/lib/internal/Magento/Framework/Test/Unit/Communication/Config/ValidatorTest.php +++ b/lib/internal/Magento/Framework/Test/Unit/Communication/Config/ValidatorTest.php @@ -1,8 +1,10 @@ - Date: Sun, 7 Oct 2018 13:08:35 +0200 Subject: [PATCH 13/16] removed wrong symbol --- .../Magento/Framework/Communication/Config/Validator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Communication/Config/Validator.php b/lib/internal/Magento/Framework/Communication/Config/Validator.php index bf21b3dcf95e1..76ef1b85b63eb 100644 --- a/lib/internal/Magento/Framework/Communication/Config/Validator.php +++ b/lib/internal/Magento/Framework/Communication/Config/Validator.php @@ -127,7 +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 + * @throws \InvalidArgumentException if methods don't have annotation */ protected function validateType($typeName) { From aedb6c92f2491ab89ebfac1d674a3cbc4d9c6b78 Mon Sep 17 00:00:00 2001 From: peterjaap Date: Wed, 10 Oct 2018 11:05:24 +0200 Subject: [PATCH 14/16] Fixed typo from filed to field --- app/code/Magento/Catalog/Model/ResourceModel/Category.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Category.php b/app/code/Magento/Catalog/Model/ResourceModel/Category.php index 1f3b2642953c8..b03657545b41c 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Category.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Category.php @@ -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'); /** @@ -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() . '/%'] ); From a2b69ed27708cedf575437e9f09e259962828ed1 Mon Sep 17 00:00:00 2001 From: eduard13 Date: Tue, 9 Oct 2018 18:27:53 +0300 Subject: [PATCH 15/16] Covering the AssignOrderToCustomerObserver by Unit Test --- .../AssignOrderToCustomerObserverTest.php | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 app/code/Magento/Sales/Test/Unit/Observer/AssignOrderToCustomerObserverTest.php diff --git a/app/code/Magento/Sales/Test/Unit/Observer/AssignOrderToCustomerObserverTest.php b/app/code/Magento/Sales/Test/Unit/Observer/AssignOrderToCustomerObserverTest.php new file mode 100644 index 0000000000000..c6e02151b9bc1 --- /dev/null +++ b/app/code/Magento/Sales/Test/Unit/Observer/AssignOrderToCustomerObserverTest.php @@ -0,0 +1,91 @@ +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]]; + } +} From ba9a1b245a2e7cd49dde7000a3ba5b69c136f143 Mon Sep 17 00:00:00 2001 From: Vincent MARMIESSE Date: Mon, 24 Sep 2018 13:30:50 +0200 Subject: [PATCH 16/16] Label should always be blank even if attribute is required --- .../Magento/Eav/Model/Entity/Attribute/Source/Table.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Eav/Model/Entity/Attribute/Source/Table.php b/app/code/Magento/Eav/Model/Entity/Attribute/Source/Table.php index bd77b952a07b8..58993b4928b3a 100644 --- a/app/code/Magento/Eav/Model/Entity/Attribute/Source/Table.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute/Source/Table.php @@ -10,6 +10,8 @@ use Magento\Framework\Escaper; /** + * Eav attribute default source when values are coming from another table + * * @api * @since 100.0.2 */ @@ -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; }