|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Magento\Bundle\Test\Unit\Model\Sales\Order\Plugin; |
| 8 | + |
| 9 | +class ItemTest extends \PHPUnit_Framework_TestCase |
| 10 | +{ |
| 11 | + private $plugin; |
| 12 | + |
| 13 | + private $itemMock; |
| 14 | + |
| 15 | + protected function setUp() |
| 16 | + { |
| 17 | + $this->itemMock = $this->getMockBuilder(\Magento\Sales\Model\Order\Item::class) |
| 18 | + ->disableOriginalConstructor() |
| 19 | + ->getMock(); |
| 20 | + $this->plugin = new \Magento\Bundle\Model\Sales\Order\Plugin\Item(); |
| 21 | + } |
| 22 | + |
| 23 | + public function testAfterGetQtyToCancelIfProductIsBundle() |
| 24 | + { |
| 25 | + $qtyToCancel = 10; |
| 26 | + $result = 5; |
| 27 | + |
| 28 | + $this->itemMock |
| 29 | + ->expects($this->once()) |
| 30 | + ->method('getProductType') |
| 31 | + ->willReturn(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE); |
| 32 | + $this->itemMock->expects($this->once())->method('isDummy')->willReturn(true); |
| 33 | + $this->itemMock->expects($this->once())->method('getQtyToInvoice')->willReturn(15); |
| 34 | + $this->itemMock->expects($this->once())->method('getSimpleQtyToShip')->willReturn($qtyToCancel); |
| 35 | + $this->assertEquals($qtyToCancel, $this->plugin->afterGetQtyToCancel($this->itemMock, $result)); |
| 36 | + } |
| 37 | + |
| 38 | + public function testAfterGetQtyToCancelIfParentProductIsBundle() |
| 39 | + { |
| 40 | + $qtyToCancel = 10; |
| 41 | + $result = 5; |
| 42 | + $parentItemMock = $this->getMockBuilder(\Magento\Sales\Model\Order\Item::class) |
| 43 | + ->disableOriginalConstructor() |
| 44 | + ->getMock(); |
| 45 | + $this->itemMock |
| 46 | + ->expects($this->once()) |
| 47 | + ->method('getProductType') |
| 48 | + ->willReturn(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE); |
| 49 | + $this->itemMock->expects($this->any())->method('getParentItem')->willReturn($parentItemMock); |
| 50 | + $parentItemMock->expects($this->once()) |
| 51 | + ->method('getProductType') |
| 52 | + ->willReturn(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE); |
| 53 | + $this->itemMock->expects($this->once())->method('isDummy')->willReturn(false); |
| 54 | + $this->itemMock->expects($this->once())->method('getQtyToInvoice')->willReturn(15); |
| 55 | + $this->itemMock->expects($this->once())->method('getQtyToShip')->willReturn($qtyToCancel); |
| 56 | + $this->assertEquals($qtyToCancel, $this->plugin->afterGetQtyToCancel($this->itemMock, $result)); |
| 57 | + } |
| 58 | + public function testAfterGetQtyToCancelForSimpleProduct() |
| 59 | + { |
| 60 | + $result = 5; |
| 61 | + $this->itemMock |
| 62 | + ->expects($this->once()) |
| 63 | + ->method('getProductType') |
| 64 | + ->willReturn(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE); |
| 65 | + $this->itemMock->expects($this->any())->method('getParentItem')->willReturn(false); |
| 66 | + $this->itemMock->expects($this->never())->method('isDummy'); |
| 67 | + $this->itemMock->expects($this->never())->method('getQtyToInvoice'); |
| 68 | + $this->assertEquals($result, $this->plugin->afterGetQtyToCancel($this->itemMock, $result)); |
| 69 | + } |
| 70 | + |
| 71 | + public function testAfterIsProcessingAvailableForProductWithoutParent() |
| 72 | + { |
| 73 | + $this->itemMock->expects($this->once())->method('getParentItem')->willReturn(false); |
| 74 | + $this->assertFalse($this->plugin->afterIsProcessingAvailable($this->itemMock, false)); |
| 75 | + } |
| 76 | + |
| 77 | + public function testAfterIsProcessingAvailableForProductWhenParentIsBundle() |
| 78 | + { |
| 79 | + $parentItemMock = $this->getMockBuilder(\Magento\Sales\Model\Order\Item::class) |
| 80 | + ->disableOriginalConstructor() |
| 81 | + ->getMock(); |
| 82 | + $this->itemMock->expects($this->any())->method('getParentItem')->willReturn($parentItemMock); |
| 83 | + $parentItemMock->expects($this->once()) |
| 84 | + ->method('getProductType') |
| 85 | + ->willReturn(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE); |
| 86 | + $this->itemMock->expects($this->once())->method('getSimpleQtyToShip')->willReturn(10); |
| 87 | + $this->itemMock->expects($this->once())->method('getQtyToCancel')->willReturn(5); |
| 88 | + $this->assertTrue($this->plugin->afterIsProcessingAvailable($this->itemMock, false)); |
| 89 | + } |
| 90 | +} |
0 commit comments