protected function setUp() { parent::setUp(); $this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class)->getMockForAbstractClass(); $this->groupRepositoryMock = $this->getMockBuilder(GroupRepositoryInterface::class)->getMockForAbstractClass(); $this->groupManagementMock = $this->getMockBuilder(GroupManagementInterface::class)->getMockForAbstractClass(); $this->searchCriteriaBuilderMock = $this->getMockBuilder(SearchCriteriaBuilder::class)->disableOriginalConstructor()->getMock(); $this->moduleManagerMock = $this->getMockBuilder(ModuleManager::class)->disableOriginalConstructor()->getMock(); $this->directoryHelperMock = $this->getMockBuilder(DirectoryHelper::class)->disableOriginalConstructor()->getMock(); $this->productResourceMock = $this->getMockBuilder(ProductResource::class)->disableOriginalConstructor()->getMock(); $this->attributeMock = $this->getMockBuilder(Attribute::class)->disableOriginalConstructor()->getMock(); $this->customerGroupMock = $this->getMockBuilder(CustomerGroupInterface::class)->getMockForAbstractClass(); $this->groupManagementMock->expects($this->any())->method('getAllCustomersGroup')->willReturn($this->customerGroupMock); }
protected function setUp() { $this->objectManagerHelper = new ObjectManagerHelper($this); $this->product = $this->objectManagerHelper->getObject('Magento\\Catalog\\Model\\Product'); $this->tpFactory = $this->getMockForAbstractClass('Magento\\Catalog\\Api\\Data\\ProductTierPriceInterfaceFactory', [], '', false, true, true, ['create']); $this->websiteMock = $this->getMock('Magento\\Store\\Model\\Website', ['getId'], [], '', false); $storeMangerMock = $this->getMockForAbstractClass('Magento\\Store\\Model\\StoreManagerInterface', [], '', false, true, true, ['getWebsite']); $storeMangerMock->expects($this->any())->method('getWebsite')->will($this->returnValue($this->websiteMock)); $this->scopeConfigMock = $this->getMockForAbstractClass('Magento\\Framework\\App\\Config\\ScopeConfigInterface', [], '', false, true, true, ['getValue']); $group = $this->getMock('\\Magento\\Customer\\Model\\Data\\Group', [], [], '', false); $group->expects($this->any())->method('getId')->willReturn(GroupManagement::CUST_GROUP_ALL); $this->groupManagementMock = $this->getMock('Magento\\Customer\\Api\\GroupManagementInterface', [], [], '', false); $this->groupManagementMock->expects($this->any())->method('getAllCustomersGroup')->will($this->returnValue($group)); $this->model = $this->objectManagerHelper->getObject('Magento\\Catalog\\Model\\Product\\Type\\Price', ['tierPriceFactory' => $this->tpFactory, 'config' => $this->scopeConfigMock, 'storeManager' => $storeMangerMock, 'groupManagement' => $this->groupManagementMock]); }
/** * Run test getQuote method * * @return void */ public function testGetQuote() { $storeId = 10; $quoteId = 22; $customerGroupId = 77; $customerId = 66; $quoteMock = $this->getMock('Magento\\Quote\\Model\\Quote', ['setStoreId', 'setCustomerGroupId', 'setIsActive', 'getId', 'assignCustomer', 'setIgnoreOldQty', 'setIsSuperMode', '__wakeup'], [], '', false); $defaultGroup = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\GroupInterface')->getMock(); $defaultGroup->expects($this->any())->method('getId')->will($this->returnValue($customerGroupId)); $this->groupManagementMock->expects($this->any())->method('getDefaultGroup')->will($this->returnValue($defaultGroup)); $this->quoteRepositoryMock->expects($this->once())->method('create')->will($this->returnValue($quoteMock)); $this->quote->expects($this->any())->method('getStoreId')->will($this->returnValue($storeId)); $quoteMock->expects($this->once())->method('setStoreId')->with($storeId); $this->quote->expects($this->any())->method('getQuoteId')->will($this->returnValue(null)); $quoteMock->expects($this->once())->method('setCustomerGroupId')->with($customerGroupId)->will($this->returnSelf()); $quoteMock->expects($this->once())->method('setIsActive')->with(false)->will($this->returnSelf()); $this->quoteRepositoryMock->expects($this->once())->method('save')->with($quoteMock); $quoteMock->expects($this->once())->method('getId')->will($this->returnValue($quoteId)); $this->quote->expects($this->any())->method('setQuoteId')->with($quoteId); $this->quote->expects($this->any())->method('getCustomerId')->will($this->returnValue($customerId)); $dataCustomerMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->disableOriginalConstructor()->getMock(); $this->customerRepositoryMock->expects($this->once())->method('getById')->with($customerId)->willReturn($dataCustomerMock); $quoteMock->expects($this->once())->method('assignCustomer')->with($dataCustomerMock); $quoteMock->expects($this->once())->method('setIgnoreOldQty')->with(true); $quoteMock->expects($this->once())->method('setIsSuperMode')->with(true); $this->assertEquals($quoteMock, $this->quote->getQuote()); }
/** * Run test getQuote method * * @return void */ public function testGetQuoteWithoutQuoteId() { $quoteId = 22; $storeId = 10; $customerId = 66; $customerGroupId = 77; $this->quote->expects($this->any())->method('getQuoteId')->will($this->returnValue(null)); $this->quote->expects($this->any())->method('setQuoteId')->with($quoteId); $cartInterfaceMock = $this->getMock('\\Magento\\Quote\\Api\\Data\\CartInterface', ['getId', 'setId', 'getCreatedAt', 'setCreatedAt', 'getUpdatedAt', 'setUpdatedAt', 'getConvertedAt', 'setConvertedAt', 'getIsActive', 'setIsActive', 'getIsVirtual', 'getItems', 'setItems', 'getItemsCount', 'setItemsCount', 'getItemsQty', 'setItemsQty', 'getCustomer', 'setCustomer', 'getBillingAddress', 'setBillingAddress', 'getReservedOrderId', 'setReservedOrderId', 'getOrigOrderId', 'setOrigOrderId', 'getCurrency', 'setCurrency', 'getCustomerIsGuest', 'setCustomerIsGuest', 'getCustomerNote', 'setCustomerNote', 'getCustomerNoteNotify', 'setCustomerNoteNotify', 'getCustomerTaxClassId', 'setCustomerTaxClassId', 'getStoreId', 'setStoreId', 'getExtensionAttributes', 'setExtensionAttributes', 'setIgnoreOldQty', 'setIsSuperMode', 'setCustomerGroupId']); $this->quoteFactoryMock->expects($this->once())->method('create')->willReturn($cartInterfaceMock); $this->quote->expects($this->any())->method('getStoreId')->will($this->returnValue($storeId)); $this->quote->expects($this->any())->method('getCustomerId')->will($this->returnValue($customerId)); $cartInterfaceMock->expects($this->atLeastOnce())->method('getId')->willReturn($quoteId); $defaultGroup = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\GroupInterface')->getMock(); $defaultGroup->expects($this->any())->method('getId')->will($this->returnValue($customerGroupId)); $this->groupManagementMock->expects($this->any())->method('getDefaultGroup')->will($this->returnValue($defaultGroup)); $dataCustomerMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->disableOriginalConstructor()->getMock(); $this->customerRepositoryMock->expects($this->once())->method('getById')->with($customerId)->willReturn($dataCustomerMock); $quoteMock = $this->getMock('Magento\\Quote\\Model\\Quote', ['setStoreId', 'setCustomerGroupId', 'setIsActive', 'assignCustomer', 'setIgnoreOldQty', 'setIsSuperMode', '__wakeup'], [], '', false); $this->quoteRepositoryMock->expects($this->once())->method('get')->willReturn($quoteMock); $cartInterfaceMock->expects($this->once())->method('setCustomerGroupId')->with($customerGroupId)->will($this->returnSelf()); $quoteMock->expects($this->once())->method('assignCustomer')->with($dataCustomerMock); $quoteMock->expects($this->once())->method('setIgnoreOldQty')->with(true); $quoteMock->expects($this->once())->method('setIsSuperMode')->with(true); $this->assertEquals($quoteMock, $this->quote->getQuote()); }
public function testExtract() { $customerData = ['firstname' => 'firstname', 'lastname' => 'firstname', 'email' => 'email.example.com']; $this->formFactory->expects($this->once())->method('create')->with('customer', 'form-code')->willReturn($this->customerForm); $this->customerForm->expects($this->once())->method('extractData')->with($this->request)->willReturn($customerData); $this->customerForm->expects($this->once())->method('getAllowedAttributes')->willReturn(['group_id' => 'attribute object']); $this->customerFactory->expects($this->once())->method('create')->willReturn($this->customerData); $this->dataObjectHelper->expects($this->once())->method('populateWithArray')->with($this->customerData, $customerData, '\\Magento\\Customer\\Api\\Data\\CustomerInterface')->willReturn($this->customerData); $this->storeManager->expects($this->once())->method('getStore')->willReturn($this->store); $this->store->expects($this->exactly(2))->method('getId')->willReturn(1); $this->customerGroupManagement->expects($this->once())->method('getDefaultGroup')->with(1)->willReturn($this->customerGroup); $this->customerGroup->expects($this->once())->method('getId')->willReturn(1); $this->customerData->expects($this->once())->method('setGroupId')->with(1); $this->store->expects($this->once())->method('getWebsiteId')->willReturn(1); $this->customerData->expects($this->once())->method('setWebsiteId')->with(1); $this->customerData->expects($this->once())->method('setStoreId')->with(1); $this->assertSame($this->customerData, $this->customerExtractor->extract('form-code', $this->request)); }