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); }
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()); }