/
githubmirror
/
magento2
Обзор
Документация
Войти
/
githubmirror
/
magento2
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
2.4-develop
dev/tests/integration/testsuite/Magento/Persistent/Model/Checkout/ConfigProviderPluginTest.php
182 строки
7 KB
Oleksandr Dubovyk
ACP2E-4682: Empty quote records are being created when customer visits a page
31 мар 2026, 21:13
31 мар 2026, 21:13
efd960f
Код
Авторство
О чём код?
<?php /** * Copyright 2020 Adobe * All Rights Reserved. */ declare(strict_types=1); namespace Magento\Persistent\Model\Checkout; use Magento\Customer\Model\Session as CustomerSession; use Magento\Checkout\Model\DefaultConfigProvider; use Magento\Checkout\Model\Session as CheckoutSession; use Magento\Framework\ObjectManagerInterface; use Magento\Persistent\Helper\Session as PersistentSessionHelper; use Magento\Persistent\Model\Session as PersistentSession; use Magento\Persistent\Model\SessionFactory as PersistentSessionFactory; use Magento\Quote\Model\QuoteIdMask; use Magento\Quote\Model\QuoteIdMaskFactory; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\Interception\PluginList; use Magento\TestFramework\Quote\Model\GetQuoteByReservedOrderId; use PHPUnit\Framework\TestCase; use Magento\TestFramework\Fixture\DataFixture; use Magento\TestFramework\Fixture\Config; use Magento\Customer\Test\Fixture\Customer; use Magento\Quote\Test\Fixture\CustomerCart; use Magento\Catalog\Test\Fixture\Product as ProductFixture; use Magento\Quote\Test\Fixture\AddProductToCart as AddProductToCartFixture; /** * Test for checkout config provider plugin * * @see \Magento\Persistent\Model\Checkout\ConfigProviderPlugin * @magentoAppArea frontend * @magentoDbIsolation enabled * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class ConfigProviderPluginTest extends TestCase { /** @var ObjectManagerInterface */ private $objectManager; /** @var DefaultConfigProvider */ private $configProvider; /** @var CustomerSession */ private $customerSession; /** @var CheckoutSession */ private $checkoutSession; /** @var QuoteIdMask */ private $quoteIdMask; /** @var PersistentSessionHelper */ private $persistentSessionHelper; /** @var PersistentSession */ private $persistentSession; /** @var GetQuoteByReservedOrderId */ private $getQuoteByReservedOrderId; /** * @inheritdoc */ protected function setUp(): void { parent::setUp(); $this->objectManager = Bootstrap::getObjectManager(); $this->configProvider = $this->objectManager->get(DefaultConfigProvider::class); $this->customerSession = $this->objectManager->get(CustomerSession::class); $this->checkoutSession = $this->objectManager->get(CheckoutSession::class); $this->quoteIdMask = $this->objectManager->get(QuoteIdMaskFactory::class)->create(); $this->persistentSessionHelper = $this->objectManager->get(PersistentSessionHelper::class); $this->persistentSession = $this->objectManager->get(PersistentSessionFactory::class)->create(); $this->getQuoteByReservedOrderId = $this->objectManager->get(GetQuoteByReservedOrderId::class); } /** * @inheritdoc */ protected function tearDown(): void { $this->customerSession->setCustomerId(null); $this->checkoutSession->clearQuote(); $this->checkoutSession->setCustomerData(null); $this->persistentSessionHelper->setSession(null); parent::tearDown(); } /** * @return void */ public function testPluginIsRegistered(): void { $pluginInfo = $this->objectManager->get(PluginList::class)->get(DefaultConfigProvider::class); $this->assertSame(ConfigProviderPlugin::class, $pluginInfo['mask_quote_id_substitutor']['instance']); } /** * @magentoDataFixture Magento/Persistent/_files/persistent_with_customer_quote_and_cookie.php * @magentoConfigFixture current_store persistent/options/enabled 1 * * @return void */ public function testWithNotLoggedCustomer(): void { $session = $this->persistentSession->loadByCustomerId(1); $this->persistentSessionHelper->setSession($session); $quote = $this->getQuoteByReservedOrderId->execute('test_order_with_customer_without_address'); $this->checkoutSession->setQuoteId($quote->getId()); $result = $this->configProvider->getConfig(); $this->assertEquals( $this->quoteIdMask->load($quote->getId(), 'quote_id')->getMaskedId(), $this->quoteIdMask->load($result['quoteData']['entity_id'], 'quote_id')->getMaskedId() ); } /** * @magentoDataFixture Magento/Persistent/_files/persistent_with_customer_quote_and_cookie.php * @magentoConfigFixture current_store persistent/options/enabled 1 * * @return void */ public function testWithLoggedCustomer(): void { $this->customerSession->setCustomerId(1); $session = $this->persistentSession->loadByCustomerId(1); $this->persistentSessionHelper->setSession($session); $quote = $this->getQuoteByReservedOrderId->execute('test_order_with_customer_without_address'); $this->checkoutSession->setQuoteId($quote->getId()); $result = $this->configProvider->getConfig(); $this->assertEquals($quote->getId(), $result['quoteData']['entity_id']); } /** * @return void */ #[ Config('persistent/options/enabled', 0, scopeType: \Magento\Store\Model\ScopeInterface::SCOPE_STORE), DataFixture(Customer::class, as: 'customer'), DataFixture( CustomerCart::class, ['customer_id' => '$customer.id$', 'reserved_order_id' => 'test_order_with_customer_without_address'], as: 'cart' ), DataFixture(ProductFixture::class, as: 'product'), DataFixture(AddProductToCartFixture::class, ['cart_id' => '$cart.id$', 'product_id' => '$product.id$']), ] public function testPersistentDisabled(): void { $quote = $this->getQuoteByReservedOrderId->execute('test_order_with_customer_without_address'); $this->checkoutSession->setQuoteId($quote->getId()); $result = $this->configProvider->getConfig(); $this->assertEquals($quote->getEntityId(), $result['quoteData']['entity_id']); } /** * @return void */ #[ Config('persistent/options/enabled', 1, scopeType: \Magento\Store\Model\ScopeInterface::SCOPE_STORE), DataFixture(Customer::class, as: 'customer'), DataFixture( CustomerCart::class, ['customer_id' => '$customer.id$', 'reserved_order_id' => 'test_order_with_customer_without_address'], as: 'cart' ), DataFixture(ProductFixture::class, as: 'product'), DataFixture(AddProductToCartFixture::class, ['cart_id' => '$cart.id$', 'product_id' => '$product.id$']), ] public function testWithoutPersistentSession(): void { $quote = $this->getQuoteByReservedOrderId->execute('test_order_with_customer_without_address'); $this->checkoutSession->setQuoteId($quote->getId()); $result = $this->configProvider->getConfig(); $this->assertEquals($quote->getEntityId(), $result['quoteData']['entity_id']); } }