示例#1
0
 /**
  * @dataProvider toOptionArrayDataProvider
  * @param boolean $isMultiselect
  * @param string|array $foregroundCountries
  * @param array $expectedResult
  */
 public function testToOptionArray($isMultiselect, $foregroundCountries, $expectedResult)
 {
     $this->_collectionMock->expects($this->once())->method('loadData')->will($this->returnSelf());
     $this->_collectionMock->expects($this->once())->method('setForegroundCountries')->with($foregroundCountries)->will($this->returnSelf());
     $this->_collectionMock->expects($this->once())->method('toOptionArray')->will($this->returnValue([]));
     $this->assertEquals($this->_model->toOptionArray($isMultiselect, $foregroundCountries), $expectedResult);
 }
示例#2
0
 /**
  * Return options array
  *
  * @param boolean $isMultiselect
  * @param string|array $foregroundCountries
  * @return array
  */
 public function toOptionArray($isMultiselect = false, $foregroundCountries = '')
 {
     if (!$this->_options) {
         $this->_options = $this->_countryCollection->loadData()->setForegroundCountries($foregroundCountries)->toOptionArray(false);
     }
     $options = $this->_options;
     if (!$isMultiselect) {
         array_unshift($options, ['value' => '', 'label' => __('--Please Select--')]);
     }
     return $options;
 }
示例#3
0
 public function testToOptionArray()
 {
     $excludedCountries = $this->model->getRestrictedCountries();
     $countries = [['value' => 'US', 'lable' => 'United States'], ['value' => 'countryCode', 'lable' => 'countryName']];
     $this->countryCollectionMock->expects($this->once())->method('addFieldToFilter')->with('country_id', ['nin' => $excludedCountries])->willReturnSelf();
     $this->countryCollectionMock->expects($this->once())->method('loadData')->willReturnSelf();
     $this->countryCollectionMock->expects($this->once())->method('toOptionArray')->willReturn($countries);
     $header = ['value' => '', 'label' => new \Magento\Framework\Phrase('--Please Select--')];
     array_unshift($countries, $header);
     $this->assertEquals($countries, $this->model->toOptionArray());
 }
示例#4
0
 /**
  * @param bool $isMultiselect
  * @return array
  */
 public function toOptionArray($isMultiselect = false)
 {
     if (!$this->options) {
         $this->options = $this->countryCollection->addFieldToFilter('country_id', ['nin' => $this->excludedCountries])->loadData()->toOptionArray(false);
     }
     $options = $this->options;
     if (!$isMultiselect) {
         array_unshift($options, ['value' => '', 'label' => __('--Please Select--')]);
     }
     return $options;
 }
示例#5
0
 /**
  * @dataProvider toOptionArrayDataProvider
  * @param array $optionsArray
  * @param string|boolean $emptyLabel
  * @param string|array $foregroundCountries
  * @param array $expectedResults
  */
 public function testToOptionArray($optionsArray, $emptyLabel, $foregroundCountries, $expectedResults)
 {
     foreach ($optionsArray as $itemData) {
         $this->_model->addItem(new \Magento\Framework\Object($itemData));
     }
     $this->_model->setForegroundCountries($foregroundCountries);
     $result = $this->_model->toOptionArray($emptyLabel);
     $this->assertEquals(count($optionsArray) + (int) (!empty($emptyLabel)), count($result));
     foreach ($expectedResults as $index => $expectedResult) {
         $this->assertEquals($expectedResult, $result[$index]['label']);
     }
 }
示例#6
0
 public function testGetRegionJson()
 {
     $countries = array(new \Magento\Framework\Object(array('country_id' => 'Country1')), new \Magento\Framework\Object(array('country_id' => 'Country2')));
     $countryIterator = new \ArrayIterator($countries);
     $this->_countryCollection->expects($this->atLeastOnce())->method('getIterator')->will($this->returnValue($countryIterator));
     $regions = array(new \Magento\Framework\Object(array('country_id' => 'Country1', 'region_id' => 'r1', 'code' => 'r1-code', 'name' => 'r1-name')), new \Magento\Framework\Object(array('country_id' => 'Country1', 'region_id' => 'r2', 'code' => 'r2-code', 'name' => 'r2-name')), new \Magento\Framework\Object(array('country_id' => 'Country2', 'region_id' => 'r3', 'code' => 'r3-code', 'name' => 'r3-name')));
     $regionIterator = new \ArrayIterator($regions);
     $this->_regionCollection->expects($this->once())->method('addCountryFilter')->with(array('Country1', 'Country2'))->will($this->returnSelf());
     $this->_regionCollection->expects($this->once())->method('load');
     $this->_regionCollection->expects($this->once())->method('getIterator')->will($this->returnValue($regionIterator));
     $expectedDataToEncode = array('config' => array('show_all_regions' => false, 'regions_required' => array()), 'Country1' => array('r1' => array('code' => 'r1-code', 'name' => 'r1-name'), 'r2' => array('code' => 'r2-code', 'name' => 'r2-name')), 'Country2' => array('r3' => array('code' => 'r3-code', 'name' => 'r3-name')));
     $this->_coreHelper->expects($this->once())->method('jsonEncode')->with(new \PHPUnit_Framework_Constraint_IsIdentical($expectedDataToEncode))->will($this->returnValue('encoded_json'));
     // Test
     $result = $this->_object->getRegionJson();
     $this->assertEquals('encoded_json', $result);
 }
示例#7
0
 /**
  * Retrieve country collection
  *
  * @return \Magento\Directory\Model\Resource\Country\Collection
  */
 public function getCountryCollection()
 {
     if (!$this->_countryCollection->isLoaded()) {
         $this->_countryCollection->loadByStore();
     }
     return $this->_countryCollection;
 }
 /**
  * @dataProvider toOptionArrayDataProvider
  * @param bool $isMultiselect
  * @param array $countries
  * @param array $regions
  * @param array $expectedResult
  */
 public function testToOptionArray($isMultiselect, $countries, $regions, $expectedResult)
 {
     $this->countryCollection->expects($this->once())->method('toOptionArray')->with(false)->will($this->returnValue(new \ArrayIterator($countries)));
     $this->regionCollection->expects($this->once())->method('getIterator')->will($this->returnValue(new \ArrayIterator($regions)));
     $this->assertEquals($expectedResult, $this->model->toOptionArray($isMultiselect));
 }