public function testGetRegionJson() { $countries = [new \Magento\Framework\DataObject(['country_id' => 'Country1']), new \Magento\Framework\DataObject(['country_id' => 'Country2'])]; $countryIterator = new \ArrayIterator($countries); $this->_countryCollection->expects($this->atLeastOnce())->method('getIterator')->will($this->returnValue($countryIterator)); $regions = [new \Magento\Framework\DataObject(['country_id' => 'Country1', 'region_id' => 'r1', 'code' => 'r1-code', 'name' => 'r1-name']), new \Magento\Framework\DataObject(['country_id' => 'Country1', 'region_id' => 'r2', 'code' => 'r2-code', 'name' => 'r2-name']), new \Magento\Framework\DataObject(['country_id' => 'Country2', 'region_id' => 'r3', 'code' => 'r3-code', 'name' => 'r3-name'])]; $regionIterator = new \ArrayIterator($regions); $this->_regionCollection->expects($this->once())->method('addCountryFilter')->with(['Country1', 'Country2'])->will($this->returnSelf()); $this->_regionCollection->expects($this->once())->method('load'); $this->_regionCollection->expects($this->once())->method('getIterator')->will($this->returnValue($regionIterator)); $expectedDataToEncode = ['config' => ['show_all_regions' => false, 'regions_required' => []], 'Country1' => ['r1' => ['code' => 'r1-code', 'name' => 'r1-name'], 'r2' => ['code' => 'r2-code', 'name' => 'r2-name']], 'Country2' => ['r3' => ['code' => 'r3-code', 'name' => 'r3-name']]]; $this->jsonHelperMock->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\\ResourceModel\\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\DataObject(['id' => $regionId])); $this->assertEquals($regionId, $this->block->getRegionIdByName($regionCode, $countryId)); }