Ejemplo n.º 1
0
 /**
  * Process js Layout of block
  *
  * @param array $jsLayout
  * @return array
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function process($jsLayout)
 {
     $elements = ['city' => ['visible' => $this->isCityActive(), 'formElement' => 'input', 'label' => __('City'), 'value' => null], 'country_id' => ['visible' => true, 'formElement' => 'select', 'label' => __('Country'), 'options' => $this->countryCollection->load()->toOptionArray(), 'value' => null], 'region_id' => ['visible' => true, 'formElement' => 'select', 'label' => __('State/Province'), 'options' => $this->regionCollection->load()->toOptionArray(), 'value' => null], 'postcode' => ['visible' => true, 'formElement' => 'input', 'label' => __('Zip/Postal Code'), 'value' => null]];
     if (isset($jsLayout['components']['block-summary']['children']['block-shipping']['children']['address-fieldsets']['children'])) {
         $fieldSetPointer =& $jsLayout['components']['block-summary']['children']['block-shipping']['children']['address-fieldsets']['children'];
         $fieldSetPointer = $this->merger->merge($elements, 'checkoutProvider', 'shippingAddress', $fieldSetPointer);
     }
     return $jsLayout;
 }
 /**
  * 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;
 }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
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.º 5
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;
 }
Ejemplo n.º 6
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\DataObject($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']);
     }
 }
Ejemplo n.º 7
0
 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);
 }
Ejemplo n.º 8
0
 /**
  * Retrieve country collection
  *
  * @param null|int|string|\Magento\Store\Model\Store $store
  * @return \Magento\Directory\Model\ResourceModel\Country\Collection
  */
 public function getCountryCollection($store = null)
 {
     if (!$this->_countryCollection->isLoaded()) {
         $this->_countryCollection->loadByStore($store);
     }
     return $this->_countryCollection;
 }
 /**
  * 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);
 }
Ejemplo n.º 10
0
 /**
  * 2016-05-19
  * @override
  * @see \Magento\Directory\Model\ResourceModel\Country\Collection::_construct
  * @return void
  */
 protected function _construct()
 {
     parent::_construct();
     $this->setModel(Country::class);
 }
Ejemplo n.º 11
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));
 }
Ejemplo n.º 12
-1
 /**
  * @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);
 }