16 $countryFactoryMock = $this->createMock(
17 \
Magento\Directory\Model\CountryFactory::class
19 $directoryHelperMock = $this->createPartialMock(
20 \
Magento\Directory\Helper\Data::class,
23 $escaperMock = $this->createMock(\
Magento\Framework\Escaper::class);
24 $elementMock = $this->createPartialMock(
25 \
Magento\Framework\Data\
Form\Element\AbstractElement::class,
26 [
'getForm',
'getHtmlAttributes']
28 $countryMock = $this->createPartialMock(
29 \
Magento\Framework\Data\
Form\Element\AbstractElement::class,
32 $regionMock = $this->createMock(
33 \
Magento\Framework\Data\
Form\Element\AbstractElement::class
35 $countryModelMock = $this->createPartialMock(
36 \
Magento\Directory\Model\Country::class,
37 [
'setId',
'getLoadedRegionCollection',
'toOptionArray',
'__wakeup']
39 $formMock = $this->createPartialMock(\
Magento\Framework\Data\Form::class, [
'getElement']);
41 $elementMock->expects($this->any())->method(
'getForm')->will($this->returnValue($formMock));
42 $elementMock->expects(
66 $this->returnValueMap([[
'country_id', $countryMock], [
'region_id', $regionMock]])
68 $countryMock->expects($this->any())->method(
'getValue')->will($this->returnValue(
'GE'));
69 $directoryHelperMock->expects(
74 $this->returnValueMap([[
'GE',
true]])
76 $countryFactoryMock->expects($this->once())->method(
'create')->will($this->returnValue($countryModelMock));
77 $countryModelMock->expects($this->any())->method(
'setId')->will($this->returnSelf());
78 $countryModelMock->expects($this->any())->method(
'getLoadedRegionCollection')->will($this->returnSelf());
79 $countryModelMock->expects($this->any())->method(
'toOptionArray')->will($this->returnValue($regionCollection));
81 $model = new \Magento\Customer\Model\Renderer\Region($countryFactoryMock, $directoryHelperMock, $escaperMock);
83 $static = new \ReflectionProperty(\
Magento\
Customer\Model\Renderer\Region::class,
'_regionCollections');
84 $static->setAccessible(
true);
85 $static->setValue([]);
87 $html =
$model->render($elementMock);
89 $this->assertContains(
'required', $html);
90 $this->assertContains(
'required-entry', $html);
99 'with no defined regions' => [[]],
100 'with defined regions' => [
102 new \Magento\Framework\DataObject([
'value' =>
'Bavaria']),
103 new \Magento\Framework\DataObject([
'value' =>
'Saxony']),
testRender($regionCollection)