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); }
/** * @dataProvider getStoreValuesForFormDataProvider * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function testGetStoreValuesForForm($empty, $all, $storeId, $groupId, $websiteId, $storeName, $groupName, $websiteName, $storeGroupId, $groupWebsiteId, $expectedResult) { $this->websiteMock->expects($this->any())->method('getId')->willReturn($websiteId); $this->websiteMock->expects($this->any())->method('getName')->willReturn($websiteName); $this->groupMock->expects($this->any())->method('getId')->willReturn($groupId); $this->groupMock->expects($this->any())->method('getName')->willReturn($groupName); $this->groupMock->expects($this->any())->method('getWebsiteId')->willReturn($groupWebsiteId); $this->storeMock->expects($this->any())->method('getId')->willReturn($storeId); $this->storeMock->expects($this->any())->method('getName')->willReturn($storeName); $this->storeMock->expects($this->any())->method('getGroupId')->willReturn($storeGroupId); $this->model->setIsAdminScopeAllowed(true); $this->assertEquals($this->model->getStoreValuesForForm($empty, $all), $expectedResult); }
public function testSave() { $this->orderMock->expects($this->exactly(3))->method('getId')->willReturn(null); $this->orderItemMock->expects($this->once())->method('getChildrenItems')->willReturn([]); $this->orderItemMock->expects($this->once())->method('getQuoteParentItemId')->willReturn(null); $this->orderMock->expects($this->once())->method('setTotalItemCount')->with(1); $this->storeGroupMock->expects($this->once())->method('getDefaultStoreId')->willReturn(1); $this->orderMock->expects($this->once())->method('getAllItems')->willReturn([$this->orderItemMock]); $this->orderMock->expects($this->once())->method('validateBeforeSave')->willReturnSelf(); $this->orderMock->expects($this->once())->method('beforeSave')->willReturnSelf(); $this->orderMock->expects($this->once())->method('isSaveAllowed')->willReturn(true); $this->orderMock->expects($this->once())->method('getEntityType')->willReturn('order'); $this->orderMock->expects($this->exactly(2))->method('getStore')->willReturn($this->storeMock); $this->storeMock->expects($this->exactly(2))->method('getGroup')->willReturn($this->storeGroupMock); $this->storeMock->expects($this->once())->method('getWebsite')->willReturn($this->websiteMock); $this->storeGroupMock->expects($this->once())->method('getDefaultStoreId')->willReturn(1); $this->salesSequenceManagerMock->expects($this->once())->method('getSequence')->with('order', 1)->willReturn($this->salesSequenceMock); $this->salesSequenceMock->expects($this->once())->method('getNextValue')->willReturn('10000001'); $this->orderMock->expects($this->once())->method('setIncrementId')->with('10000001')->willReturnSelf(); $this->orderMock->expects($this->once())->method('getIncrementId')->willReturn(null); $this->orderMock->expects($this->once())->method('getData')->willReturn(['increment_id' => '10000001']); $this->objectRelationProcessorMock->expects($this->once())->method('validateDataIntegrity')->with(null, ['increment_id' => '10000001']); $this->relationCompositeMock->expects($this->once())->method('processRelations')->with($this->orderMock); $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->adapterMock); $this->adapterMock->expects($this->any())->method('quoteInto'); $this->adapterMock->expects($this->any())->method('describeTable')->will($this->returnValue([])); $this->adapterMock->expects($this->any())->method('update'); $this->adapterMock->expects($this->any())->method('lastInsertId'); $this->orderMock->expects($this->any())->method('getId')->will($this->returnValue(1)); $this->entitySnapshotMock->expects($this->once())->method('isModified')->with($this->orderMock)->will($this->returnValue(true)); $this->resource->save($this->orderMock); }
/** * Prepare array of store groups * can be filtered to contain default store group or not by $withDefault flag * depending on flag $codeKey array keys can be group id or group code * * @param bool $withDefault * @param bool $codeKey * @return \Magento\Store\Model\Group[] */ public function getGroups($withDefault = false, $codeKey = false) { $groups = []; if ($withDefault) { $key = $codeKey ? $this->_group->getCode() : $this->_group->getId(); $groups[$key] = $this->_group; } return $groups; }
/** * Update default store (store view) for Baltic group (as EN store) and create new stores for Balrics (as RU store) * and for Russian group (as RU store). */ private function processStores() { /* load default store and update it as Baltic_EN*/ $this->storeBalticEn = $this->saveStore(self::DEF_STORE_ID_DEFAULT, true, 'EN'); /* create RU-store for Baltic group */ $this->storeBalticRu = $this->saveStore(self::DEF_STORE_ID_BALTIC_RU, true, 'RU', 'baltic_ru', self::DEF_WEBSITE_ID_MAIN, $this->groupBaltic->getId(), 10); /* create Ru-store for Russian group */ $this->storeRussianRu = $this->saveStore(self::DEF_STORE_ID_RUSSIAN_RU, true, 'RU', 'russian_ru', self::DEF_WEBSITE_ID_MAIN, $this->groupRussian->getId(), 10); }
public function testToOptionArray() { $websiteCollection = [$this->websiteMock]; $groupCollection = [$this->groupMock]; $storeCollection = [$this->storeMock]; $expectedOptions = [['label' => __('All Store Views'), 'value' => '0'], ['label' => 'Main Website', 'value' => [['label' => ' Main Website Store', 'value' => [['label' => ' Default Store View', 'value' => '1']]]]]]; $this->systemStoreMock->expects($this->once())->method('getWebsiteCollection')->willReturn($websiteCollection); $this->systemStoreMock->expects($this->once())->method('getGroupCollection')->willReturn($groupCollection); $this->systemStoreMock->expects($this->once())->method('getStoreCollection')->willReturn($storeCollection); $this->websiteMock->expects($this->atLeastOnce())->method('getId')->willReturn('1'); $this->websiteMock->expects($this->any())->method('getName')->willReturn('Main Website'); $this->groupMock->expects($this->atLeastOnce())->method('getWebsiteId')->willReturn('1'); $this->groupMock->expects($this->atLeastOnce())->method('getId')->willReturn('1'); $this->groupMock->expects($this->atLeastOnce())->method('getName')->willReturn('Main Website Store'); $this->storeMock->expects($this->atLeastOnce())->method('getGroupId')->willReturn('1'); $this->storeMock->expects($this->atLeastOnce())->method('getName')->willReturn('Default Store View'); $this->storeMock->expects($this->atLeastOnce())->method('getId')->willReturn('1'); $this->escaperMock->expects($this->atLeastOnce())->method('escapeHtml')->willReturnMap([['Default Store View', null, 'Default Store View'], ['Main Website Store', null, 'Main Website Store'], ['Main Website', null, 'Main Website']]); $this->assertEquals($expectedOptions, $this->options->toOptionArray()); }
/** * @param Group $group * @return array */ public function getStoreCollection(Group $group) { return $group->getStores(); }
/** * Set group model for store * * @param Group $group * @return Store */ public function setGroup(Group $group) { $this->setGroupId($group->getId()); return $this; }
/** * Set group model for store * * @param \Magento\Store\Model\Group $group * @return void */ public function setGroup(\Magento\Store\Model\Group $group) { $this->setGroupId($group->getId()); }
/** * @param \Magento\Store\Model\Group $group * @return bool */ public function isStoreGroupSelected(\Magento\Store\Model\Group $group) { return $this->getStoreGroupId() === $group->getId() && $this->getStoreGroupId() === null; }
/** * Loads default store and returns its id * * @return int */ public function getGroupId() { $this->loadStore(); return $this->group->getId(); }
/** * Verify if selected default store is active * * @param array $postData * @param \Magento\Store\Model\Group $groupModel * @return bool */ private function isSelectedDefaultStoreActive(array $postData, \Magento\Store\Model\Group $groupModel) { if (!empty($postData['group']['default_store_id'])) { $defaultStoreId = $postData['group']['default_store_id']; if (!empty($groupModel->getStores()[$defaultStoreId]) && !$groupModel->getStores()[$defaultStoreId]->isActive()) { return false; } } return true; }
/** * @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; }