/** * Get storage instance * * @return \Magento\Store\Model\StoreManagerInterface */ protected function _getStorage() { if (!$this->_storage instanceof \Magento\Store\Model\StoreManagerInterface) { $arguments = ['isSingleStoreAllowed' => $this->_isSingleStoreAllowed, 'currentStore' => $this->_currentStore, 'scopeCode' => $this->_scopeCode, 'scopeType' => $this->_scopeType]; $this->_storage = $this->_factory->get($arguments); } return $this->_storage; }
/** * @covers \Magento\Store\Model\StorageFactory::_checkRequestStore * @covers \Magento\Store\Model\StorageFactory::getActiveStoreByCode * @covers \Magento\Store\Model\StorageFactory::setCurrentStore * * @dataProvider getFromRequestDataProvider * * @param bool $isActiveStore * @param bool $isDefault */ public function testGetFromRequest($isActiveStore, $isDefault) { $this->_appStateMock->expects($this->once())->method('isInstalled')->will($this->returnValue(true)); $storeDefault = $this->getMock('Magento\\Store\\Model\\Store', array(), array(), '', false); if (!$isDefault) { $storeDefault->expects($this->atLeastOnce())->method('getId')->will($this->returnValue(22)); $this->_httpContext->expects($this->once())->method('setValue')->with(\Magento\Store\Model\Store::ENTITY, 'store1', \Magento\Store\Model\Store::DEFAULT_CODE)->will($this->returnSelf()); } $this->website->expects($this->any())->method('getDefaultStore')->will($this->returnValue(!$isDefault ? $storeDefault : $this->store)); $this->website->expects($this->atLeastOnce())->method('getDefaultGroupId')->will($this->returnValue(11)); $this->group->expects($this->any())->method('getDefaultStoreId')->will($this->returnValue(21)); $this->store->expects($this->atLeastOnce())->method('getId')->will($this->returnValue(21)); $this->store->expects($this->once())->method('getIsActive')->will($this->returnValue($isActiveStore)); $this->store->expects($this->any())->method('getWebsite')->will($this->returnValue($this->website)); $this->storage->expects($this->any())->method('setCurrentStore')->with('store1'); $this->_objectManagerMock->expects($this->once())->method('create')->will($this->returnValue($this->storage)); $this->request->expects($this->atLeastOnce())->method('getParam')->with('___store')->will($this->returnValue('store1')); $this->assertEquals($this->storage, $this->_model->get($this->_arguments)); }
/** * @covers \Magento\Store\Model\StorageFactory::_checkRequestStore * @covers \Magento\Store\Model\StorageFactory::getActiveStoreByCode * @covers \Magento\Store\Model\StorageFactory::setCurrentStore * * @dataProvider getFromRequestDataProvider * * @param bool $isActiveStore * @param bool $isDefault */ public function testGetFromRequest($isActiveStore, $isDefault) { $this->_appStateMock->expects($this->once())->method('isInstalled')->will($this->returnValue(true)); $storeDefault = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false); if (!$isDefault) { $storeDefault->expects($this->atLeastOnce())->method('getId')->will($this->returnValue(22)); $this->_httpContext->expects($this->once())->method('setValue')->with(\Magento\Store\Model\Store::ENTITY, 'store1', \Magento\Store\Model\Store::DEFAULT_CODE)->will($this->returnSelf()); } $this->website->expects($this->any())->method('getDefaultStore')->will($this->returnValue(!$isDefault ? $storeDefault : $this->store)); $this->website->expects($this->atLeastOnce())->method('getDefaultGroupId')->will($this->returnValue(11)); $this->group->expects($this->any())->method('getDefaultStoreId')->will($this->returnValue(21)); $this->store->expects($this->atLeastOnce())->method('getId')->will($this->returnValue(21)); $this->store->expects($this->once())->method('getIsActive')->will($this->returnValue($isActiveStore)); $this->store->expects($this->any())->method('getWebsite')->will($this->returnValue($this->website)); $this->storage->expects($this->any())->method('setCurrentStore')->with('store1'); $numCreateCookieCalls = $isDefault ? 0 : 1; $this->_objectManagerMock->expects($this->once())->method('create')->will($this->returnValue($this->storage)); $cookieMetadata = $this->helper->getObject('Magento\\Framework\\Stdlib\\Cookie\\PublicCookieMetadata', []); $this->cookieMetadataFactoryMock->expects($this->exactly($numCreateCookieCalls))->method('createPublicCookieMetadata')->will($this->returnValue($cookieMetadata)); $this->request->expects($this->atLeastOnce())->method('getParam')->with('___store')->will($this->returnValue('store1')); $this->assertEquals($this->storage, $this->_model->get($this->_arguments)); }
/** * Get storage instance * * @return \Magento\Store\Model\StoreManagerInterface */ protected function _getStorage() { $arguments = array('isSingleStoreAllowed' => $this->_isSingleStoreAllowed, 'currentStore' => $this->_currentStore, 'scopeCode' => $this->_scopeCode, 'scopeType' => $this->_scopeType); return $this->_factory->get($arguments); }