Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
LayoutProcessorTest.php
Go to the documentation of this file.
1 <?php
7 
8 class LayoutProcessorTest extends \PHPUnit\Framework\TestCase
9 {
13  private $layoutProcessor;
14 
18  protected $model;
19 
23  protected $merger;
24 
28  protected $countryCollection;
29 
33  protected $regionCollection;
34 
39 
40  protected function setUp()
41  {
42  $this->merger = $this->getMockBuilder(\Magento\Checkout\Block\Checkout\AttributeMerger::class)
43  ->disableOriginalConstructor()
44  ->getMock();
45  $this->countryCollection =
46  $this->getMockBuilder(\Magento\Directory\Model\ResourceModel\Country\Collection::class)
47  ->disableOriginalConstructor()
48  ->getMock();
49  $this->regionCollection =
50  $this->getMockBuilder(\Magento\Directory\Model\ResourceModel\Region\Collection::class)
51  ->disableOriginalConstructor()
52  ->getMock();
53  $this->topDestinationCountries =
54  $this->getMockBuilder(\Magento\Directory\Model\TopDestinationCountries::class)
55  ->disableOriginalConstructor()
56  ->getMock();
57  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
58  $this->layoutProcessor = $objectManager->getObject(
59  \Magento\Checkout\Block\Cart\LayoutProcessor::class,
60  [
61  'merger' => $this->merger,
62  'countryCollection' => $this->countryCollection,
63  'regionCollection' => $this->regionCollection,
64  'topDestinationCountries' => $this->topDestinationCountries
65  ]
66  );
67  }
68 
69  public function testProcess()
70  {
71  $countries = [];
72  $regions = [];
73  $topDestinationCountries = ['UA','AF'];
74 
75  $layout = [];
76  $layout['components']['block-summary']['children']['block-shipping']['children']
77  ['address-fieldsets']['children'] = [
78  'fieldOne' => ['param' => 'value'],
79  'fieldTwo' => ['param' => 'value']
80  ];
81  $layoutPointer = &$layout['components']['block-summary']['children']['block-shipping']
82  ['children']['address-fieldsets']['children'];
83 
84  $this->countryCollection->expects($this->once())->method('loadByStore')->willReturnSelf();
85  $this->countryCollection
86  ->expects($this->once())
87  ->method('setForegroundCountries')
89  ->willReturnSelf();
90  $this->countryCollection->expects($this->once())->method('toOptionArray')->willReturn($countries);
91 
92  $this->regionCollection->expects($this->once())->method('addAllowedCountriesFilter')->willReturnSelf();
93  $this->regionCollection->expects($this->once())->method('toOptionArray')->willReturn($regions);
94 
95  $this->topDestinationCountries->expects($this->once())->method('getTopDestinations')
96  ->willReturn($topDestinationCountries);
97 
98  $layoutMerged = $layout;
99  $layoutMerged['components']['block-summary']['children']['block-shipping']['children']
100  ['address-fieldsets']['children']['fieldThree'] = ['param' => 'value'];
101  $layoutMergedPointer = &$layoutMerged['components']['block-summary']['children']['block-shipping']
102  ['children']['address-fieldsets']['children'];
103  $layoutMerged['components']['checkoutProvider'] = [
104  'dictionaries' => [
105  'country_id' => [],
106  'region_id' => [],
107  ]
108  ];
109  $elements = [
110  'city' => [
111  'visible' => false,
112  'formElement' => 'input',
113  'label' => __('City'),
114  'value' => null
115  ],
116  'country_id' => [
117  'visible' => 1,
118  'formElement' => 'select',
119  'label' => __('Country'),
120  'options' => [],
121  'value' => null
122  ],
123  'region_id' => [
124  'visible' => 1,
125  'formElement' => 'select',
126  'label' => __('State/Province'),
127  'options' => [],
128  'value' => null
129  ],
130  'postcode' => [
131  'visible' => 1,
132  'formElement' => 'input',
133  'label' => __('Zip/Postal Code'),
134  'value' => null
135  ]
136  ];
137  $this->merger->expects($this->once())
138  ->method('merge')
139  ->with($elements, 'checkoutProvider', 'shippingAddress', $layoutPointer)
140  ->willReturn($layoutMergedPointer);
141 
142  $this->assertEquals($layoutMerged, $this->layoutProcessor->process($layout));
143  }
144 }
$objectManager
Definition: bootstrap.php:17
__()
Definition: __.php:13