27 $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
29 $countryCollectionFactory = $this->getMockBuilder(
31 )->setMethods([
'create',
'__wakeup',
'__sleep'])->disableOriginalConstructor()->getMock();
33 $this->countryCollection = $this->getMockBuilder(
35 )->setMethods([
'load',
'toOptionArray',
'__wakeup',
'__sleep'])
36 ->disableOriginalConstructor()
38 $countryCollectionFactory->expects($this->once())
40 ->will($this->returnValue($this->countryCollection));
41 $this->countryCollection->expects($this->once())
43 ->will($this->returnSelf());
45 $regionCollectionFactory = $this->getMockBuilder(
47 )->disableOriginalConstructor()->setMethods([
'create',
'__wakeup',
'__sleep'])->getMock();
48 $this->regionCollection = $this->getMockBuilder(\
Magento\Directory\Model\
ResourceModel\Region\Collection::class)
49 ->disableOriginalConstructor()
50 ->setMethods([
'load',
'getIterator',
'__wakeup',
'__sleep'])
52 $regionCollectionFactory->expects($this->once())
54 ->will($this->returnValue($this->regionCollection));
55 $this->regionCollection->expects($this->once())
57 ->will($this->returnValue($this->regionCollection));
59 $this->model = $objectManagerHelper->getObject(
60 \
Magento\Directory\Model\Config\Source\Allregion::class,
62 'countryCollectionFactory' => $countryCollectionFactory,
63 'regionCollectionFactory' => $regionCollectionFactory
77 $this->countryCollection->expects($this->once())
78 ->method(
'toOptionArray')
80 ->will($this->returnValue(
new \ArrayIterator($countries)));
81 $this->regionCollection->expects($this->once())
82 ->method(
'getIterator')
83 ->will($this->returnValue(
new \ArrayIterator($regions)));
85 $this->assertEquals($expectedResult, $this->model->toOptionArray($isMultiselect));
99 $this->generateCountry(
'France',
'fr'),
102 $this->generateRegion(
'fr', 1,
'Paris')
123 $this->generateCountry(
'France',
'fr'),
126 $this->generateRegion(
'fr', 1,
'Paris'),
127 $this->generateRegion(
'fr', 2,
'Marseille')
138 'label' =>
'Marseille',
148 $this->generateCountry(
'France',
'fr'),
149 $this->generateCountry(
'Germany',
'de'),
152 $this->generateRegion(
'fr', 1,
'Paris'),
153 $this->generateRegion(
'de', 2,
'Berlin')
166 'label' =>
'Germany',
186 private function generateCountry($countryLabel, $countryValue)
189 'label' => $countryLabel,
190 'value' => $countryValue
202 private function generateRegion($countryId,
$id, $defaultName)
204 $region = $this->getMockBuilder(\
Magento\Directory\Model\Region::class)
205 ->disableOriginalConstructor()
206 ->setMethods([
'getCountryId',
'getId',
'getDefaultName',
'__wakeup',
'__sleep'])
208 $region->expects($this->once())
209 ->method(
'getCountryId')
210 ->will($this->returnValue($countryId));
211 $region->expects($this->once())
213 ->will($this->returnValue(
$id));
214 $region->expects($this->once())
215 ->method(
'getDefaultName')
216 ->will($this->returnValue($defaultName));
toOptionArrayDataProvider()
testToOptionArray($isMultiselect, $countries, $regions, $expectedResult)