47 private $objectManager;
50 private $compositeValidatorMock;
54 $this->contextMock = $this->createMock(\
Magento\Framework\Model\Context::class);
55 $this->registryMock = $this->createMock(\
Magento\Framework\Registry::class);
56 $this->directoryDataMock = $this->createMock(\
Magento\Directory\Helper\Data::class);
57 $this->eavConfigMock = $this->createMock(\
Magento\Eav\Model\Config::class);
59 $this->regionFactoryMock = $this->createPartialMock(\
Magento\Directory\Model\RegionFactory::class, [
'create']);
60 $this->countryFactoryMock = $this->createPartialMock(
61 \
Magento\Directory\Model\CountryFactory::class,
64 $regionCollectionMock = $this->createMock(\
Magento\Directory\Model\
ResourceModel\Region\Collection::class);
65 $regionCollectionMock->expects($this->any())
67 ->will($this->returnValue(0));
68 $countryMock = $this->createMock(\
Magento\Directory\Model\Country::class);
69 $countryMock->expects($this->any())
70 ->method(
'getRegionCollection')
71 ->will($this->returnValue($regionCollectionMock));
72 $this->countryFactoryMock->expects($this->any())
74 ->will($this->returnValue($countryMock));
77 $this->resourceCollectionMock = $this->getMockBuilder(\
Magento\Framework\Data\
Collection\AbstractDb::class)
78 ->disableOriginalConstructor()
79 ->getMockForAbstractClass();
80 $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
81 $this->compositeValidatorMock = $this->createMock(CompositeValidator::class);
82 $this->model = $this->objectManager->getObject(
85 'context' => $this->contextMock,
86 'registry' => $this->registryMock,
87 'directoryData' => $this->directoryDataMock,
88 'eavConfig' => $this->eavConfigMock,
89 'addressConfig' => $this->addressConfigMock,
90 'regionFactory' => $this->regionFactoryMock,
91 'countryFactory' => $this->countryFactoryMock,
92 'resource' => $this->resourceMock,
93 'resourceCollection' => $this->resourceCollectionMock,
94 'compositeValidator' => $this->compositeValidatorMock,
104 $this->model->setData(
'region_id', 1);
105 $this->model->setData(
'region',
'');
106 $this->model->setData(
'country_id', $countryId);
107 $this->assertEquals(
'RegionName', $this->model->getRegion());
115 $this->model->setData(
'region_id',
'');
116 $this->model->setData(
'region', 2);
117 $this->model->setData(
'country_id', $countryId);
118 $this->assertEquals(
'RegionName', $this->model->getRegion());
123 $this->regionFactoryMock->expects($this->never())->method(
'create');
125 $this->model->setData(
'region_id',
'');
126 $this->model->setData(
'region',
'RegionName');
127 $this->assertEquals(
'RegionName', $this->model->getRegion());
132 $this->regionFactoryMock->expects($this->never())->method(
'create');
134 $this->assertNull($this->model->getRegion());
142 $this->model->setData(
'region_id', 3);
143 $this->model->setData(
'region',
'');
144 $this->model->setData(
'country_id', $countryId);
145 $this->assertEquals(
'UK', $this->model->getRegionCode());
153 $this->model->setData(
'region_id',
'');
154 $this->model->setData(
'region', 4);
155 $this->model->setData(
'country_id', $countryId);
156 $this->assertEquals(
'UK', $this->model->getRegionCode());
161 $this->regionFactoryMock->expects($this->never())->method(
'create');
163 $this->model->setData(
'region_id',
'');
164 $this->model->setData(
'region',
'UK');
165 $this->assertEquals(
'UK', $this->model->getRegionCode());
170 $this->regionFactoryMock->expects($this->never())->method(
'create');
172 $this->assertNull($this->model->getRegionCode());
180 $region = $this->createPartialMock(
181 \
Magento\Directory\Model\Region::class,
182 [
'getCountryId',
'getName',
'__wakeup',
'load']
184 $region->expects($this->once())
186 ->will($this->returnValue($regionName));
187 $region->expects($this->once())
188 ->method(
'getCountryId')
189 ->will($this->returnValue($countryId));
190 $this->regionFactoryMock->expects($this->once())
192 ->will($this->returnValue($region));
200 $region = $this->createPartialMock(
201 \
Magento\Directory\Model\Region::class,
202 [
'getCountryId',
'getCode',
'__wakeup',
'load']
204 $region->expects($this->once())
206 ->will($this->returnValue($regionCode));
207 $region->expects($this->once())
208 ->method(
'getCountryId')
209 ->will($this->returnValue($countryId));
210 $this->regionFactoryMock->expects($this->once())
212 ->will($this->returnValue($region));
226 $this->model->setData($key);
227 $this->assertEquals($key, $this->model->getData());
239 'street' =>
'value1',
249 $this->model->setData($key);
250 $this->assertEquals($expected, $this->model->getData());
264 $this->model->setData(
'street',
$value);
265 $this->assertEquals(
$value, $this->model->getData());
276 'key' => new \Magento\Framework\DataObject(),
280 'key' => new \Magento\Framework\DataObject()
283 $this->model->setData(
'key',
$value);
284 $this->assertEquals($expected, $this->model->getData());
296 $this->compositeValidatorMock->method(
'validate')->with($this->model)->willReturn($expected);
299 $this->model->setData($key,
$value);
302 $actual = $this->model->validate();
303 $this->assertEquals($expected, $actual);
313 'firstname' =>
'First Name',
314 'lastname' =>
'Last Name',
315 'street' =>
"Street 1\nStreet 2",
317 'telephone' =>
'555-55-55',
318 'country_id' => $countryId,
321 'company' =>
'Magento',
326 array_merge(array_diff_key(
$data, [
'firstname' =>
'']), [
'country_id' => $countryId++]),
327 [
'"firstname" is required. Enter and try again.'],
330 array_merge(array_diff_key(
$data, [
'lastname' =>
'']), [
'country_id' => $countryId++]),
331 [
'"lastname" is required. Enter and try again.'],
334 array_merge(array_diff_key(
$data, [
'street' =>
'']), [
'country_id' => $countryId++]),
335 [
'"street" is required. Enter and try again.'],
338 array_merge(array_diff_key(
$data, [
'city' =>
'']), [
'country_id' => $countryId++]),
339 [
'"city" is required. Enter and try again.'],
342 array_merge(array_diff_key(
$data, [
'telephone' =>
'']), [
'country_id' => $countryId++]),
343 [
'"telephone" is required. Enter and try again.'],
346 array_merge(array_diff_key(
$data, [
'postcode' =>
'']), [
'country_id' => $countryId++]),
347 [
'"postcode" is required. Enter and try again.'],
350 array_merge(
$data, [
'country_id' => $countryId++,
'region_id' => 2]),
351 [
'Invalid value of "2" provided for the regionId field.'],
354 array_diff_key(
$data, [
'country_id' =>
'']),
355 [
'"countryId" is required. Enter and try again.'],
357 'validated' => [array_merge(
$data, [
'country_id' => $countryId++]),
true],
366 $this->model->setData(
'street', $street);
367 $this->assertEquals($expectedResult, $this->model->getStreetFull());
375 $this->model->setData(
'street', $street);
376 $this->assertEquals($expectedResult, $this->model->getData(
'street'));
387 [
"first line\nsecond line", [
'first line',
'second line']],
388 [
'single line', [
'single line']],
389 [
'single line',
'single line'],
395 $this->objectManager->setBackwardCompatibleProperty(
testGetRegionCodeWithRegion()
testGetRegionCodeWithRegionId()
testGetRegionWithoutRegion()
testValidate(array $data, $expected)
testSetDataStreetAlwaysConvertedToString($expectedResult, $street)
prepareGetRegionCode($countryId, $regionCode='UK')
testGetStreetFullAlwaysReturnsString($expectedResult, $street)
testGetRegionCodeWithoutRegion()
testGetRegionWithRegion()
testGetRegionWithRegionName()
testGetRegionWithRegionId()
prepareGetRegion($countryId, $regionName='RegionName')
testGetRegionCodeWithRegionName()
getStreetFullDataProvider()
testSetDataWithMultidimensionalArray()