|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\Quote\Model\Product\Plugin; |
| 9 | + |
| 10 | +use Magento\Quote\Model\ResourceModel\Quote as QuoteResource; |
| 11 | +use Magento\TestFramework\Helper\Bootstrap; |
| 12 | +use Magento\TestFramework\Quote\Model\GetQuoteByReservedOrderId; |
| 13 | +use PHPUnit\Framework\TestCase; |
| 14 | + |
| 15 | +/** |
| 16 | + * Tests for update quote plugin. |
| 17 | + * |
| 18 | + * @magentoAppArea adminhtml |
| 19 | + */ |
| 20 | +class UpdateQuoteTest extends TestCase |
| 21 | +{ |
| 22 | + /** |
| 23 | + * @var GetQuoteByReservedOrderId |
| 24 | + */ |
| 25 | + private $getQuoteByReservedOrderId; |
| 26 | + |
| 27 | + /** |
| 28 | + * @inheritdoc |
| 29 | + */ |
| 30 | + protected function setUp(): void |
| 31 | + { |
| 32 | + parent::setUp(); |
| 33 | + |
| 34 | + $objectManager = Bootstrap::getObjectManager(); |
| 35 | + $this->getQuoteByReservedOrderId = $objectManager->get(GetQuoteByReservedOrderId::class); |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * Test to update the column trigger_recollect is 1 from quote table. |
| 40 | + * |
| 41 | + * @magentoDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php |
| 42 | + * @return void |
| 43 | + */ |
| 44 | + public function testUpdateQuoteRecollectAfterChangeProductPrice(): void |
| 45 | + { |
| 46 | + $quote = $this->getQuoteByReservedOrderId->execute('test_order_with_simple_product_without_address'); |
| 47 | + $this->assertNotNull($quote); |
| 48 | + $this->assertFalse((bool)$quote->getTriggerRecollect()); |
| 49 | + $this->assertNotEmpty($quote->getItems()); |
| 50 | + $quoteItem = current($quote->getItems()); |
| 51 | + $product = $quoteItem->getProduct(); |
| 52 | + |
| 53 | + /** @var QuoteResource $quoteResource */ |
| 54 | + $quoteResource = $quote->getResource(); |
| 55 | + $quoteResource->markQuotesRecollect($product->getId()); |
| 56 | + /** @var AdapterInterface $connection */ |
| 57 | + $connection = $quoteResource->getConnection(); |
| 58 | + $select = $connection->select() |
| 59 | + ->from( |
| 60 | + $quoteResource->getTable('quote'), |
| 61 | + ['trigger_recollect'] |
| 62 | + )->where( |
| 63 | + "reserved_order_id = 'test_order_with_simple_product_without_address'" |
| 64 | + ); |
| 65 | + |
| 66 | + $quoteRow = $connection->fetchRow($select); |
| 67 | + $this->assertNotEmpty($quoteRow); |
| 68 | + $this->assertTrue((bool)$quoteRow['trigger_recollect']); |
| 69 | + } |
| 70 | +} |
0 commit comments