Example #1
0
 protected function setUp()
 {
     $this->context = $this->getMockBuilder('Magento\\Framework\\App\\Helper\\Context')->disableOriginalConstructor()->getMock();
     $this->customerMetadataService = $this->getMock('Magento\\Customer\\Api\\CustomerMetadataInterface');
     $attributeMetadata = $this->getMock('Magento\\Customer\\Api\\Data\\AttributeMetadataInterface');
     $attributeMetadata->expects($this->any())->method('isVisible')->will($this->returnValue(true));
     $this->customerMetadataService->expects($this->any())->method('getAttributeMetadata')->will($this->returnValue($attributeMetadata));
     $this->object = new \Magento\Customer\Helper\View($this->context, $this->customerMetadataService);
 }
Example #2
0
 /**
  * @param \Magento\Customer\Api\Data\CustomerInterface $customerData
  * @param string $expectedCustomerName
  * @param bool $isPrefixAllowed
  * @param bool $isMiddleNameAllowed
  * @param bool $isSuffixAllowed
  * @dataProvider getCustomerNameDataProvider
  */
 public function testGetCustomerName($customerData, $expectedCustomerName, $isPrefixAllowed = false, $isMiddleNameAllowed = false, $isSuffixAllowed = false)
 {
     $visibleAttribute = $this->getMock('Magento\\Customer\\Api\\Data\\AttributeMetadataInterface');
     $visibleAttribute->expects($this->any())->method('isVisible')->will($this->returnValue(true));
     $invisibleAttribute = $this->getMock('Magento\\Customer\\Api\\Data\\AttributeMetadataInterface');
     $invisibleAttribute->expects($this->any())->method('isVisible')->will($this->returnValue(false));
     $this->_customerMetadataService->expects($this->any())->method('getAttributeMetadata')->will($this->returnValueMap([['prefix', $isPrefixAllowed ? $visibleAttribute : $invisibleAttribute], ['middlename', $isMiddleNameAllowed ? $visibleAttribute : $invisibleAttribute], ['suffix', $isSuffixAllowed ? $visibleAttribute : $invisibleAttribute]]));
     $this->assertEquals($expectedCustomerName, $this->_helper->getCustomerName($customerData), 'Full customer name is invalid');
 }
Example #3
0
 /**
  * @param $attrCode
  * @param $attrClass
  * @param $customAttrClass
  * @param $result
  * @dataProvider getAttributeValidationClassDataProvider
  */
 public function testGetAttributeValidationClass($attrCode, $attrClass, $customAttrClass, $result)
 {
     $attributeMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AttributeMetadataInterface')->getMock();
     $attributeMock->expects($this->any())->method('getFrontendClass')->will($this->returnValue($attrClass));
     $customAttrMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AttributeMetadataInterface')->getMock();
     $customAttrMock->expects($this->any())->method('isVisible')->will($this->returnValue(true));
     $customAttrMock->expects($this->any())->method('getFrontendClass')->will($this->returnValue($customAttrClass));
     $this->customerMetadataService->expects($this->any())->method('getAttributeMetadata')->will($this->returnValue($customAttrMock));
     $this->addressMetadataService->expects($this->any())->method('getAttributeMetadata')->will($this->returnValue($attributeMock));
     $this->assertEquals($result, $this->helper->getAttributeValidationClass($attrCode));
 }
Example #4
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());
 }
 public function testGetList()
 {
     $attributeCode = 'attribute_code';
     $billingPrefix = 'billing_';
     $this->customerMetadata->expects($this->once())->method('getAllAttributesMetadata')->willReturn([]);
     $this->addressMetadata->expects($this->once())->method('getAllAttributesMetadata')->willReturn([$this->attribute]);
     $this->addressMetadataManagement->expects($this->once())->method('canBeFilterableInGrid')->with($this->attribute)->willReturn(true);
     $this->addressMetadataManagement->expects($this->once())->method('canBeSearchableInGrid')->with($this->attribute)->willReturn(true);
     $this->attribute->expects($this->atLeastOnce())->method('getAttributeCode')->willReturn($attributeCode);
     $this->attribute->expects($this->once())->method('getFrontendInput')->willReturn('frontend-input');
     $this->attribute->expects($this->once())->method('getFrontendLabel')->willReturn('frontend-label');
     $this->attribute->expects($this->once())->method('getBackendType')->willReturn('backend-type');
     $this->attribute->expects($this->once())->method('getOptions')->willReturn([$this->option]);
     $this->attribute->expects($this->once())->method('getIsUsedInGrid')->willReturn(true);
     $this->attribute->expects($this->once())->method('getIsVisibleInGrid')->willReturn(true);
     $this->attribute->expects($this->once())->method('getValidationRules')->willReturn([]);
     $this->attribute->expects($this->once())->method('isRequired')->willReturn(false);
     $this->option->expects($this->once())->method('getLabel')->willReturn('Label');
     $this->option->expects($this->once())->method('getValue')->willReturn('Value');
     $this->attributeFilter->expects($this->once())->method('filter')->willReturnArgument(0);
     $this->assertEquals([$billingPrefix . $attributeCode => ['attribute_code' => 'billing_attribute_code', 'frontend_input' => 'frontend-input', 'frontend_label' => 'frontend-label', 'backend_type' => 'backend-type', 'options' => [['label' => 'Label', 'value' => 'Value']], 'is_used_in_grid' => true, 'is_visible_in_grid' => true, 'is_filterable_in_grid' => true, 'is_searchable_in_grid' => true, 'validation_rules' => [], 'required' => false, 'entity_type_code' => 'customer_address']], $this->component->getList());
 }
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testGetList()
 {
     $sortOrder = $this->getMock('Magento\\Framework\\Api\\SortOrder', [], [], '', false);
     $filterGroup = $this->getMock('Magento\\Framework\\Api\\Search\\FilterGroup', [], [], '', false);
     $filter = $this->getMock('Magento\\Framework\\Api\\Filter', [], [], '', false);
     $collection = $this->getMock('Magento\\Customer\\Model\\ResourceModel\\Customer\\Collection', [], [], '', false);
     $searchResults = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\AddressSearchResultsInterface', [], '', false);
     $searchCriteria = $this->getMockForAbstractClass('Magento\\Framework\\Api\\SearchCriteriaInterface', [], '', false);
     $customerModel = $this->getMock('Magento\\Customer\\Model\\Customer', ['getId', 'setId', 'setStoreId', 'getStoreId', 'getAttributeSetId', 'setAttributeSetId', 'setRpToken', 'setRpTokenCreatedAt', 'getDataModel', 'setPasswordHash', 'getCollection'], [], 'customerModel', false);
     $metadata = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\AttributeMetadataInterface', [], '', false);
     $this->searchResultsFactory->expects($this->once())->method('create')->willReturn($searchResults);
     $searchResults->expects($this->once())->method('setSearchCriteria')->with($searchCriteria);
     $this->customerFactory->expects($this->once())->method('create')->willReturn($customerModel);
     $customerModel->expects($this->once())->method('getCollection')->willReturn($collection);
     $this->extensionAttributesJoinProcessor->expects($this->once())->method('process')->with($collection, 'Magento\\Customer\\Api\\Data\\CustomerInterface');
     $this->customerMetadata->expects($this->once())->method('getAllAttributesMetadata')->willReturn([$metadata]);
     $metadata->expects($this->once())->method('getAttributeCode')->willReturn('attribute-code');
     $collection->expects($this->once())->method('addAttributeToSelect')->with('attribute-code');
     $collection->expects($this->once())->method('addNameToSelect');
     $collection->expects($this->at(2))->method('joinAttribute')->with('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')->willReturnSelf();
     $collection->expects($this->at(3))->method('joinAttribute')->with('billing_city', 'customer_address/city', 'default_billing', null, 'left')->willReturnSelf();
     $collection->expects($this->at(4))->method('joinAttribute')->with('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')->willReturnSelf();
     $collection->expects($this->at(5))->method('joinAttribute')->with('billing_region', 'customer_address/region', 'default_billing', null, 'left')->willReturnSelf();
     $collection->expects($this->at(6))->method('joinAttribute')->with('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left')->willReturnSelf();
     $collection->expects($this->at(7))->method('joinAttribute')->with('company', 'customer_address/company', 'default_billing', null, 'left')->willReturnSelf();
     $searchCriteria->expects($this->once())->method('getFilterGroups')->willReturn([$filterGroup]);
     $collection->expects($this->once())->method('addFieldToFilter')->with([['attribute' => 'Field', 'eq' => 'Value']], []);
     $filterGroup->expects($this->once())->method('getFilters')->willReturn([$filter]);
     $filter->expects($this->once())->method('getConditionType')->willReturn(false);
     $filter->expects($this->once())->method('getField')->willReturn('Field');
     $filter->expects($this->atLeastOnce())->method('getValue')->willReturn('Value');
     $collection->expects($this->once())->method('addOrder')->with('Field', 'ASC');
     $searchCriteria->expects($this->atLeastOnce())->method('getSortOrders')->willReturn([$sortOrder]);
     $sortOrder->expects($this->once())->method('getField')->willReturn('Field');
     $sortOrder->expects($this->once())->method('getDirection')->willReturn(\Magento\Framework\Api\SortOrder::SORT_ASC);
     $searchCriteria->expects($this->once())->method('getCurrentPage')->willReturn(1);
     $collection->expects($this->once())->method('setCurPage')->with(1);
     $searchCriteria->expects($this->once())->method('getPageSize')->willReturn(10);
     $collection->expects($this->once())->method('setPageSize')->with(10);
     $collection->expects($this->once())->method('getSize')->willReturn(23);
     $searchResults->expects($this->once())->method('setTotalCount')->with(23);
     $collection->expects($this->once())->method('getIterator')->willReturn(new \ArrayIterator([$customerModel]));
     $customerModel->expects($this->atLeastOnce())->method('getDataModel')->willReturn($this->customer);
     $searchResults->expects($this->once())->method('setItems')->with([$this->customer]);
     $this->assertSame($searchResults, $this->model->getList($searchCriteria));
 }
Example #7
0
 public function testGetMaxDateRangeWithException()
 {
     $this->customerMetadata->expects($this->any())->method('getAttributeMetadata')->will($this->throwException(new NoSuchEntityException(__(NoSuchEntityException::MESSAGE_SINGLE_FIELD, ['fieldName' => 'field', 'fieldValue' => 'value']))));
     $this->assertNull($this->_block->getMaxDateRange());
 }
Example #8
0
 public function testIsRequiredWithException()
 {
     $this->customerMetadata->expects($this->any())->method('getAttributeMetadata')->will($this->throwException(new NoSuchEntityException(__(NoSuchEntityException::MESSAGE_SINGLE_FIELD, ['fieldName' => 'field', 'fieldValue' => 'value']))));
     $this->assertSame(false, $this->_block->isRequired());
 }