Beispiel #1
0
 /**
  * @covers \Magento\Sales\Ui\Component\DataProvider\Document::getCustomAttribute
  */
 public function testGetCustomerGroupAttribute()
 {
     $this->document->setData('customer_group_id', 1);
     $group = $this->getMockForAbstractClass(GroupInterface::class);
     $this->groupRepository->expects(static::once())->method('getById')->willReturn($group);
     $group->expects(static::once())->method('getCode')->willReturn('General');
     $attribute = $this->document->getCustomAttribute('customer_group_id');
     static::assertEquals('General', $attribute->getValue());
 }
 protected function processInit($groupId)
 {
     $searchResult = $this->getMock('Magento\\Customer\\Api\\Data\\GroupSearchResultsInterface', [], [], '', false);
     $this->groupRepositoryInterface->expects($this->once())->method('getList')->willReturn($searchResult);
     $group = $this->getMock('Magento\\Customer\\Model\\Data\\Group', [], [], '', false);
     $group->expects($this->once())->method('getId')->willReturn($groupId);
     $searchResult->expects($this->once())->method('getItems')->willReturn([$group]);
     return $this->tierPrice->init(null);
 }
 public function testPrepareDataSource()
 {
     $itemName = 'itemName';
     $oldItemValue = 'oldItemValue';
     $newItemValue = 'newItemValue';
     $dataSource = ['data' => ['items' => [[$itemName => $oldItemValue]]]];
     $group = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\GroupInterface');
     $group->expects($this->once())->method('getCode')->willReturn($newItemValue);
     $this->groupRepository->expects($this->once())->method('getById')->with($oldItemValue)->willReturn($group);
     $this->model->setData('name', $itemName);
     $dataSource = $this->model->prepareDataSource($dataSource);
     $this->assertEquals($newItemValue, $dataSource['data']['items'][0][$itemName]);
 }
Beispiel #4
0
 public function testToOptionArray()
 {
     $customerGroups = [['label' => __('ALL GROUPS'), 'value' => 32000], ['label' => __('NOT LOGGED IN'), 'value' => 0]];
     $this->moduleManagerMock->expects($this->any())->method('isEnabled')->willReturn(true);
     $this->searchCriteriaBuilderMock->expects($this->any())->method('create')->willReturn($this->searchCriteriaMock);
     $this->groupRepositoryMock->expects($this->any())->method('getList')->with($this->searchCriteriaMock)->willReturn($this->searchResultMock);
     $this->groupRepositoryMock->expects($this->any())->method('getList')->with($this->searchCriteriaMock)->willReturn($this->searchResultMock);
     $groupTest = $this->getMockBuilder('\\Magento\\Customer\\Api\\Data\\GroupInterface')->disableOriginalConstructor()->setMethods(['getCode', 'getId'])->getMockForAbstractClass();
     $groupTest->expects($this->any())->method('getCode')->willReturn(__('NOT LOGGED IN'));
     $groupTest->expects($this->any())->method('getId')->willReturn(0);
     $groups = [$groupTest];
     $this->searchResultMock->expects($this->any())->method('getItems')->willReturn($groups);
     $this->assertEquals($customerGroups, $this->model->toOptionArray());
 }
Beispiel #5
0
 public function testSetAccountData()
 {
     $taxClassId = 1;
     $attributes = [['email', '*****@*****.**'], ['group_id', 1]];
     $attributeMocks = [];
     foreach ($attributes as $attribute) {
         $attributeMock = $this->getMock('Magento\\Customer\\Api\\Data\\AttributeMetadataInterface', [], [], '', false);
         $attributeMock->expects($this->any())->method('getAttributeCode')->will($this->returnValue($attribute[0]));
         $attributeMocks[] = $attributeMock;
     }
     $customerGroupMock = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\GroupInterface', [], '', false, true, true, ['getTaxClassId']);
     $customerGroupMock->expects($this->once())->method('getTaxClassId')->will($this->returnValue($taxClassId));
     $customerFormMock = $this->getMock('Magento\\Customer\\Model\\Metadata\\Form', [], [], '', false);
     $customerFormMock->expects($this->any())->method('getAttributes')->will($this->returnValue($attributeMocks));
     $customerFormMock->expects($this->any())->method('extractData')->will($this->returnValue([]));
     $customerFormMock->expects($this->any())->method('restoreData')->will($this->returnValue([]));
     $customerFormMock->expects($this->any())->method('prepareRequest')->will($this->returnValue($this->getMock('Magento\\Framework\\App\\RequestInterface')));
     $customerMock = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false);
     $this->customerMapper->expects($this->atLeastOnce())->method('toFlatArray')->willReturn(['email' => '*****@*****.**', 'group_id' => 1, 'gender' => 1]);
     $quoteMock = $this->getMock('Magento\\Quote\\Model\\Quote', [], [], '', false);
     $quoteMock->expects($this->any())->method('getCustomer')->will($this->returnValue($customerMock));
     $quoteMock->expects($this->once())->method('addData')->with(['customer_email' => $attributes[0][1], 'customer_group_id' => $attributes[1][1], 'customer_tax_class_id' => $taxClassId]);
     $this->dataObjectHelper->expects($this->once())->method('populateWithArray')->with($customerMock, ['email' => '*****@*****.**', 'group_id' => 1, 'gender' => 1], '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     $this->formFactoryMock->expects($this->any())->method('create')->will($this->returnValue($customerFormMock));
     $this->sessionQuoteMock->expects($this->any())->method('getQuote')->will($this->returnValue($quoteMock));
     $this->customerFactoryMock->expects($this->any())->method('create')->will($this->returnValue($customerMock));
     $this->groupRepositoryMock->expects($this->once())->method('getById')->will($this->returnValue($customerGroupMock));
     $this->adminOrderCreate->setAccountData([]);
 }
Beispiel #6
0
 public function testInitAddToCustomerGroups()
 {
     $searchCriteria = $this->getMock('Magento\\Framework\\Api\\SearchCriteria', [], [], '', false);
     $this->searchCriteriaBuilder->expects($this->once())->method('create')->willReturn($searchCriteria);
     $groupSearchResult = $this->getMockForAbstractClass('\\Magento\\Customer\\Api\\Data\\GroupSearchResultsInterface', [], '', false);
     $this->groupRepository->expects($this->once())->method('getList')->with($searchCriteria)->willReturn($groupSearchResult);
     $groupTest = $this->getMockBuilder('\\Magento\\Customer\\Api\\Data\\GroupInterface')->disableOriginalConstructor()->setMethods(['getCode', 'getId'])->getMockForAbstractClass();
     $expectedCode = 'code';
     $expectedId = 'id';
     $expectedCustomerGroups = [$expectedCode => $expectedId];
     $groupTest->expects($this->once())->method('getCode')->willReturn($expectedCode);
     $groupTest->expects($this->once())->method('getId')->willReturn($expectedId);
     $groups = [$groupTest];
     $groupSearchResult->expects($this->once())->method('getItems')->willReturn($groups);
     $this->groupPrice->init();
     $this->assertEquals($expectedCustomerGroups, $this->getPropertyValue($this->groupPrice, 'customerGroups'));
 }
Beispiel #7
0
 public function testExecuteWithTaxClassAndException()
 {
     $taxClass = '3';
     $groupId = 0;
     $code = 'NOT LOGGED IN';
     $this->request->expects($this->exactly(3))->method('getParam')->withConsecutive(['tax_class'], ['id'], ['code'])->willReturnOnConsecutiveCalls($taxClass, $groupId, null);
     $this->resultRedirectFactory->expects($this->once())->method('create')->willReturn($this->resultRedirect);
     $this->groupRepositoryMock->expects($this->once())->method('getById')->with($groupId)->willReturn($this->group);
     $this->group->expects($this->once())->method('getCode')->willReturn($code);
     $this->group->expects($this->once())->method('setCode')->with($code);
     $this->group->expects($this->once())->method('setTaxClassId')->with($taxClass);
     $this->groupRepositoryMock->expects($this->once())->method('save')->with($this->group);
     $this->messageManager->expects($this->once())->method('addSuccess')->with(__('You saved the customer group.'));
     $exception = new \Exception('Exception');
     $this->resultRedirect->expects($this->at(0))->method('setPath')->with('customer/group')->willThrowException($exception);
     $this->messageManager->expects($this->once())->method('addError')->with('Exception');
     $this->dataObjectProcessorMock->expects($this->once())->method('buildOutputDataArray')->with($this->group, '\\Magento\\Customer\\Api\\Data\\GroupInterface')->willReturn(['code' => $code]);
     $this->session->expects($this->once())->method('setCustomerGroupData')->with(['customer_group_code' => $code]);
     $this->resultRedirect->expects($this->at(1))->method('setPath')->with('customer/group/edit', ['id' => $groupId]);
     $this->assertSame($this->resultRedirect, $this->controller->execute());
 }
Beispiel #8
0
 /**
  * @covers \Magento\Customer\Ui\Component\DataProvider\Document::getCustomAttribute
  */
 public function testGetWebsiteAttribute()
 {
     $websiteId = 1;
     $this->document->setData('website_id', $websiteId);
     $this->groupRepository->expects(static::never())->method('getById');
     $this->customerMetadata->expects(static::never())->method('getAttributeMetadata');
     $website = $this->getMockForAbstractClass(WebsiteInterface::class);
     $this->storeManager->expects(static::once())->method('getWebsites')->willReturn([$websiteId => $website]);
     $website->expects(static::once())->method('getName')->willReturn('Main Website');
     $attribute = $this->document->getCustomAttribute('website_id');
     static::assertEquals('Main Website', $attribute->getValue());
 }
 /**
  * @dataProvider isValidAddMessagesCallDataProvider
  *
  * @param array $value
  * @param bool  $hasEmptyColumns
  * @param array $customerGroups
  * @param array $expectedMessages
  */
 public function testIsValidAddMessagesCall($value, $hasEmptyColumns, $customerGroups, $expectedMessages)
 {
     $priceContextMock = $this->getMock('\\Magento\\CatalogImportExport\\Model\\Import\\Product', [], ['\\Magento\\Framework\\Json\\Helper\\Data', '\\Magento\\ImportExport\\Helper\\Data', '\\Magento\\ImportExport\\Model\\ResourceModel\\Import\\Data', '\\Magento\\Eav\\Model\\Config', '\\Magento\\Framework\\App\\ResourceConnection', '\\Magento\\ImportExport\\Model\\ResourceModel\\Helper', '\\Magento\\Framework\\Stdlib\\StringUtils', 'ProcessingErrorAggregatorInterface'], '', false);
     $this->tierPrice->expects($this->once())->method('isValidValueAndLength')->willReturn(true);
     $this->tierPrice->expects($this->any())->method('hasEmptyColumns')->willReturn($hasEmptyColumns);
     $this->setPropertyValue($this->tierPrice, 'customerGroups', $customerGroups);
     $searchCriteria = $this->getMock('Magento\\Framework\\Api\\SearchCriteria', [], [], '', false);
     $this->searchCriteriaBuilder->expects($this->any())->method('create')->willReturn($searchCriteria);
     $groupSearchResult = $this->getMockForAbstractClass('\\Magento\\Customer\\Api\\Data\\GroupSearchResultsInterface', [], '', false);
     $this->groupRepository->expects($this->any())->method('getList')->with($searchCriteria)->willReturn($groupSearchResult);
     $groupTest = $this->getMockBuilder('\\Magento\\Customer\\Api\\Data\\GroupInterface')->disableOriginalConstructor()->setMethods(['getCode', 'getId'])->getMockForAbstractClass();
     $groupTest->expects($this->once())->method('getCode');
     $groupTest->expects($this->any())->method('getId');
     $groups = [$groupTest];
     $groupSearchResult->expects($this->any())->method('getItems')->willReturn($groups);
     $this->tierPrice->init($priceContextMock);
     $this->tierPrice->isValid($value);
 }