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(), $result['quoteData']['entity_id'] ); } /** * @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']); } /** * @magentoDataFixture Magento/Checkout/_files/quote_with_customer_without_address.php * @magentoConfigFixture current_store persistent/options/enabled 0 * * @return void */ public function testPersistentDisabled(): void { $quote = $this->getQuoteByReservedOrderId->execute('test_order_with_customer_without_address'); $this->checkoutSession->setQuoteId($quote->getId()); $result = $this->configProvider->getConfig(); $this->assertNull($result['quoteData']['entity_id']); } /** * @magentoDataFixture Magento/Checkout/_files/quote_with_customer_without_address.php * @magentoConfigFixture current_store persistent/options/enabled 1 * * @return void */ public function testWithoutPersistentSession(): void { $quote = $this->getQuoteByReservedOrderId->execute('test_order_with_customer_without_address'); $this->checkoutSession->setQuoteId($quote->getId()); $result = $this->configProvider->getConfig(); $this->assertNull($result['quoteData']['entity_id']); } }