11 use Magento\Directory\Model\ResourceModel\Country\CollectionFactory as CountryCollectionFactory;
24 class DataTest extends \PHPUnit\Framework\TestCase
33 private $helperDataMock;
36 private $cacheTypeConfigMock;
39 private $countryCollectionFactoryMock;
42 private $scopeConfigMock;
45 private $storeManagerMock;
51 private $countryCollectionMock;
57 private $serializerMock;
61 $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
64 $this->helperDataMock = $this->getMockBuilder(\
Magento\Directory\Helper\Data::class)
65 ->disableOriginalConstructor()
68 $this->cacheTypeConfigMock = $this->getMockBuilder(\
Magento\Framework\
App\Cache\Type\Config::class)
69 ->disableOriginalConstructor()
74 $this->block = $objectManagerHelper->getObject(
77 'context' => $this->contextMock,
78 'directoryHelper' => $this->helperDataMock,
79 'configCacheType' => $this->cacheTypeConfigMock,
80 'countryCollectionFactory' => $this->countryCollectionFactoryMock
84 $this->serializerMock = $this->createMock(SerializerInterface::class);
85 $objectManagerHelper->setBackwardCompatibleProperty(
94 $this->storeMock = $this->getMockBuilder(\
Magento\
Store\Model\Store::class)
95 ->disableOriginalConstructor()
98 $this->scopeConfigMock = $this->getMockBuilder(\
Magento\Framework\
App\
Config\ScopeConfigInterface::class)
99 ->getMockForAbstractClass();
101 $this->storeManagerMock = $this->getMockBuilder(\
Magento\
Store\Model\StoreManagerInterface::class)
102 ->getMockForAbstractClass();
104 $this->storeManagerMock->expects($this->any())
106 ->willReturn($this->storeMock);
108 $this->layoutMock = $this->getMockBuilder(\
Magento\Framework\View\LayoutInterface::class)
109 ->getMockForAbstractClass();
111 $this->contextMock = $this->getMockBuilder(\
Magento\Framework\View\Element\Template\Context::class)
112 ->disableOriginalConstructor()
115 $this->contextMock->expects($this->any())
116 ->method(
'getScopeConfig')
117 ->willReturn($this->scopeConfigMock);
119 $this->contextMock->expects($this->any())
120 ->method(
'getStoreManager')
121 ->willReturn($this->storeManagerMock);
123 $this->contextMock->expects($this->any())
124 ->method(
'getLayout')
125 ->willReturn($this->layoutMock);
130 $this->countryCollectionMock = $this->getMockBuilder(
132 )->disableOriginalConstructor()->getMock();
134 $this->countryCollectionFactoryMock = $this->getMockBuilder(
137 ->disableOriginalConstructor()
143 $this->countryCollectionFactoryMock->expects($this->any())
145 ->willReturn($this->countryCollectionMock);
161 $expectedDestinations,
165 $this->helperDataMock->expects($this->once())
166 ->method(
'getDefaultCountry')
167 ->willReturn($defaultCountry);
169 $this->storeMock->expects($this->once())
173 $this->serializerMock->expects($this->once())
174 ->method(
'serialize')
175 ->willReturn(
'serializedData');
177 $this->cacheTypeConfigMock->expects($this->once())
179 ->with(
'DIRECTORY_COUNTRY_SELECT_STORE_' .
$storeCode)
181 $this->cacheTypeConfigMock->expects($this->once())
183 ->with(
'serializedData',
'DIRECTORY_COUNTRY_SELECT_STORE_' .
$storeCode)
186 $this->scopeConfigMock->expects($this->once())
189 ->willReturn($destinations);
191 $this->countryCollectionMock->expects($this->once())
192 ->method(
'loadByStore')
194 $this->countryCollectionMock->expects($this->any())
195 ->method(
'setForegroundCountries')
196 ->with($expectedDestinations)
198 $this->countryCollectionMock->expects($this->once())
199 ->method(
'toOptionArray')
204 $this->layoutMock->expects($this->once())
205 ->method(
'createBlock')
206 ->willReturn($elementHtmlSelect);
208 $this->assertEquals($resultHtml, $this->block->getCountryHtmlSelect());
231 'label' =>
'United States',
246 'label' =>
'United States',
262 'label' =>
'United States',
266 'label' =>
'Great Britain',
282 $name =
'country_id';
286 $elementHtmlSelect = $this->getMockBuilder(\
Magento\Framework\View\Element\Html\Select::class)
287 ->disableOriginalConstructor()
299 $elementHtmlSelect->expects($this->once())
303 $elementHtmlSelect->expects($this->once())
307 $elementHtmlSelect->expects($this->once())
311 $elementHtmlSelect->expects($this->once())
313 ->with($defaultCountry)
315 $elementHtmlSelect->expects($this->once())
316 ->method(
'setOptions')
319 $elementHtmlSelect->expects($this->once())
320 ->method(
'setExtraParams')
321 ->with(
'data-validate="{\'validate-select\':true}"')
323 $elementHtmlSelect->expects($this->once())
325 ->willReturn($resultHtml);
327 return $elementHtmlSelect;
testGetCountryHtmlSelect( $storeCode, $defaultCountry, $destinations, $expectedDestinations, $options, $resultHtml)
dataProviderGetCountryHtmlSelect()
mockElementHtmlSelect($defaultCountry, $options, $resultHtml)
prepareCountryCollection()
if(!isset($_GET['name'])) $name