Skip to content

Commit 1df03f5

Browse files
author
Oleksandr Dubovyk
committed
Merge remote-tracking branch 'origin/develop' into PR
2 parents 8474a57 + 2badc7e commit 1df03f5

File tree

10 files changed

+245
-71
lines changed

10 files changed

+245
-71
lines changed

app/code/Magento/Cms/view/adminhtml/ui_component/cms_page_form.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
<item name="config" xsi:type="array">
100100
<item name="collapsible" xsi:type="boolean">true</item>
101101
<item name="label" xsi:type="string" translate="true">Content</item>
102+
<item name="sortOrder" xsi:type="number">10</item>
102103
</item>
103104
</argument>
104105
<field name="content_heading">
@@ -130,6 +131,7 @@
130131
<item name="config" xsi:type="array">
131132
<item name="collapsible" xsi:type="boolean">true</item>
132133
<item name="label" xsi:type="string" translate="true">Search Engine Optimisation</item>
134+
<item name="sortOrder" xsi:type="number">20</item>
133135
</item>
134136
</argument>
135137
<field name="identifier">
@@ -174,6 +176,7 @@
174176
<item name="config" xsi:type="array">
175177
<item name="collapsible" xsi:type="boolean">true</item>
176178
<item name="label" xsi:type="string" translate="true">Page in Websites</item>
179+
<item name="sortOrder" xsi:type="number">30</item>
177180
</item>
178181
</argument>
179182
<field name="storeviews">
@@ -198,6 +201,7 @@
198201
<item name="config" xsi:type="array">
199202
<item name="collapsible" xsi:type="boolean">true</item>
200203
<item name="label" xsi:type="string" translate="true">Design</item>
204+
<item name="sortOrder" xsi:type="number">50</item>
201205
</item>
202206
</argument>
203207
<field name="page_layout">
@@ -229,6 +233,7 @@
229233
<item name="config" xsi:type="array">
230234
<item name="collapsible" xsi:type="boolean">true</item>
231235
<item name="label" xsi:type="string" translate="true">Custom Design Update</item>
236+
<item name="sortOrder" xsi:type="number">60</item>
232237
</item>
233238
</argument>
234239
<field name="custom_theme_from">

app/code/Magento/Customer/Block/Address/Edit.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,10 @@ protected function _prepareLayout()
126126
$this->pageConfig->getTitle()->set($this->getTitle());
127127

128128
if ($postedData = $this->_customerSession->getAddressFormData(true)) {
129-
if (!empty($postedData['region_id']) || !empty($postedData['region'])) {
130-
$postedData['region'] = [
131-
'region_id' => $postedData['region_id'],
132-
'region' => $postedData['region'],
133-
];
134-
}
129+
$postedData['region'] = [
130+
'region_id' => $postedData['region_id'],
131+
'region' => $postedData['region'],
132+
];
135133
$this->dataObjectHelper->populateWithArray(
136134
$this->_address,
137135
$postedData,

app/code/Magento/Customer/Controller/Address/FormPost.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,10 @@ protected function getExistingAddressData()
146146
*/
147147
protected function updateRegionData(&$attributeValues)
148148
{
149-
if ($this->helperData->isRegionRequired($attributeValues['country_id'])) {
149+
if (!empty($attributeValues['region_id'])) {
150150
$newRegion = $this->regionFactory->create()->load($attributeValues['region_id']);
151151
$attributeValues['region_code'] = $newRegion->getCode();
152152
$attributeValues['region'] = $newRegion->getDefaultName();
153-
} else {
154-
$attributeValues['region_id'] = null;
155153
}
156154

157155
$regionData = [

app/code/Magento/Customer/Model/ResourceModel/AddressRepository.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,20 @@ private function _validate(CustomerAddressModel $customerAddressModel)
287287
$exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'countryId']));
288288
}
289289

290-
if ($customerAddressModel->getCountryModel()->getRegionCollection()->getSize()
291-
&& !\Zend_Validate::is($customerAddressModel->getRegionId(), 'NotEmpty')
292-
&& $this->directoryData->isRegionRequired($customerAddressModel->getCountryId())
293-
) {
294-
$exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'regionId']));
290+
if ($this->directoryData->isRegionRequired($customerAddressModel->getCountryId())) {
291+
$regionCollection = $customerAddressModel->getCountryModel()->getRegionCollection();
292+
if (!$regionCollection->count() && empty($customerAddressModel->getRegion())) {
293+
$exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'region']));
294+
} elseif (
295+
$regionCollection->count()
296+
&& !in_array(
297+
$customerAddressModel->getRegionId(),
298+
array_column($regionCollection->getData(), 'region_id')
299+
)
300+
) {
301+
$exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'regionId']));
302+
}
295303
}
296-
297304
return $exception;
298305
}
299306
}

app/code/Magento/Customer/Model/ResourceModel/CustomerRepository.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,13 +399,12 @@ protected function addFilterGroupToCollection(
399399
\Magento\Customer\Model\ResourceModel\Customer\Collection $collection
400400
) {
401401
$fields = [];
402-
$conditions = [];
403402
foreach ($filterGroup->getFilters() as $filter) {
404403
$condition = $filter->getConditionType() ? $filter->getConditionType() : 'eq';
405404
$fields[] = ['attribute' => $filter->getField(), $condition => $filter->getValue()];
406405
}
407406
if ($fields) {
408-
$collection->addFieldToFilter($fields, $conditions);
407+
$collection->addFieldToFilter($fields);
409408
}
410409
}
411410
}

app/code/Magento/Customer/Test/Unit/Controller/Address/FormPostTest.php

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,6 @@ public function testExecute(
411411
$addressId,
412412
$countryId,
413413
$customerId,
414-
$isRegionRequired,
415414
$regionId,
416415
$region,
417416
$regionCode,
@@ -489,11 +488,6 @@ public function testExecute(
489488
->with($newAddressData)
490489
->willReturn($newAddressData);
491490

492-
$this->helperData->expects($this->once())
493-
->method('isRegionRequired')
494-
->with($countryId)
495-
->willReturn($isRegionRequired);
496-
497491
$this->region->expects($this->any())
498492
->method('load')
499493
->with($newRegionId)
@@ -581,31 +575,31 @@ public function testExecute(
581575
public function dataProviderTestExecute()
582576
{
583577
return [
584-
[1, 1, 1, true, null, '', null, '', null, ''],
585-
[1, 1, 1, false, '', null, '', null, '', null],
578+
[1, 1, 1, null, '', null, '', null, ''],
579+
[1, 1, 1, '', null, '', null, '', null],
586580

587-
[1, 1, 1, true, null, null, null, 12, null, null],
588-
[1, 1, 1, true, null, null, null, 1, 'California', null],
589-
[1, 1, 1, true, null, null, null, 1, 'California', 'CA'],
581+
[1, 1, 1, null, null, null, 12, null, null],
582+
[1, 1, 1, null, null, null, 1, 'California', null],
583+
[1, 1, 1, null, null, null, 1, 'California', 'CA'],
590584

591-
[1, 1, 1, false, null, null, null, 1, null, 'CA'],
592-
[1, 1, 1, false, null, null, null, null, null, 'CA'],
585+
[1, 1, 1, null, null, null, 1, null, 'CA'],
586+
[1, 1, 1, null, null, null, null, null, 'CA'],
593587

594-
[1, 1, 1, true, 2, null, null, null, null, null],
595-
[1, 1, 1, true, 2, 'Alaska', null, null, null, null],
596-
[1, 1, 1, true, 2, 'Alaska', 'AK', null, null, null],
588+
[1, 1, 1, 2, null, null, null, null, null],
589+
[1, 1, 1, 2, 'Alaska', null, null, null, null],
590+
[1, 1, 1, 2, 'Alaska', 'AK', null, null, null],
597591

598-
[1, 1, 1, false, 2, null, null, null, null, null],
599-
[1, 1, 1, false, 2, 'Alaska', null, null, null, null],
600-
[1, 1, 1, false, 2, 'Alaska', 'AK', null, null, null],
592+
[1, 1, 1, 2, null, null, null, null, null],
593+
[1, 1, 1, 2, 'Alaska', null, null, null, null],
594+
[1, 1, 1, 2, 'Alaska', 'AK', null, null, null],
601595

602-
[1, 1, 1, true, 2, null, null, 12, null, null],
603-
[1, 1, 1, true, 2, 'Alaska', null, 12, null, 'CA'],
604-
[1, 1, 1, true, 2, 'Alaska', 'AK', 12, 'California', null],
596+
[1, 1, 1, 2, null, null, 12, null, null],
597+
[1, 1, 1, 2, 'Alaska', null, 12, null, 'CA'],
598+
[1, 1, 1, 2, 'Alaska', 'AK', 12, 'California', null],
605599

606-
[1, 1, 1, false, 2, null, null, 12, null, null],
607-
[1, 1, 1, false, 2, 'Alaska', null, 12, null, 'CA'],
608-
[1, 1, 1, false, 2, 'Alaska', 'AK', 12, 'California', null],
600+
[1, 1, 1, 2, null, null, 12, null, null],
601+
[1, 1, 1, 2, 'Alaska', null, 12, null, 'CA'],
602+
[1, 1, 1, 2, 'Alaska', 'AK', 12, 'California', null],
609603
];
610604
}
611605

app/code/Magento/Customer/Test/Unit/Model/ResourceModel/AddressRepositoryTest.php

Lines changed: 175 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public function setUp()
101101
'getCity',
102102
'getTelephone',
103103
'getRegionId',
104+
'getRegion',
104105
'updateData',
105106
'setCustomer',
106107
'getCountryModel',
@@ -211,6 +212,177 @@ public function testSaveWithException()
211212
$this->repository->save($customerAddress);
212213
}
213214

215+
/**
216+
* @expectedException \Magento\Framework\Exception\InputException
217+
* @expectedExceptionMessage region is a required field.
218+
*/
219+
public function testSaveWithInvalidRegion()
220+
{
221+
$customerId = 34;
222+
$addressId = 53;
223+
$customerAddress = $this->getMockForAbstractClass('Magento\Customer\Api\Data\AddressInterface', [], '', false);
224+
$customerAddress->expects($this->atLeastOnce())
225+
->method('getCustomerId')
226+
->willReturn($customerId);
227+
$customerAddress->expects($this->atLeastOnce())
228+
->method('getId')
229+
->willReturn($addressId);
230+
$this->customerRegistry->expects($this->once())
231+
->method('retrieve')
232+
->with($customerId)
233+
->willReturn($this->customer);
234+
$this->addressRegistry->expects($this->once())
235+
->method('retrieve')
236+
->with($addressId)
237+
->willReturn($this->address);
238+
$this->address->expects($this->once())
239+
->method('updateData')
240+
->with($customerAddress);
241+
$countryModel = $this->getMock('Magento\Directory\Model\Country', [], [], '', false);
242+
$regionCollection = $this->getMock(
243+
'Magento\Directory\Model\ResourceModel\Region\Collection',
244+
[],
245+
[],
246+
'',
247+
false
248+
);
249+
250+
$this->address->expects($this->once())
251+
->method('getShouldIgnoreValidation')
252+
->willReturn(false);
253+
$this->address->expects($this->atLeastOnce())
254+
->method('getCountryId')
255+
->willReturn(1);
256+
$this->address->expects($this->once())
257+
->method('getFirstname')
258+
->willReturn('firstname');
259+
$this->address->expects($this->once())
260+
->method('getLastname')
261+
->willReturn('lastname');
262+
$this->address->expects($this->once())
263+
->method('getStreetLine')
264+
->with(1)
265+
->willReturn('street line');
266+
$this->address->expects($this->once())
267+
->method('getCity')
268+
->willReturn('city');
269+
$this->address->expects($this->once())
270+
->method('getTelephone')
271+
->willReturn('23423423423');
272+
$this->address->expects($this->never())
273+
->method('getRegionId')
274+
->willReturn(null);
275+
276+
$this->directoryData->expects($this->once())
277+
->method('getCountriesWithOptionalZip')
278+
->willReturn([1]);
279+
$this->address->expects($this->once())
280+
->method('getCountryModel')
281+
->willReturn($countryModel);
282+
$countryModel->expects($this->once())
283+
->method('getRegionCollection')
284+
->willReturn($regionCollection);
285+
$regionCollection->expects($this->once())
286+
->method('count')
287+
->willReturn(0);
288+
$this->directoryData->expects($this->once())
289+
->method('isRegionRequired')
290+
->with(1)
291+
->willReturn(true);
292+
$this->address->expects($this->once())
293+
->method('getRegion')
294+
->willReturn('');
295+
296+
$this->repository->save($customerAddress);
297+
}
298+
299+
/**
300+
* @expectedException \Magento\Framework\Exception\InputException
301+
* @expectedExceptionMessage regionId is a required field.
302+
*/
303+
public function testSaveWithInvalidRegionId()
304+
{
305+
$customerId = 34;
306+
$addressId = 53;
307+
$customerAddress = $this->getMockForAbstractClass('Magento\Customer\Api\Data\AddressInterface', [], '', false);
308+
$customerAddress->expects($this->atLeastOnce())
309+
->method('getCustomerId')
310+
->willReturn($customerId);
311+
$customerAddress->expects($this->atLeastOnce())
312+
->method('getId')
313+
->willReturn($addressId);
314+
$this->customerRegistry->expects($this->once())
315+
->method('retrieve')
316+
->with($customerId)
317+
->willReturn($this->customer);
318+
$this->addressRegistry->expects($this->once())
319+
->method('retrieve')
320+
->with($addressId)
321+
->willReturn($this->address);
322+
$this->address->expects($this->once())
323+
->method('updateData')
324+
->with($customerAddress);
325+
$countryModel = $this->getMock('Magento\Directory\Model\Country', [], [], '', false);
326+
$regionCollection = $this->getMock(
327+
'Magento\Directory\Model\ResourceModel\Region\Collection',
328+
[],
329+
[],
330+
'',
331+
false
332+
);
333+
334+
$this->address->expects($this->once())
335+
->method('getShouldIgnoreValidation')
336+
->willReturn(false);
337+
$this->address->expects($this->atLeastOnce())
338+
->method('getCountryId')
339+
->willReturn(1);
340+
$this->address->expects($this->once())
341+
->method('getFirstname')
342+
->willReturn('firstname');
343+
$this->address->expects($this->once())
344+
->method('getLastname')
345+
->willReturn('lastname');
346+
$this->address->expects($this->once())
347+
->method('getStreetLine')
348+
->with(1)
349+
->willReturn('street line');
350+
$this->address->expects($this->once())
351+
->method('getCity')
352+
->willReturn('city');
353+
$this->address->expects($this->once())
354+
->method('getTelephone')
355+
->willReturn('23423423423');
356+
$this->address->expects($this->once())
357+
->method('getRegionId')
358+
->willReturn(2);
359+
360+
$this->directoryData->expects($this->once())
361+
->method('getCountriesWithOptionalZip')
362+
->willReturn([1]);
363+
$this->address->expects($this->once())
364+
->method('getCountryModel')
365+
->willReturn($countryModel);
366+
$countryModel->expects($this->once())
367+
->method('getRegionCollection')
368+
->willReturn($regionCollection);
369+
$regionCollection->expects($this->atLeastOnce())
370+
->method('count')
371+
->willReturn(2);
372+
$regionCollection->expects($this->once())
373+
->method('getData')
374+
->willReturn([5, 6, 7, 8, 9]);
375+
$this->directoryData->expects($this->once())
376+
->method('isRegionRequired')
377+
->with(1)
378+
->willReturn(true);
379+
$this->address->expects($this->never())
380+
->method('getRegion')
381+
->willReturn('');
382+
383+
$this->repository->save($customerAddress);
384+
}
385+
214386
protected function prepareMocksForInvalidAddressValidation()
215387
{
216388
$countryModel = $this->getMock('Magento\Directory\Model\Country', [], [], '', false);
@@ -238,7 +410,7 @@ protected function prepareMocksForInvalidAddressValidation()
238410
->method('getCity');
239411
$this->address->expects($this->once())
240412
->method('getTelephone');
241-
$this->address->expects($this->once())
413+
$this->address->expects($this->never())
242414
->method('getRegionId')
243415
->willReturn(null);
244416

@@ -252,8 +424,8 @@ protected function prepareMocksForInvalidAddressValidation()
252424
->method('getRegionCollection')
253425
->willReturn($regionCollection);
254426
$regionCollection->expects($this->once())
255-
->method('getSize')
256-
->willReturn(2);
427+
->method('count')
428+
->willReturn(0);
257429
$this->directoryData->expects($this->once())
258430
->method('isRegionRequired')
259431
->with(null)

app/code/Magento/Customer/Test/Unit/Model/ResourceModel/CustomerRepositoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ public function testGetList()
722722
->willReturn([$filterGroup]);
723723
$collection->expects($this->once())
724724
->method('addFieldToFilter')
725-
->with([['attribute' => 'Field', 'eq' => 'Value']], []);
725+
->with([['attribute' => 'Field', 'eq' => 'Value']]);
726726
$filterGroup->expects($this->once())
727727
->method('getFilters')
728728
->willReturn([$filter]);

0 commit comments

Comments
 (0)