6 declare(strict_types=1);
24 private $storeSwitcher;
29 private $objectManager;
34 private $productRepository;
44 $this->storeSwitcher = $this->objectManager->get(StoreSwitcher::class);
45 $this->productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
55 public function testSwitchToNonExistingPage(): void
57 $fromStoreCode =
'default';
62 $toStoreCode =
'fixture_second_store';
67 $this->setBaseUrl($toStore);
69 $product = $this->productRepository->get(
'simple333');
71 $redirectUrl =
"http://domain.com/{$product->getUrlKey()}.html";
72 $expectedUrl = $toStore->getBaseUrl();
74 $this->assertEquals($expectedUrl, $this->storeSwitcher->switch($fromStore, $toStore, $redirectUrl));
83 public function testSwitchToExistingPage(): void
85 $fromStoreCode =
'default';
90 $toStoreCode =
'fixture_second_store';
95 $redirectUrl = $expectedUrl =
"http://localhost/page-c";
97 $this->assertEquals($expectedUrl, $this->storeSwitcher->switch($fromStore, $toStore, $redirectUrl));
106 private function setBaseUrl(StoreInterface $targetStore): void
108 $configValue = $this->objectManager->create(Value::class);
109 $configValue->load(
'web/unsecure/base_url',
'path');
110 $baseUrl =
'http://domain.com/';
111 if (!$configValue->getPath()) {
112 $configValue->setPath(
'web/unsecure/base_url');
114 $configValue->setValue($baseUrl);
116 $configValue->setScopeId($targetStore->getId());
117 $configValue->save();
119 $reinitibleConfig = $this->objectManager->create(ReinitableConfigInterface::class);
120 $reinitibleConfig->reinit();
static getObjectManager()