Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DirectoryDataProcessorTest.php
Go to the documentation of this file.
1 <?php
7 
8 class DirectoryDataProcessorTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $model;
14 
19 
24 
29 
34 
38  protected $storeResolverMock;
39 
43  protected $storeManagerMock;
44 
48  private $directoryDataHelperMock;
49 
50  protected function setUp()
51  {
52  $this->countryCollectionFactoryMock = $this->createPartialMock(
53  \Magento\Directory\Model\ResourceModel\Country\CollectionFactory::class,
54  ['create']
55  );
56  $this->countryCollectionMock = $this->createMock(
57  \Magento\Directory\Model\ResourceModel\Country\Collection::class
58  );
59  $this->regionCollectionFactoryMock = $this->createPartialMock(
60  \Magento\Directory\Model\ResourceModel\Region\CollectionFactory::class,
61  ['create']
62  );
63  $this->regionCollectionMock = $this->createMock(
64  \Magento\Directory\Model\ResourceModel\Region\Collection::class
65  );
66  $this->storeResolverMock = $this->createMock(
67  \Magento\Store\Api\StoreResolverInterface::class
68  );
69  $this->directoryDataHelperMock = $this->createMock(\Magento\Directory\Helper\Data::class);
70  $this->storeManagerMock = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
71  ->disableOriginalConstructor()
72  ->getMock();
73 
74  $this->model = new \Magento\Checkout\Block\Checkout\DirectoryDataProcessor(
75  $this->countryCollectionFactoryMock,
76  $this->regionCollectionFactoryMock,
77  $this->storeResolverMock,
78  $this->directoryDataHelperMock,
79  $this->storeManagerMock
80  );
81  }
82 
83  public function testProcess()
84  {
85  $expectedResult['components']['checkoutProvider']['dictionaries'] = [
86  'country_id' => [],
87  'region_id' => [],
88  ];
89 
90  $storeMock = $this->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class)
91  ->disableOriginalConstructor()
92  ->getMock();
93  $storeMock->expects($this->atLeastOnce())->method('getId')->willReturn(42);
94  $this->storeManagerMock->expects($this->atLeastOnce())->method('getStore')->willReturn($storeMock);
95 
96  $this->countryCollectionFactoryMock->expects($this->once())
97  ->method('create')
98  ->willReturn($this->countryCollectionMock);
99  $this->countryCollectionMock->expects($this->once())->method('loadByStore')->willReturnSelf();
100  $this->countryCollectionMock->expects($this->once())->method('toOptionArray')->willReturn([]);
101  $this->regionCollectionFactoryMock->expects($this->once())
102  ->method('create')
103  ->willReturn($this->regionCollectionMock);
104  $this->regionCollectionMock->expects($this->once())->method('addAllowedCountriesFilter')->willReturnSelf();
105  $this->regionCollectionMock->expects($this->once())->method('toOptionArray')->willReturn([]);
106 
107  $this->assertEquals($expectedResult, $this->model->process([]));
108  }
109 }