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); }
public function testGetRegionIdByName() { $regionCode = 'TX'; $countryId = 'US'; $regionId = 57; $regionCollectionMock = $this->getMockBuilder('\\Magento\\Directory\\Model\\Resource\\Region\\Collection')->disableOriginalConstructor()->getMock(); $this->regionCollectionFactoryMock->expects($this->once())->method('create')->willReturn($regionCollectionMock); $regionCollectionMock->expects($this->once())->method('addRegionCodeOrNameFilter')->with($regionCode)->willReturnSelf(); $regionCollectionMock->expects($this->once())->method('addCountryFilter')->with($countryId)->willReturnSelf(); $regionCollectionMock->expects($this->once())->method('getSize')->willReturn(1); $regionCollectionMock->expects($this->once())->method('getFirstItem')->willReturn(new \Magento\Framework\Object(['id' => $regionId])); $this->assertEquals($regionId, $this->block->getRegionIdByName($regionCode, $countryId)); }