Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
StoreSwitcherTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
8 namespace Magento\Store\Model;
9 
10 use Magento\Framework\ObjectManagerInterface as ObjectManager;
12 
13 class StoreSwitcherTest extends \PHPUnit\Framework\TestCase
14 {
18  private $storeSwitcher;
19 
23  private $objectManager;
24 
30  protected function setUp()
31  {
32  $this->objectManager = Bootstrap::getObjectManager();
33  $this->storeSwitcher = $this->objectManager->get(StoreSwitcher::class);
34  }
35 
43  public function testSwitch(): void
44  {
45  $redirectUrl = "http://domain.com/?SID=e5h3e086dce3ckkqt9ia7avl27&___store=fixture_second_store";
46  $expectedUrl = "http://domain.com/";
47  $fromStoreCode = 'test';
49  $storeRepository = $this->objectManager->create(\Magento\Store\Api\StoreRepositoryInterface::class);
50  $fromStore = $storeRepository->get($fromStoreCode);
51 
52  $toStoreCode = 'fixture_second_store';
54  $storeRepository = $this->objectManager->create(\Magento\Store\Api\StoreRepositoryInterface::class);
55  $toStore = $storeRepository->get($toStoreCode);
56 
57  $this->assertEquals($expectedUrl, $this->storeSwitcher->switch($fromStore, $toStore, $redirectUrl));
58  }
59 }