|
10 | 10 |
|
11 | 11 | use Magento\Quote\Model\Quote\Address;
|
12 | 12 | use Magento\Store\Model\ScopeInterface;
|
| 13 | +use Magento\Quote\Api\Data\CartInterface; |
13 | 14 | use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
|
14 | 15 |
|
15 | 16 | /**
|
@@ -1040,4 +1041,94 @@ public function testAddItem()
|
1040 | 1041 |
|
1041 | 1042 | $this->quote->addItem($item);
|
1042 | 1043 | }
|
| 1044 | + |
| 1045 | + /** |
| 1046 | + * @param array $productTypes |
| 1047 | + * @param int $expected |
| 1048 | + * @dataProvider dataProviderForTestBeforeSaveIsVirtualQuote |
| 1049 | + */ |
| 1050 | + public function testBeforeSaveIsVirtualQuote(array $productTypes, $expected) |
| 1051 | + { |
| 1052 | + $storeId = 1; |
| 1053 | + $currencyMock = $this->getMockBuilder('Magento\Directory\Model\Currency') |
| 1054 | + ->disableOriginalConstructor() |
| 1055 | + ->getMock(); |
| 1056 | + $currencyMock->expects($this->any()) |
| 1057 | + ->method('getCode') |
| 1058 | + ->will($this->returnValue('test_code')); |
| 1059 | + $currencyMock->expects($this->any()) |
| 1060 | + ->method('getRate') |
| 1061 | + ->will($this->returnValue('test_rate')); |
| 1062 | + $storeMock = $this->getMockBuilder('Magento\Store\Model\Store') |
| 1063 | + ->disableOriginalConstructor() |
| 1064 | + ->getMock(); |
| 1065 | + $storeMock->expects($this->once()) |
| 1066 | + ->method('getBaseCurrency') |
| 1067 | + ->will($this->returnValue($currencyMock)); |
| 1068 | + $storeMock->expects($this->once()) |
| 1069 | + ->method('getCurrentCurrency') |
| 1070 | + ->will($this->returnValue($currencyMock)); |
| 1071 | + |
| 1072 | + $this->storeManagerMock->expects($this->any()) |
| 1073 | + ->method('getStore') |
| 1074 | + ->with($storeId) |
| 1075 | + ->will($this->returnValue($storeMock)); |
| 1076 | + $this->quote->setStoreId($storeId); |
| 1077 | + |
| 1078 | + $collectionMock = $this->getMock( |
| 1079 | + 'Magento\Quote\Model\Resource\Quote\Item\Collection', |
| 1080 | + [], |
| 1081 | + [], |
| 1082 | + '', |
| 1083 | + false |
| 1084 | + ); |
| 1085 | + $items = []; |
| 1086 | + foreach ($productTypes as $type) { |
| 1087 | + $productMock = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false);; |
| 1088 | + $productMock->expects($this->any())->method('getIsVirtual')->willReturn($type); |
| 1089 | + |
| 1090 | + $itemMock = $this->getMock( |
| 1091 | + 'Magento\Quote\Model\Quote\Item', |
| 1092 | + ['isDeleted', 'getParentItemId', 'getProduct'], |
| 1093 | + [], |
| 1094 | + '', |
| 1095 | + false |
| 1096 | + ); |
| 1097 | + $itemMock->expects($this->any()) |
| 1098 | + ->method('isDeleted') |
| 1099 | + ->willReturn(false); |
| 1100 | + $itemMock->expects($this->any()) |
| 1101 | + ->method('getParentItemId') |
| 1102 | + ->willReturn(false); |
| 1103 | + $itemMock->expects($this->any()) |
| 1104 | + ->method('getProduct') |
| 1105 | + ->willReturn($productMock); |
| 1106 | + $items[] = $itemMock; |
| 1107 | + } |
| 1108 | + $iterator = new \ArrayIterator($items); |
| 1109 | + $collectionMock->expects($this->any()) |
| 1110 | + ->method('getIterator') |
| 1111 | + ->will($this->returnValue($iterator)); |
| 1112 | + $this->quoteItemCollectionFactoryMock->expects($this->once()) |
| 1113 | + ->method('create') |
| 1114 | + ->will($this->returnValue($collectionMock)); |
| 1115 | + |
| 1116 | + $this->quote->beforeSave(); |
| 1117 | + $this->assertEquals($expected, $this->quote->getDataByKey(CartInterface::KEY_IS_VIRTUAL)); |
| 1118 | + } |
| 1119 | + |
| 1120 | + |
| 1121 | + /** |
| 1122 | + * @return array |
| 1123 | + */ |
| 1124 | + public function dataProviderForTestBeforeSaveIsVirtualQuote() |
| 1125 | + { |
| 1126 | + return [ |
| 1127 | + [[true], 1], |
| 1128 | + [[true, true], 1], |
| 1129 | + [[false], 0], |
| 1130 | + [[true, false], 0], |
| 1131 | + [[false, false], 0] |
| 1132 | + ]; |
| 1133 | + } |
1043 | 1134 | }
|
0 commit comments