|
30 | 30 | use Magento\Framework\DataObject\Copy;
|
31 | 31 | use Magento\Framework\DataObject\Factory;
|
32 | 32 | use Magento\Framework\Event\Manager;
|
| 33 | +use Magento\Framework\Exception\LocalizedException; |
33 | 34 | use Magento\Framework\Exception\NoSuchEntityException;
|
34 | 35 | use Magento\Framework\Model\Context;
|
35 | 36 | use Magento\Framework\Phrase;
|
@@ -1072,17 +1073,28 @@ public function testAddProductItemPreparation(): void
|
1072 | 1073 | }
|
1073 | 1074 |
|
1074 | 1075 | /**
|
| 1076 | + * @param $request |
| 1077 | + * @param $hasError |
1075 | 1078 | * @return void
|
| 1079 | + * @throws LocalizedException |
| 1080 | + * @dataProvider dataProviderForTestAddProductItem |
1076 | 1081 | */
|
1077 |
| - public function testAddProductItemNew(): void |
| 1082 | + public function testAddProductItemNew($request, $hasError): void |
1078 | 1083 | {
|
1079 |
| - $itemMock = $this->createMock(Item::class); |
| 1084 | + $itemMock = $this->getMockBuilder(Item::class) |
| 1085 | + ->disableOriginalConstructor() |
| 1086 | + ->addMethods(['getHasError']) |
| 1087 | + ->onlyMethods(['representProduct', 'setProduct', 'setOptions', 'setQuote', 'getProduct']) |
| 1088 | + ->getMock(); |
| 1089 | + $itemMock->expects($this->once())->method('getHasError')->willReturn($hasError); |
| 1090 | + $product = $this->createMock(Product::class); |
| 1091 | + $itemMock->expects($this->any())->method('getProduct')->willReturn($product); |
1080 | 1092 |
|
1081 | 1093 | $expectedResult = $itemMock;
|
1082 | 1094 | $requestMock = $this->createMock(
|
1083 | 1095 | DataObject::class
|
1084 | 1096 | );
|
1085 |
| - $this->objectFactoryMock->expects($this->once()) |
| 1097 | + $this->objectFactoryMock->expects($this->any()) |
1086 | 1098 | ->method('create')
|
1087 | 1099 | ->with(['qty' => 1])
|
1088 | 1100 | ->willReturn($requestMock);
|
@@ -1145,10 +1157,29 @@ public function testAddProductItemNew(): void
|
1145 | 1157 | ->method('getTypeInstance')
|
1146 | 1158 | ->willReturn($typeInstanceMock);
|
1147 | 1159 |
|
1148 |
| - $result = $this->quote->addProduct($this->productMock, null); |
| 1160 | + $result = $this->quote->addProduct($this->productMock, $request); |
1149 | 1161 | $this->assertEquals($expectedResult, $result);
|
1150 | 1162 | }
|
1151 | 1163 |
|
| 1164 | + /** |
| 1165 | + * @return array[] |
| 1166 | + */ |
| 1167 | + private function dataProviderForTestAddProductItem(): array |
| 1168 | + { |
| 1169 | + return [ |
| 1170 | + 'not_force_item' => [null, false], |
| 1171 | + 'force_item' => [ |
| 1172 | + new DataObject( |
| 1173 | + [ |
| 1174 | + 'force_add_to_cart' => true, |
| 1175 | + 'qty' => 1 |
| 1176 | + ] |
| 1177 | + ), |
| 1178 | + true |
| 1179 | + ] |
| 1180 | + ]; |
| 1181 | + } |
| 1182 | + |
1152 | 1183 | /**
|
1153 | 1184 | * @return void
|
1154 | 1185 | */
|
|
0 commit comments