objectManager = Bootstrap::getObjectManager(); $this->layout = $this->objectManager->get(LayoutInterface::class); $this->storeManager = $this->objectManager->get(StoreManagerInterface::class); } /** * @magentoConfigFixture current_store currency/options/allow USD * * @return void */ public function testDefaultCurrencySwitcher(): void { $this->assertCurrencySwitcherPerStore(''); } /** * @magentoConfigFixture current_store currency/options/allow EUR,USD * * @return void */ public function testCurrencySwitcher(): void { $this->assertCurrencySwitcherPerStore('Currency USD - US Dollar EUR - Euro'); } /** * @magentoConfigFixture current_store currency/options/allow USD,CNY * @magentoConfigFixture fixturestore_store currency/options/allow USD,UAH * * @magentoDataFixture Magento/Store/_files/core_fixturestore.php * @magentoDataFixture Magento/Directory/_files/usd_cny_rate.php * @magentoDataFixture Magento/Directory/_files/usd_uah_rate.php * * @return void */ public function testMultiStoreCurrencySwitcher(): void { $this->assertCurrencySwitcherPerStore('Currency USD - US Dollar CNY - Chinese Yuan'); $this->assertCurrencySwitcherPerStore('Currency USD - US Dollar UAH - Ukrainian Hryvnia', 'fixturestore'); } /** * Check currency switcher diplaying per stores * * @param string $expectedData * @param string $storeCode * @return void */ private function assertCurrencySwitcherPerStore( string $expectedData, string $storeCode = 'default' ): void { $currentStore = $this->storeManager->getStore(); try { if ($currentStore->getCode() !== $storeCode) { $this->storeManager->setCurrentStore($storeCode); } $actualData = trim(preg_replace('/\s+/', ' ', strip_tags($this->getBlock()->toHtml()))); $this->assertEquals($expectedData, $actualData); } finally { if ($currentStore->getCode() !== $storeCode) { $this->storeManager->setCurrentStore($currentStore); } } } /** * Get currency block * * @return Currency */ private function getBlock(): Currency { $block = $this->layout->createBlock(Currency::class); $block->setTemplate(self::CURRENCY_SWITCHER_TEMPLATE); return $block; } }