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());
 }
 protected function setUp()
 {
     $this->objectManager = new ObjectManager($this);
     $this->assignedWebsites = [self::SECOND_WEBSITE_ID];
     $this->websiteMock = $this->getMockBuilder('Magento\\Store\\Model\\Website')->setMethods(['getId', 'getName'])->disableOriginalConstructor()->getMock();
     $this->secondWebsiteMock = $this->getMockBuilder('Magento\\Store\\Model\\Website')->setMethods(['getId', 'getName'])->disableOriginalConstructor()->getMock();
     $this->websiteRepositoryMock = $this->getMockBuilder('Magento\\Store\\Api\\WebsiteRepositoryInterface')->setMethods(['getList', 'getDefault'])->getMockForAbstractClass();
     $this->websiteRepositoryMock->expects($this->any())->method('getDefault')->willReturn($this->websiteMock);
     $this->websiteRepositoryMock->expects($this->any())->method('getList')->willReturn([$this->websiteMock, $this->secondWebsiteMock]);
     $this->groupRepositoryMock = $this->getMockBuilder('Magento\\Store\\Api\\GroupRepositoryInterface')->setMethods(['getList'])->getMockForAbstractClass();
     $this->storeRepositoryMock = $this->getMockBuilder('Magento\\Store\\Api\\StoreRepositoryInterface')->setMethods(['getList'])->getMockForAbstractClass();
     $this->locatorMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Locator\\LocatorInterface')->setMethods(['getProduct', 'getWebsiteIds'])->getMockForAbstractClass();
     $this->productMock = $this->getMockBuilder('Magento\\Catalog\\Api\\Data\\ProductInterface')->setMethods(['getId'])->getMockForAbstractClass();
     $this->locatorMock->expects($this->any())->method('getProduct')->willReturn($this->productMock);
     $this->locatorMock->expects($this->any())->method('getWebsiteIds')->willReturn($this->assignedWebsites);
     $this->storeManagerMock = $this->getMockBuilder('Magento\\Store\\Model\\StoreManagerInterface')->setMethods(['isSingleStoreMode'])->getMockForAbstractClass();
     $this->storeManagerMock->expects($this->any())->method('isSingleStoreMode')->willReturn(false);
     $this->groupMock = $this->getMockBuilder('Magento\\Store\\Model\\ResourceModel\\Group\\Collection')->setMethods(['getId', 'getName', 'getWebsiteId'])->disableOriginalConstructor()->getMock();
     $this->groupMock->expects($this->any())->method('getWebsiteId')->willReturn(self::WEBSITE_ID);
     $this->groupMock->expects($this->any())->method('getId')->willReturn(self::GROUP_ID);
     $this->groupRepositoryMock->expects($this->any())->method('getList')->willReturn([$this->groupMock]);
     $this->storeViewMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->setMethods(['getName', 'getId', 'getStoreGroupId'])->disableOriginalConstructor()->getMock();
     $this->storeViewMock->expects($this->any())->method('getName')->willReturn(self::STORE_VIEW_NAME);
     $this->storeViewMock->expects($this->any())->method('getStoreGroupId')->willReturn(self::GROUP_ID);
     $this->storeViewMock->expects($this->any())->method('getId')->willReturn(self::STORE_VIEW_ID);
     $this->storeRepositoryMock->expects($this->any())->method('getList')->willReturn([$this->storeViewMock]);
     $this->productMock->expects($this->any())->method('getId')->willReturn(self::PRODUCT_ID);
     $this->secondWebsiteMock->expects($this->any())->method('getId')->willReturn($this->assignedWebsites[0]);
     $this->websiteMock->expects($this->any())->method('getId')->willReturn(self::WEBSITE_ID);
 }
 public function testAfterGetDefaultStore()
 {
     $storeId = 1;
     $websiteStoreIds = [1, 2, 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);
     $geoStore = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $this->storeRepository->expects($this->once())->method('getById')->willReturn($geoStore);
     $this->assertSame($geoStore, $this->geoWebsite->afterGetDefaultStore($website, $store));
 }
Exemple #4
0
 public function testBeforeDispatchNoStoreCookie()
 {
     $storeCode = null;
     $this->storeCookieManagerMock->expects($this->once())->method('getStoreCodeFromCookie')->willReturn($storeCode);
     $this->storeManagerMock->expects($this->never())->method('getDefaultStoreView')->willReturn($this->storeMock);
     $this->storeRepositoryMock->expects($this->never())->method('getActiveStoreByCode');
     $this->storeCookieManagerMock->expects($this->never())->method('deleteStoreCookie')->with($this->storeMock);
     $this->plugin->beforeDispatch($this->subjectMock, $this->requestMock);
 }
 public function testAroundDispatchNoStoreCookie()
 {
     $storeCode = null;
     $this->storeManagerMock->expects($this->once())->method('getDefaultStoreView')->willReturn($this->storeMock);
     $this->storeCookieManagerMock->expects($this->once())->method('getStoreCodeFromCookie')->willReturn($storeCode);
     $this->storeRepositoryMock->expects($this->never())->method('getActiveStoreByCode');
     $this->storeCookieManagerMock->expects($this->never())->method('deleteStoreCookie')->with($this->storeMock);
     $this->assertEquals('ExpectedValue', $this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock));
 }
 public function testUpdateStoreIdNotFoundCountryStore()
 {
     $countryCode = 'UA';
     $storeId = 2;
     $websiteStoreCodes = ['us', 'uk'];
     $websiteId = 11;
     $this->generalConfig->expects($this->once())->method('isMappingSore')->willReturn(true);
     $store = $this->getMockBuilder('Magento\\Store\\Api\\Data\\StoreInterface')->disableOriginalConstructor()->getMock();
     $store->expects($this->once())->method('getWebsiteId')->willReturn($websiteId);
     $this->storeRepository->expects($this->once())->method('getById')->willReturn($store);
     $this->storeRepository->expects($this->never())->method('get');
     $website = $this->getMockBuilder('Magento\\Store\\Model\\Website')->disableOriginalConstructor()->getMock();
     $website->expects($this->once())->method('getStoreCodes')->willReturn($websiteStoreCodes);
     $this->websiteRepository->expects($this->once())->method('getById')->with($websiteId)->willReturn($website);
     $this->websiteRepository->expects($this->never())->method('getDefault');
     $this->assertEquals($storeId, $this->countryStoreMapping->updateStoreId($storeId, $countryCode));
 }
 public function testExecuteSuccessWithUseStoreInUrl()
 {
     $currentActiveStoreCode = 'sv1';
     $storeToSwitchToCode = 'sv2';
     $defaultStoreViewCode = 'default';
     $originalRedirectUrl = "magento.com/{$currentActiveStoreCode}/test-page/test-sub-page";
     $expectedRedirectUrl = "magento.com/{$storeToSwitchToCode}/test-page/test-sub-page";
     $currentActiveStoreMock = $this->getMockBuilder('Magento\\Store\\Api\\Data\\StoreInterface')->disableOriginalConstructor()->setMethods(['isUseStoreInUrl', 'getBaseUrl'])->getMockForAbstractClass();
     $defaultStoreViewMock = $this->getMockBuilder('Magento\\Store\\Api\\Data\\StoreInterface')->getMock();
     $storeToSwitchToMock = $this->getMockBuilder('Magento\\Store\\Api\\Data\\StoreInterface')->disableOriginalConstructor()->setMethods(['isUseStoreInUrl', 'getBaseUrl'])->getMockForAbstractClass();
     $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($currentActiveStoreMock);
     $this->requestMock->expects($this->once())->method('getParam')->willReturn($storeToSwitchToCode);
     $this->storeRepositoryMock->expects($this->once())->method('getActiveStoreByCode')->willReturn($storeToSwitchToMock);
     $this->storeManagerMock->expects($this->once())->method('getDefaultStoreView')->willReturn($defaultStoreViewMock);
     $defaultStoreViewMock->expects($this->once())->method('getId')->willReturn($defaultStoreViewCode);
     $storeToSwitchToMock->expects($this->once())->method('getId')->willReturn($storeToSwitchToCode);
     $storeToSwitchToMock->expects($this->once())->method('isUseStoreInUrl')->willReturn(true);
     $this->redirectMock->expects($this->any())->method('getRedirectUrl')->willReturn($originalRedirectUrl);
     $currentActiveStoreMock->expects($this->any())->method('getBaseUrl')->willReturn("magento.com/{$currentActiveStoreCode}");
     $storeToSwitchToMock->expects($this->once())->method('getBaseUrl')->willReturn("magento.com/{$storeToSwitchToCode}");
     $this->responseMock->expects($this->once())->method('setRedirect')->with($expectedRedirectUrl);
     $this->model->execute();
 }
 /**
  * @dataProvider getStoresDataProvider
  */
 public function testGetStores($storesList, $withDefault, $codeKey, $expectedStores)
 {
     $this->storeRepositoryMock->expects($this->any())->method('getList')->willReturn($storesList);
     $this->assertEquals($expectedStores, $this->model->getStores($withDefault, $codeKey));
 }