public function testGetId() { $storeId = 2; $websiteId = 55; $this->storeSwitcher->expects($this->once())->method('isInitialized')->willReturn(true); $store = $this->getMock('Magento\\Store\\Api\\Data\\StoreInterface'); $store->expects($this->once())->method('getWebsiteId')->willReturn($websiteId); $this->storeSwitcher->expects($this->once())->method('getStoreId')->willReturn($storeId); $this->storeRepository->expects($this->once())->method('getById')->with($storeId)->willReturn($store); $this->assertSame($websiteId, $this->geoWebsite->getId()); $this->assertSame($websiteId, $this->geoWebsite->getId()); }
/** * @return bool|int */ public function getId() { if (null === $this->defaultWebsiteId && $this->storeSwitcher->isInitialized()) { try { $storeId = $this->storeSwitcher->getStoreId(); if ($storeId) { $store = $this->storeRepository->getById($storeId); $this->defaultWebsiteId = $store->getWebsiteId(); } else { $this->defaultWebsiteId = false; } } catch (\Exception $e) { $this->defaultWebsiteId = false; } } return $this->defaultWebsiteId ?: false; }
/** * Adds a theme key to identifier for a built-in cache if user-agent theme rule is actual * * @param \Magento\Framework\App\PageCache\Identifier $identifier * @param string $result * @return string * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function afterGetValue(\Magento\Framework\App\PageCache\Identifier $identifier, $result) { if ($this->generalConfig->isAvailable() && $this->storeSwitcher->getStoreId()) { $result .= $this->storeSwitcher->getStoreId(); } return $result; }
public function testAfterGetDefaultStoreNotInWebsite() { $storeId = 1; $websiteStoreIds = [1, 3]; $geoStoreId = 2; $this->generalConfig->expects($this->once())->method('isAvailable')->willReturn(true); $this->storeSwitcher->expects($this->once())->method('isInitialized')->willReturn(true); $this->storeSwitcher->expects($this->once())->method('getStoreId')->willReturn($geoStoreId); $website = $this->getMockBuilder('Magento\\Store\\Model\\Website')->disableOriginalConstructor()->getMock(); $website->expects($this->once())->method('getStoreIds')->willReturn($websiteStoreIds); $store = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $store->expects($this->once())->method('getId')->willReturn($storeId); $this->assertSame($store, $this->geoWebsite->afterGetDefaultStore($website, $store)); }
/** * @return bool */ protected function isNeededProcess() { return $this->storeSwitcher->isInitialized() && $this->generalConfig->isAvailable() && $this->geoWebsite->getId() !== false; }
protected function setGeneralConfigIsInitialized($isInitialized) { $this->storeSwitcher->expects($this->once())->method('isInitialized')->willReturn($isInitialized); return $this->storeSwitcher; }
/** * Change scope */ protected function switchScope() { $storeId = $this->storeSwitcher->getStoreId(); if ($storeId) { $this->runMode = ScopeInterface::SCOPE_STORE; $this->scopeCode = $this->storeRepository->getById($storeId)->getCode(); } }
/** * @param int|bool $storeId * @param string $identifierValue * @param string $geoIdentifierValue * @dataProvider afterGetValueDataProvider */ public function testAfterGetValue($storeId, $identifierValue, $geoIdentifierValue) { $this->generalConfig->expects($this->once())->method('isAvailable')->willReturn(true); $this->storeSwitcher->expects($this->atLeastOnce())->method('getStoreId')->willReturn($storeId); /** @var \Magento\Framework\App\PageCache\Identifier $identifier */ $identifier = $this->getMockBuilder('Magento\\Framework\\App\\PageCache\\Identifier')->disableOriginalConstructor()->getMock(); $this->assertEquals($geoIdentifierValue, $this->geoIdentifier->afterGetValue($identifier, $identifierValue)); }
/** * @param \Magento\Store\Model\Group $subject * @param \Magento\Store\Model\Store $store * @return \Magento\Store\Model\Store */ public function afterGetDefaultStore(Group $subject, Store $store) { if ($this->generalConfig->isAvailable() && $this->storeSwitcher->isInitialized()) { $storeId = $this->storeSwitcher->getStoreId(); if ($store->getId() != $storeId && in_array($storeId, $subject->getStoreIds())) { $store = $this->storeRepository->getById($storeId); } } return $store; }
public function testGetStoreIdWithPermanentRuleException() { $countryCode = 'UA'; $storeId = 2; $ex = new \Exception('Permanent Rule Exception'); $this->country->expects($this->once())->method('getCountryCode')->willReturn($countryCode); $this->rule->expects($this->once())->method('getStoreId')->with($countryCode)->willReturn($storeId); $this->permanentRule->expects($this->once())->method('updateStoreId')->with($storeId, $countryCode)->willThrowException($ex); $this->logger->expects($this->once())->method('critical')->with($ex); $this->assertFalse($this->switcher->isInitialized()); $this->assertEquals($storeId, $this->switcher->getStoreId()); $this->assertTrue($this->switcher->isInitialized()); }