/** * Create mock for country collection factory */ protected function getCollectionFactoryMock() { $this->collection = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->setMethods(['addFieldToFilter', 'loadData', 'toOptionArray', '__wakeup'])->getMock(); $this->collection->expects(static::any())->method('addFieldToFilter')->willReturnSelf(); $this->collection->expects(static::any())->method('loadData')->willReturnSelf(); $collectionFactory = $this->getMockBuilder(CollectionFactory::class)->disableOriginalConstructor()->setMethods(['create'])->getMock(); $collectionFactory->expects(static::once())->method('create')->willReturn($this->collection); return $collectionFactory; }
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()); }
public function testGetCountryCollection() { $this->_countryCollection->expects($this->once())->method('isLoaded')->will($this->returnValue(0)); $store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false); $this->_countryCollection->expects($this->once())->method('loadByStore')->with($store); $this->_object->getCountryCollection($store); }
/** * Init country collection mock * @param array $countries */ protected function initCountryCollectionMock(array $countries) { $this->countryCollectionMock->expects(static::once())->method('addFieldToFilter')->willReturnSelf(); $this->countryCollectionMock->expects(static::once())->method('loadData')->willReturnSelf(); $this->countryCollectionMock->expects(static::once())->method('toOptionArray')->willReturn($countries); }
/** * @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)); }
/** * @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); }