39 private $addressMetadataService;
41 protected function setUp()
43 $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
44 $className = \Magento\Customer\Helper\Address::class;
48 $this->blockFactory =
$arguments[
'blockFactory'];
49 $this->storeManager =
$arguments[
'storeManager'];
50 $this->scopeConfig = $this->context->getScopeConfig();
51 $this->customerMetadataService =
$arguments[
'customerMetadataService'];
52 $this->addressConfig =
$arguments[
'addressConfig'];
53 $this->addressMetadataService =
$arguments[
'addressMetadataService'];
65 $attributeMock = $this->getMockBuilder(
66 \
Magento\Customer\Api\Data\AttributeMetadataInterface::class
68 $attributeMock->expects($this->any())->method(
'getMultilineCount')->will($this->returnValue($numLines));
70 $this->addressMetadataService
71 ->expects($this->any())
72 ->method(
'getAttributeMetadata')
73 ->will($this->returnValue($attributeMock));
75 $store = $this->getMockBuilder(\
Magento\Store\Model\Store::class)->disableOriginalConstructor()->getMock();
76 $this->storeManager->expects($this->any())->method(
'getStore')->will($this->returnValue(
$store));
78 $this->assertEquals($expectedNumLines, $this->helper->getStreetLines());
106 $this->helper = new \Magento\Customer\Helper\Address(
110 $this->customerMetadataService,
111 $this->addressMetadataService,
114 $this->assertEquals(
$result, $this->helper->getRenderer($renderer));
122 $blockMock = $this->getMockBuilder(\
Magento\Framework\View\Element\BlockInterface::class)->getMock();
124 \
Magento\Framework\View\Element\BlockFactory::class
125 )->disableOriginalConstructor()->getMock();
127 ->method(
'createBlock')
128 ->with(
'some_test_block', [])
129 ->will($this->returnValue($blockMock));
138 $result = [
'key1' =>
'value1',
'key2' =>
'value2'];
139 $store = $this->getMockBuilder(\
Magento\Store\Model\Store::class)->disableOriginalConstructor()->getMock();
140 $store->expects($this->any())
141 ->method(
'getWebsiteId')
142 ->will($this->returnValue(
'1'));
143 $this->scopeConfig->expects($this->once())
145 ->with(
'customer/address', \
Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$store)
146 ->will($this->returnValue(
$result));
147 $this->storeManager->expects($this->any())->method(
'getStore')->will($this->returnValue(
$store));
148 $this->assertNull($this->helper->getConfig(
'unavailable_key'));
149 $this->assertFalse($this->helper->canShowConfig(
'unavailable_key'));
150 $this->assertEquals(
$result[
'key1'], $this->helper->getConfig(
'key1'));
151 $this->assertEquals(
$result[
'key2'], $this->helper->getConfig(
'key2'));
152 $this->assertTrue($this->helper->canShowConfig(
'key1'));
153 $this->assertTrue($this->helper->canShowConfig(
'key2'));
159 $attributeClass =
'Attribute_Class';
161 $attributeMock = $this->getMockBuilder(\
Magento\Customer\Api\Data\AttributeMetadataInterface::class)
162 ->getMockForAbstractClass();
163 $attributeMock->expects($this->once())
164 ->method(
'getFrontendClass')
165 ->willReturn($attributeClass);
167 $this->addressMetadataService->expects($this->any())
168 ->method(
'getAttributeMetadata')
169 ->willReturn($attributeMock);
171 $this->assertEquals($attributeClass, $this->helper->getAttributeValidationClass(
$attributeCode));
176 $attrCode =
'attr_code';
178 $this->addressMetadataService->expects($this->any())
179 ->method(
'getAttributeMetadata')
182 $this->assertEquals(
'', $this->helper->getAttributeValidationClass($attrCode));
193 $this->assertEquals(
$result, $this->helper->convertStreetLines($origStreets, $toCount));
202 [[
'street1',
'street2',
'street3',
'street4'], 3, [
'street1 street2',
'street3',
'street4']],
203 [[
'street1',
'street2',
'street3',
'street4'], 2, [
'street1 street2',
'street3 street4']],
214 $this->scopeConfig->expects($this->once())
217 \
Magento\Customer\Helper\Address::XML_PATH_VAT_VALIDATION_ENABLED,
218 \
Magento\Store\Model\ScopeInterface::SCOPE_STORE,
221 ->will($this->returnValue(
$result));
222 $this->assertEquals(
$result, $this->helper->isVatValidationEnabled(
$store));
244 $this->scopeConfig->expects($this->once())
247 \
Magento\Customer\Helper\Address::XML_PATH_VIV_ON_EACH_TRANSACTION,
248 \
Magento\Store\Model\ScopeInterface::SCOPE_STORE,
251 ->will($this->returnValue(
$result));
252 $this->assertEquals(
$result, $this->helper->hasValidateOnEachTransaction(
$store));
274 $this->scopeConfig->expects($this->once())
277 \
Magento\Customer\Helper\Address::XML_PATH_VIV_TAX_CALCULATION_ADDRESS_TYPE,
278 \
Magento\Store\Model\ScopeInterface::SCOPE_STORE,
281 ->will($this->returnValue(
$result));
282 $this->assertEquals(
$result, $this->helper->getTaxCalculationAddressType(
$store));
291 [0,
'address_type_store_0'],
292 [1,
'address_type_store_1'],
293 [2,
'address_type_store_2'],
299 $this->scopeConfig->expects($this->once())
302 \
Magento\Customer\Helper\Address::XML_PATH_VIV_DISABLE_AUTO_ASSIGN_DEFAULT,
303 \
Magento\Store\Model\ScopeInterface::SCOPE_STORE
305 ->will($this->returnValue(
true));
306 $this->assertTrue($this->helper->isDisableAutoGroupAssignDefaultValue());
311 $this->scopeConfig->expects($this->once())
314 \
Magento\Customer\Helper\Address::XML_PATH_VAT_FRONTEND_VISIBILITY,
315 \
Magento\Store\Model\ScopeInterface::SCOPE_STORE
317 ->will($this->returnValue(
true));
318 $this->assertTrue($this->helper->isVatAttributeVisible());
328 $this->addressConfig->expects($this->once())
329 ->method(
'getFormatByCode')
331 ->will($this->returnValue(
334 $this->assertEquals(
$result, $this->helper->getFormatTypeRenderer(
$code));
342 $renderer = $this->getMockBuilder(\
Magento\Customer\Block\Address\Renderer\RendererInterface::class)
343 ->disableOriginalConstructor()->getMock();
345 [
'valid_code', $renderer],
346 [
'invalid_code',
null]
358 $renderer = $this->getMockBuilder(\
Magento\Customer\Block\Address\Renderer\RendererInterface::class)
359 ->disableOriginalConstructor()->getMock();
360 $renderer->expects($this->once())
361 ->method(
'getFormatArray')
362 ->will($this->returnValue([
'key' =>
'value']));
364 $this->addressConfig->expects($this->once())
365 ->method(
'getFormatByCode')
367 ->will($this->returnValue(
368 new \
Magento\Framework\DataObject(!empty(
$result) ? [
'renderer' => $renderer] : [])
371 $this->assertEquals(
$result, $this->helper->getFormat(
$code));
380 [
'valid_code', [
'key' =>
'value']],
392 $attributeMetadata =
null;
393 if ($isMetadataExists) {
394 $attributeMetadata = $this->getMockBuilder(\
Magento\Customer\Api\Data\AttributeMetadataInterface::class)
395 ->getMockForAbstractClass();
396 $attributeMetadata->expects($this->once())
397 ->method(
'isVisible')
400 $this->addressMetadataService->expects($this->once())
401 ->method(
'getAttributeMetadata')
403 ->willReturn($attributeMetadata);
404 $this->assertEquals($isMetadataExists, $this->helper->isAttributeVisible(
$attributeCode));
414 [
'invalid_code',
false]
getVatValidationEnabledDataProvider()
isAttributeVisibleDataProvider()
testGetRenderer($renderer, $blockFactory, $result)
testGetFormatTypeRenderer($code, $result)
testGetConfigCanShowConfig()
testGetFormat($code, $result)
getRendererDataProvider()
getConvertStreetLinesDataProvider()
testGetAttributeValidationClass()
testIsVatValidationEnabled($store, $result)
testGetAttributeValidationClassWithNoAttribute()
getValidateOnEachTransactionDataProvider()
getTaxCalculationAddressTypeDataProvider()
testIsVatAttributeVisible()
testGetTaxCalculationAddressType($store, $result)
testIsAttributeVisible($attributeCode, $isMetadataExists)
testGetStreetLines($numLines, $expectedNumLines)
testConvertStreetLines($origStreets, $toCount, $result)
testIsDisableAutoGroupAssignDefaultValue()
getFormatTypeRendererDataProvider()
testHasValidateOnEachTransaction($store, $result)