From 7a04c04bec1fa3525d8b43ca684e13da3cb37974 Mon Sep 17 00:00:00 2001 From: Pascal Brouwers Date: Fri, 24 Jan 2020 15:42:02 +0100 Subject: [PATCH 1/3] issue/26526 Fix orderRepository does not check if there are no extensionAttributes --- app/code/Magento/Sales/Model/OrderRepository.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/code/Magento/Sales/Model/OrderRepository.php b/app/code/Magento/Sales/Model/OrderRepository.php index f93de4c32d888..baac39b333712 100644 --- a/app/code/Magento/Sales/Model/OrderRepository.php +++ b/app/code/Magento/Sales/Model/OrderRepository.php @@ -157,6 +157,9 @@ public function get($id) private function setOrderTaxDetails(OrderInterface $order) { $extensionAttributes = $order->getExtensionAttributes(); + if ($extensionAttributes === null) { + $extensionAttributes = $this->orderExtensionFactory->create(); + } $orderTaxDetails = $this->orderTaxManagement->getOrderTaxDetails($order->getEntityId()); $appliedTaxes = $orderTaxDetails->getAppliedTaxes(); @@ -180,6 +183,9 @@ private function setOrderTaxDetails(OrderInterface $order) private function setPaymentAdditionalInfo(OrderInterface $order): void { $extensionAttributes = $order->getExtensionAttributes(); + if ($extensionAttributes === null) { + $extensionAttributes = $this->orderExtensionFactory->create(); + } $paymentAdditionalInformation = $order->getPayment()->getAdditionalInformation(); $objects = []; From bb408984f2d58d301eef6d8faf3bff2c268f385f Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Fri, 4 Sep 2020 15:24:24 +0300 Subject: [PATCH 2/3] magento/magento2#26526: OrderRepository does not check if there are no extensionAttributes. --- .../Test/Unit/Model/OrderRepositoryTest.php | 69 +++++++++++++++++-- 1 file changed, 64 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Sales/Test/Unit/Model/OrderRepositoryTest.php b/app/code/Magento/Sales/Test/Unit/Model/OrderRepositoryTest.php index 84c66d12c10d8..407d158e6f8d4 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/OrderRepositoryTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/OrderRepositoryTest.php @@ -18,12 +18,13 @@ use Magento\Sales\Api\Data\OrderInterface; use Magento\Sales\Api\Data\OrderPaymentInterface; use Magento\Sales\Api\Data\OrderSearchResultInterfaceFactory as SearchResultFactory; +use Magento\Sales\Model\Order; use Magento\Sales\Model\Order\Shipping; use Magento\Sales\Model\Order\ShippingAssignment; use Magento\Sales\Model\Order\ShippingAssignmentBuilder; use Magento\Sales\Model\OrderRepository; use Magento\Sales\Model\ResourceModel\Metadata; -use Magento\Sales\Model\ResourceModel\Order; +use Magento\Sales\Model\ResourceModel\Order as OrderResource; use Magento\Sales\Model\ResourceModel\Order\Collection; use Magento\Tax\Api\Data\OrderTaxDetailsInterface; use Magento\Tax\Api\OrderTaxManagementInterface; @@ -70,6 +71,11 @@ class OrderRepositoryTest extends TestCase */ private $paymentAdditionalInfoFactory; + /** + * @var OrderExtensionFactory|\PHPUnit_Framework_MockObject_MockObject + */ + private $orderExtensionFactoryMock; + /** * Setup the test * @@ -88,7 +94,7 @@ protected function setUp(): void $this->collectionProcessor = $this->createMock( CollectionProcessorInterface::class ); - $orderExtensionFactoryMock = $this->getMockBuilder(OrderExtensionFactory::class) + $this->orderExtensionFactoryMock = $this->getMockBuilder(OrderExtensionFactory::class) ->disableOriginalConstructor() ->getMock(); $this->orderTaxManagementMock = $this->getMockBuilder(OrderTaxManagementInterface::class) @@ -103,7 +109,7 @@ protected function setUp(): void 'metadata' => $this->metadata, 'searchResultFactory' => $this->searchResultFactory, 'collectionProcessor' => $this->collectionProcessor, - 'orderExtensionFactory' => $orderExtensionFactoryMock, + 'orderExtensionFactory' => $this->orderExtensionFactoryMock, 'orderTaxManagement' => $this->orderTaxManagementMock, 'paymentAdditionalInfoFactory' => $this->paymentAdditionalInfoFactory ] @@ -178,10 +184,10 @@ public function testGetList() */ public function testSave() { - $mapperMock = $this->getMockBuilder(Order::class) + $mapperMock = $this->getMockBuilder(OrderResource::class) ->disableOriginalConstructor() ->getMock(); - $orderEntity = $this->createMock(\Magento\Sales\Model\Order::class); + $orderEntity = $this->createMock(Order::class); $extensionAttributes = $this->getMockBuilder(OrderExtension::class) ->addMethods(['getShippingAssignments']) ->getMock(); @@ -207,4 +213,57 @@ public function testSave() $orderEntity->expects($this->any())->method('getEntityId')->willReturn(1); $this->orderRepository->save($orderEntity); } + + /** + * Test for method get. + * + * @return void + */ + public function testGet() + { + $orderId = 1; + $appliedTaxes = 'applied_taxes'; + $items = 'items'; + $paymentInfo = []; + + $orderEntity = $this->createMock(Order::class); + $paymentMock = $this->getMockBuilder(OrderPaymentInterface::class) + ->disableOriginalConstructor()->getMockForAbstractClass(); + $paymentMock->expects($this->once())->method('getAdditionalInformation')->willReturn($paymentInfo); + $orderExtension = $this->getMockBuilder(OrderExtension::class) + ->setMethods( + [ + 'getShippingAssignments', + 'setAppliedTaxes', + 'setConvertingFromQuote', + 'setItemAppliedTaxes', + 'setPaymentAdditionalInfo' + ] + ) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $orderExtension->expects($this->once())->method('getShippingAssignments')->willReturn(true); + $orderExtension->expects($this->once())->method('setAppliedTaxes')->with($appliedTaxes); + $orderExtension->expects($this->once())->method('setConvertingFromQuote')->with(true); + $orderExtension->expects($this->once())->method('setItemAppliedTaxes')->with($items); + $orderExtension->expects($this->once())->method('setPaymentAdditionalInfo')->with($paymentInfo); + $this->orderExtensionFactoryMock->expects($this->once())->method('create')->willReturn($orderExtension); + $orderEntity->expects($this->once())->method('load')->with($orderId)->willReturn($orderEntity); + $orderEntity->expects($this->exactly(2))->method('getEntityId')->willReturn($orderId); + $orderEntity->expects($this->once())->method('getPayment')->willReturn($paymentMock); + $orderEntity->expects($this->exactly(2))->method('setExtensionAttributes')->with($orderExtension); + $orderEntity->expects($this->exactly(3)) + ->method('getExtensionAttributes') + ->willReturnOnConsecutiveCalls(null, $orderExtension, $orderExtension); + $this->metadata->expects($this->once())->method('getNewInstance')->willReturn($orderEntity); + $orderTaxDetailsMock = $this->getMockBuilder(OrderTaxDetailsInterface::class) + ->disableOriginalConstructor() + ->setMethods(['setAppliedTaxes'])->getMockForAbstractClass(); + $orderTaxDetailsMock->expects($this->once())->method('getAppliedTaxes')->willReturn($appliedTaxes); + $orderTaxDetailsMock->expects($this->once())->method('getItems')->willReturn($items); + $this->orderTaxManagementMock->expects($this->atLeastOnce())->method('getOrderTaxDetails') + ->willReturn($orderTaxDetailsMock); + + $this->orderRepository->get($orderId); + } } From ff12e395b639b2f3155efcd730c8c20fc9389b50 Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Tue, 8 Sep 2020 14:16:18 +0300 Subject: [PATCH 3/3] magento/magento2#25147: Totals Information Management - setting quote shipping method when address method is null - static test fix. --- app/code/Magento/Sales/Test/Unit/Model/OrderRepositoryTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Sales/Test/Unit/Model/OrderRepositoryTest.php b/app/code/Magento/Sales/Test/Unit/Model/OrderRepositoryTest.php index 407d158e6f8d4..2e51bd8d75b89 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/OrderRepositoryTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/OrderRepositoryTest.php @@ -72,7 +72,7 @@ class OrderRepositoryTest extends TestCase private $paymentAdditionalInfoFactory; /** - * @var OrderExtensionFactory|\PHPUnit_Framework_MockObject_MockObject + * @var OrderExtensionFactory|\MockObject */ private $orderExtensionFactoryMock;