|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2016 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Magento\GiftMessage\Test\Unit\Model\Plugin; |
| 8 | + |
| 9 | +class OrderGetListTest extends \PHPUnit_Framework_TestCase |
| 10 | +{ |
| 11 | + /** |
| 12 | + * @var \Magento\GiftMessage\Model\Plugin\OrderGet |
| 13 | + */ |
| 14 | + private $plugin; |
| 15 | + |
| 16 | + /** |
| 17 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 18 | + */ |
| 19 | + private $giftMessageOrderRepositoryMock; |
| 20 | + |
| 21 | + /** |
| 22 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 23 | + */ |
| 24 | + private $giftMessageOrderItemRepositoryMock; |
| 25 | + |
| 26 | + /** |
| 27 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 28 | + */ |
| 29 | + private $orderExtensionFactoryMock; |
| 30 | + |
| 31 | + /** |
| 32 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 33 | + */ |
| 34 | + private $orderItemExtensionFactoryMock; |
| 35 | + |
| 36 | + /** |
| 37 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 38 | + */ |
| 39 | + private $orderMock; |
| 40 | + |
| 41 | + /** |
| 42 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 43 | + */ |
| 44 | + private $orderExtensionMock; |
| 45 | + |
| 46 | + /** |
| 47 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 48 | + */ |
| 49 | + private $giftMessageMock; |
| 50 | + |
| 51 | + /** |
| 52 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 53 | + */ |
| 54 | + private $orderRepositoryMock; |
| 55 | + |
| 56 | + /** |
| 57 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 58 | + */ |
| 59 | + private $collectionMock; |
| 60 | + |
| 61 | + public function setUp() |
| 62 | + { |
| 63 | + $this->giftMessageOrderRepositoryMock = $this->getMock( |
| 64 | + \Magento\GiftMessage\Api\OrderRepositoryInterface::class |
| 65 | + ); |
| 66 | + $this->giftMessageOrderItemRepositoryMock = $this->getMock( |
| 67 | + \Magento\GiftMessage\Api\OrderItemRepositoryInterface::class |
| 68 | + ); |
| 69 | + $this->orderExtensionFactoryMock = $this->getMock( |
| 70 | + \Magento\Sales\Api\Data\OrderExtensionFactory::class, |
| 71 | + ['create'], |
| 72 | + [], |
| 73 | + '', |
| 74 | + false |
| 75 | + ); |
| 76 | + $this->orderItemExtensionFactoryMock = $this->getMock( |
| 77 | + \Magento\Sales\Api\Data\OrderItemExtensionFactory::class, |
| 78 | + ['create'], |
| 79 | + [], |
| 80 | + '', |
| 81 | + false |
| 82 | + ); |
| 83 | + $this->orderMock = $this->getMock( |
| 84 | + \Magento\Sales\Api\Data\OrderInterface::class |
| 85 | + ); |
| 86 | + $this->orderExtensionMock = $this->getMock( |
| 87 | + \Magento\Sales\Api\Data\OrderExtension::class, |
| 88 | + ['getGiftMessage', 'setGiftMessage'], |
| 89 | + [], |
| 90 | + '', |
| 91 | + false |
| 92 | + ); |
| 93 | + $this->giftMessageMock = $this->getMock( |
| 94 | + \Magento\GiftMessage\Api\Data\MessageInterface::class |
| 95 | + ); |
| 96 | + |
| 97 | + $this->orderRepositoryMock = $this->getMock( |
| 98 | + \Magento\Sales\Api\OrderRepositoryInterface::class |
| 99 | + ); |
| 100 | + |
| 101 | + $this->collectionMock = $this->getMock( |
| 102 | + \Magento\Sales\Model\ResourceModel\Order\Collection::class, |
| 103 | + [], |
| 104 | + [], |
| 105 | + '', |
| 106 | + false |
| 107 | + ); |
| 108 | + $this->plugin = new \Magento\GiftMessage\Model\Plugin\OrderGetList( |
| 109 | + $this->giftMessageOrderRepositoryMock, |
| 110 | + $this->giftMessageOrderItemRepositoryMock, |
| 111 | + $this->orderExtensionFactoryMock, |
| 112 | + $this->orderItemExtensionFactoryMock |
| 113 | + ); |
| 114 | + } |
| 115 | + |
| 116 | + public function testAfterGetList() |
| 117 | + { |
| 118 | + //set Gift Message List for Order |
| 119 | + $orderId = 1; |
| 120 | + $this->orderMock->expects($this->once())->method('getEntityId')->willReturn($orderId); |
| 121 | + $this->orderMock |
| 122 | + ->expects($this->once()) |
| 123 | + ->method('getExtensionAttributes') |
| 124 | + ->willReturn($this->orderExtensionMock); |
| 125 | + $this->orderExtensionMock->expects($this->once())->method('getGiftMessage')->willReturn([]); |
| 126 | + $this->giftMessageOrderRepositoryMock |
| 127 | + ->expects($this->once()) |
| 128 | + ->method('get') |
| 129 | + ->with($orderId) |
| 130 | + ->willReturn($this->giftMessageMock); |
| 131 | + $this->orderExtensionMock |
| 132 | + ->expects($this->once()) |
| 133 | + ->method('setGiftMessage') |
| 134 | + ->with($this->giftMessageMock) |
| 135 | + ->willReturnSelf(); |
| 136 | + $this->orderMock |
| 137 | + ->expects($this->once()) |
| 138 | + ->method('setExtensionAttributes') |
| 139 | + ->with($this->orderExtensionMock) |
| 140 | + ->willReturnSelf(); |
| 141 | + |
| 142 | + // set Gift Message on Item Level |
| 143 | + $this->orderMock->expects($this->once())->method('getItems')->willReturn([]); |
| 144 | + $this->collectionMock->expects($this->once())->method('getItems')->willReturn([$this->orderMock]); |
| 145 | + $this->plugin->afterGetList($this->orderRepositoryMock, $this->collectionMock); |
| 146 | + } |
| 147 | + |
| 148 | +} |
0 commit comments