|
10 | 10 | use Magento\Catalog\Api\ProductRepositoryInterface;
|
11 | 11 | use Magento\Catalog\Model\Product\Type;
|
12 | 12 | use Magento\Customer\Api\CustomerRepositoryInterface;
|
| 13 | +use Magento\Customer\Model\Vat; |
| 14 | +use Magento\Framework\App\Config\ScopeConfigInterface; |
| 15 | +use Magento\Framework\DataObject; |
13 | 16 | use Magento\Framework\Exception\LocalizedException;
|
14 | 17 | use Magento\Framework\Exception\StateException;
|
15 | 18 | use Magento\Framework\ObjectManagerInterface;
|
16 | 19 | use Magento\Quote\Api\CartManagementInterface;
|
| 20 | +use Magento\Quote\Observer\Frontend\Quote\Address\CollectTotalsObserver; |
| 21 | +use Magento\Quote\Observer\Frontend\Quote\Address\VatValidator; |
17 | 22 | use Magento\Sales\Api\OrderManagementInterface;
|
18 | 23 | use Magento\Sales\Api\OrderRepositoryInterface;
|
19 | 24 | use Magento\Store\Model\StoreManagerInterface;
|
20 | 25 | use Magento\TestFramework\Helper\Bootstrap;
|
21 | 26 | use Magento\TestFramework\Quote\Model\GetQuoteByReservedOrderId;
|
22 | 27 | use PHPUnit\Framework\ExpectationFailedException;
|
23 | 28 | use PHPUnit\Framework\TestCase;
|
| 29 | +use Psr\Log\LoggerInterface; |
24 | 30 |
|
25 | 31 | /**
|
26 | 32 | * Class for testing QuoteManagement model
|
@@ -106,6 +112,28 @@ public function testSubmit(): void
|
106 | 112 | }
|
107 | 113 | }
|
108 | 114 |
|
| 115 | + /** |
| 116 | + * Verify guest customer place order with auto-group assigment. |
| 117 | + * |
| 118 | + * @magentoDataFixture Magento/Sales/_files/guest_quote_with_addresses.php |
| 119 | + * |
| 120 | + * @magentoConfigFixture default_store customer/create_account/auto_group_assign 1 |
| 121 | + * @magentoConfigFixture default_store customer/create_account/tax_calculation_address_type shipping |
| 122 | + * @magentoConfigFixture default_store customer/create_account/viv_intra_union_group 2 |
| 123 | + * @magentoConfigFixture default_store customer/create_account/viv_on_each_transaction 1 |
| 124 | + * |
| 125 | + * @return void |
| 126 | + */ |
| 127 | + public function testSubmitGuestCustomer(): void |
| 128 | + { |
| 129 | + $this->mockVatValidation(); |
| 130 | + $quote = $this->getQuoteByReservedOrderId->execute('guest_quote'); |
| 131 | + $this->cartManagement->placeOrder($quote->getId()); |
| 132 | + $quoteAfterOrderPlaced = $this->getQuoteByReservedOrderId->execute('guest_quote'); |
| 133 | + self::assertEquals(2, $quoteAfterOrderPlaced->getCustomerGroupId()); |
| 134 | + self::assertEquals(3, $quoteAfterOrderPlaced->getCustomerTaxClassId()); |
| 135 | + } |
| 136 | + |
109 | 137 | /**
|
110 | 138 | * Tries to create order with product that has child items and one of them was deleted.
|
111 | 139 | *
|
@@ -231,4 +259,33 @@ private function makeProductOutOfStock(string $sku): void
|
231 | 259 | $stockItem->setIsInStock(false);
|
232 | 260 | $this->productRepository->save($product);
|
233 | 261 | }
|
| 262 | + |
| 263 | + /** |
| 264 | + * Makes customer vat validator 'check vat number' response successful. |
| 265 | + * |
| 266 | + * @return void |
| 267 | + */ |
| 268 | + private function mockVatValidation(): void |
| 269 | + { |
| 270 | + $vatMock = $this->getMockBuilder(Vat::class) |
| 271 | + ->setConstructorArgs( |
| 272 | + [ |
| 273 | + 'scopeConfig' => $this->objectManager->get(ScopeConfigInterface::class), |
| 274 | + 'logger' => $this->objectManager->get(LoggerInterface::class), |
| 275 | + ] |
| 276 | + ) |
| 277 | + ->onlyMethods(['checkVatNumber']) |
| 278 | + ->getMock(); |
| 279 | + $gatewayResponse = new DataObject([ |
| 280 | + 'is_valid' => true, |
| 281 | + 'request_date' => 'testData', |
| 282 | + 'request_identifier' => 'testRequestIdentifier', |
| 283 | + 'request_success' => true, |
| 284 | + ]); |
| 285 | + $vatMock->method('checkVatNumber')->willReturn($gatewayResponse); |
| 286 | + $this->objectManager->removeSharedInstance(CollectTotalsObserver::class); |
| 287 | + $this->objectManager->removeSharedInstance(VatValidator::class); |
| 288 | + $this->objectManager->removeSharedInstance(Vat::class); |
| 289 | + $this->objectManager->addSharedInstance($vatMock, Vat::class); |
| 290 | + } |
234 | 291 | }
|
0 commit comments