Ejemplo n.º 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);
 }
Ejemplo n.º 2
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());
 }
Ejemplo n.º 3
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);
 }
Ejemplo n.º 4
0
 /**
  * @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));
 }