Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
LayoutProcessorTest.php
Go to the documentation of this file.
1 <?php
7 
13 
15 use PHPUnit_Framework_MockObject_MockObject as MockObject;
16 
20 class LayoutProcessorTest extends \PHPUnit\Framework\TestCase
21 {
25  private $attributeDataProvider;
26 
30  private $attributeMapper;
31 
35  private $attributeMerger;
36 
40  private $dataHelper;
41 
45  private $layoutProcessor;
46 
50  private $storeManager;
51 
52  protected function setUp()
53  {
54  $this->attributeDataProvider = $this->getMockBuilder(AttributeMetadataDataProvider::class)
55  ->disableOriginalConstructor()
56  ->setMethods(['loadAttributesCollection'])
57  ->getMock();
58 
59  $this->attributeMapper = $this->getMockBuilder(AttributeMapper::class)
60  ->disableOriginalConstructor()
61  ->setMethods(['map'])
62  ->getMock();
63 
64  $this->attributeMerger = $this->getMockBuilder(AttributeMerger::class)
65  ->disableOriginalConstructor()
66  ->setMethods(['merge'])
67  ->getMock();
68 
69  $this->dataHelper = $this->getMockBuilder(Data::class)
70  ->disableOriginalConstructor()
71  ->setMethods(['isDisplayBillingOnPaymentMethodAvailable'])
72  ->getMock();
73 
74  $options = $this->getMockBuilder(Options::class)
75  ->disableOriginalConstructor()
76  ->getMock();
77 
78  $shippingConfig = $this->getMockBuilder(\Magento\Shipping\Model\Config::class)
79  ->disableOriginalConstructor()
80  ->getMock();
81 
82  $this->storeManager = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
83 
84  $this->layoutProcessor = new LayoutProcessor(
85  $this->attributeDataProvider,
86  $this->attributeMapper,
87  $this->attributeMerger,
88  $options,
89  $this->dataHelper,
90  $shippingConfig,
91  $this->storeManager
92  );
93  }
94 
98  public function testProcess()
99  {
100  $jsLayout = $this->getLayoutData();
101 
102  $this->attributeDataProvider->expects(static::once())
103  ->method('loadAttributesCollection')
104  ->willReturn([]);
105 
106  $this->dataHelper->expects(static::once())
107  ->method('isDisplayBillingOnPaymentMethodAvailable')
108  ->willReturn(true);
109 
110  $this->attributeMerger->expects(static::exactly(2))
111  ->method('merge')
112  ->willReturnMap([
113  ['payment1_1' => $this->getBillingComponent('payment1_1')],
114  ['payment2_1' => $this->getBillingComponent('payment2_1')],
115  ]);
116 
117  $actual = $this->layoutProcessor->process($jsLayout);
118 
119  static::assertArrayHasKey(
120  'payment1_1-form',
121  $actual['components']['checkout']['children']['steps']['children']['billing-step']['children']
122  ['payment']['children']['payments-list']['children']
123  );
124  static::assertArrayHasKey(
125  'payment2_1-form',
126  $actual['components']['checkout']['children']['steps']['children']['billing-step']['children']
127  ['payment']['children']['payments-list']['children']
128  );
129  static::assertArrayNotHasKey(
130  'payment2_2-form',
131  $actual['components']['checkout']['children']['steps']['children']['billing-step']['children']
132  ['payment']['children']['payments-list']['children']
133  );
134  static::assertArrayHasKey(
135  'afterMethods',
136  $actual['components']['checkout']['children']['steps']['children']['billing-step']
137  ['children']['payment']['children']
138  );
139  static::assertEmpty(
140  $actual['components']['checkout']['children']['steps']['children']['billing-step']
141  ['children']['payment']['children']['afterMethods']['children']
142  );
143  }
144 
149  {
150  $jsLayout = $this->getLayoutData();
151 
152  $this->attributeDataProvider->expects(static::once())
153  ->method('loadAttributesCollection')
154  ->willReturn([]);
155 
156  $this->dataHelper->expects(static::once())
157  ->method('isDisplayBillingOnPaymentMethodAvailable')
158  ->willReturn(false);
159 
160  $this->attributeMerger->expects(static::once())
161  ->method('merge')
162  ->willReturn($this->getBillingComponent('shared'));
163 
164  $actual = $this->layoutProcessor->process($jsLayout);
165 
166  static::assertEmpty(
167  $actual['components']['checkout']['children']['steps']['children']['billing-step']['children']
168  ['payment']['children']['payments-list']['children']
169  );
170 
171  static::assertNotEmpty(
172  $actual['components']['checkout']['children']['steps']['children']['billing-step']['children']
173  ['payment']['children']['afterMethods']['children']
174  );
175  static::assertArrayHasKey(
176  'billing-address-form',
177  $actual['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']
178  ['children']['afterMethods']['children']
179  );
180  }
181 
186  private function getLayoutData()
187  {
188  return [
189  'components' => [
190  'checkout' => [
191  'children' => [
192  'steps' => [
193  'children' => [
194  'billing-step' => [
195  'children' => [
196  'payment' => [
197  'children' => [
198  'renders' => [
199  'children' => [
200  'payment1' => [
201  'methods' => [
202  'payment1_1' => [
203  'isBillingAddressRequired' => true
204  ]
205  ]
206  ],
207  'payment2' => [
208  'methods' => [
209  'payment2_1' => [
210  'isBillingAddressRequired' => true
211  ],
212  'payment2_2' => [
213  'isBillingAddressRequired' => false
214  ]
215  ]
216  ]
217  ]
218  ]
219  ]
220  ]
221  ]
222  ]
223  ]
224  ]
225  ]
226  ]
227  ]
228  ];
229  }
230 
236  private function getBillingComponent($paymentCode)
237  {
238  return [
239  'country_id' => [
240  'sortOrder' => 115,
241  ],
242  'region' => [
243  'visible' => false,
244  ],
245  'region_id' => [
246  'component' => 'Magento_Ui/js/form/element/region',
247  'config' => [
248  'template' => 'ui/form/field',
249  'elementTmpl' => 'ui/form/element/select',
250  'customEntry' => 'billingAddress' . $paymentCode . '.region',
251  ],
252  'validation' => [
253  'required-entry' => true,
254  ],
255  'filterBy' => [
256  'target' => '${ $.provider }:${ $.parentScope }.country_id',
257  'field' => 'country_id',
258  ],
259  ],
260  'postcode' => [
261  'component' => 'Magento_Ui/js/form/element/post-code',
262  'validation' => [
263  'required-entry' => true,
264  ],
265  ],
266  'company' => [
267  'validation' => [
268  'min_text_length' => 0,
269  ],
270  ],
271  'fax' => [
272  'validation' => [
273  'min_text_length' => 0,
274  ],
275  ],
276  'telephone' => [
277  'config' => [
278  'tooltip' => [
279  'description' => ('For delivery questions.'),
280  ],
281  ],
282  ],
283  ];
284  }
285 }
return false
Definition: gallery.phtml:36