Skip to content

Commit d875854

Browse files
🔃 [Magento Community Engineering] Community Contributions - 2.4-develop
Accepted Community Pull Requests: - #25905: [Checkout] Cover DirectoryData by Unit Test (by @edenduong) - #25774: [Config] Giving the possibility to have a config dependency based on empty config value (by @eduard13) - #25541: Removes hardcoded references to country selector component (by @krzksz) - #25604: Moving Ui message.js hide speed and timeout into variables for easier… (by @edward-simpson) - #25790: Don't disable FPC for maintenance, instead send "no cache" headers (by @Parakoopa) - #25808: No marginal white space validation added (by @ajithkumar-maragathavel) Fixed GitHub Issues: - #22416: Coupling beetwen Magento_Checkout::js/view/shipping.js:validateShippingInformation() and layout definition or view. (reported by @funkyproject) has been fixed in #25541 by @krzksz in 2.4-develop branch Related commits: 1. 666cca8 - #24229: Unable to enable maintenance mode when env.php is read only (reported by @ihor-sviziev) has been fixed in #25790 by @Parakoopa in 2.4-develop branch Related commits: 1. acd42b8 2. d1b81aa
2 parents 9125aa6 + 45e8188 commit d875854

File tree

18 files changed

+449
-391
lines changed

18 files changed

+449
-391
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Checkout\Test\Unit\CustomerData;
10+
11+
use Magento\Checkout\CustomerData\DirectoryData;
12+
use Magento\Directory\Helper\Data as HelperData;
13+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
14+
use Magento\Directory\Model\Country;
15+
use PHPUnit\Framework\TestCase;
16+
17+
class DirectoryDataTest extends TestCase
18+
{
19+
/**
20+
* @var DirectoryData
21+
*/
22+
private $model;
23+
24+
/**
25+
* @var HelperData|\PHPUnit_Framework_MockObject_MockObject
26+
*/
27+
private $directoryHelperMock;
28+
29+
/**
30+
* @var ObjectManagerHelper
31+
*/
32+
private $objectManager;
33+
34+
/**
35+
* Setup environment for testing
36+
*/
37+
protected function setUp()
38+
{
39+
$this->objectManager = new ObjectManagerHelper($this);
40+
$this->directoryHelperMock = $this->createMock(HelperData::class);
41+
42+
$this->model = $this->objectManager->getObject(
43+
DirectoryData::class,
44+
[
45+
'directoryHelper' => $this->directoryHelperMock
46+
]
47+
);
48+
}
49+
50+
/**
51+
* Test getSectionData() function
52+
*/
53+
public function testGetSectionData()
54+
{
55+
$regions = [
56+
'US' => [
57+
'TX' => [
58+
'code' => 'TX',
59+
'name' => 'Texas'
60+
]
61+
]
62+
];
63+
64+
$testCountryInfo = $this->objectManager->getObject(Country::class);
65+
$testCountryInfo->setData('country_id', 'US');
66+
$testCountryInfo->setData('iso2_code', 'US');
67+
$testCountryInfo->setData('iso3_code', 'USA');
68+
$testCountryInfo->setData('name_default', 'United States of America');
69+
$testCountryInfo->setData('name_en_US', 'United States of America');
70+
$countries = ['US' => $testCountryInfo];
71+
72+
$this->directoryHelperMock->expects($this->any())
73+
->method('getRegionData')
74+
->willReturn($regions);
75+
76+
$this->directoryHelperMock->expects($this->any())
77+
->method('getCountryCollection')
78+
->willReturn($countries);
79+
80+
/* Assert result */
81+
$this->assertEquals(
82+
[
83+
'US' => [
84+
'name' => 'United States of America',
85+
'regions' => [
86+
'TX' => [
87+
'code' => 'TX',
88+
'name' => 'Texas'
89+
]
90+
]
91+
]
92+
],
93+
$this->model->getSectionData()
94+
);
95+
}
96+
}

app/code/Magento/Checkout/view/frontend/web/js/view/shipping.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ define([
6060
template: 'Magento_Checkout/shipping',
6161
shippingFormTemplate: 'Magento_Checkout/shipping-address/form',
6262
shippingMethodListTemplate: 'Magento_Checkout/shipping-address/shipping-method-list',
63-
shippingMethodItemTemplate: 'Magento_Checkout/shipping-address/shipping-method-item'
63+
shippingMethodItemTemplate: 'Magento_Checkout/shipping-address/shipping-method-item',
64+
imports: {
65+
countryOptions: '${ $.parentName }.shippingAddress.shipping-address-fieldset.country_id:indexedOptions'
66+
}
6467
},
6568
visible: ko.observable(!quote.isVirtual()),
6669
errorValidationMessage: ko.observable(false),
@@ -276,9 +279,7 @@ define([
276279
loginFormSelector = 'form[data-role=email-with-possible-login]',
277280
emailValidationResult = customer.isLoggedIn(),
278281
field,
279-
country = registry.get(this.parentName + '.shippingAddress.shipping-address-fieldset.country_id'),
280-
countryIndexedOptions = country.indexedOptions,
281-
option = countryIndexedOptions[quote.shippingAddress().countryId],
282+
option = _.isObject(this.countryOptions) && this.countryOptions[quote.shippingAddress().countryId],
282283
messageContainer = registry.get('checkout.errors').messageContainer;
283284

284285
if (!quote.shippingMethod()) {

app/code/Magento/Cms/Test/Unit/Controller/Adminhtml/Block/SaveTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,58 @@ public function testSaveAndClose()
373373
$this->assertSame($this->resultRedirect, $this->saveController->execute());
374374
}
375375

376+
public function testSaveActionWithMarginalSpace()
377+
{
378+
$postData = [
379+
'title' => 'unique_title_123',
380+
'identifier' => ' unique_title_123',
381+
'stores' => ['0'],
382+
'is_active' => true,
383+
'content' => '',
384+
'back' => 'continue'
385+
];
386+
387+
$this->requestMock->expects($this->any())->method('getPostValue')->willReturn($postData);
388+
$this->requestMock->expects($this->atLeastOnce())
389+
->method('getParam')
390+
->willReturnMap(
391+
[
392+
['block_id', null, 1],
393+
['back', null, true],
394+
]
395+
);
396+
397+
$this->blockFactory->expects($this->atLeastOnce())
398+
->method('create')
399+
->willReturn($this->blockMock);
400+
401+
$this->blockRepository->expects($this->once())
402+
->method('getById')
403+
->with($this->blockId)
404+
->willReturn($this->blockMock);
405+
406+
$this->blockMock->expects($this->once())->method('setData');
407+
$this->blockRepository->expects($this->once())->method('save')
408+
->with($this->blockMock)
409+
->willThrowException(new \Exception('No marginal white space please.'));
410+
411+
$this->messageManagerMock->expects($this->never())
412+
->method('addSuccessMessage');
413+
$this->messageManagerMock->expects($this->once())
414+
->method('addExceptionMessage');
415+
416+
$this->dataPersistorMock->expects($this->any())
417+
->method('set')
418+
->with('cms_block', array_merge($postData, ['block_id' => null]));
419+
420+
$this->resultRedirect->expects($this->atLeastOnce())
421+
->method('setPath')
422+
->with('*/*/edit', ['block_id' => $this->blockId])
423+
->willReturnSelf();
424+
425+
$this->assertSame($this->resultRedirect, $this->saveController->execute());
426+
}
427+
376428
public function testSaveActionThrowsException()
377429
{
378430
$postData = [

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
<settings>
106106
<validation>
107107
<rule name="required-entry" xsi:type="boolean">true</rule>
108+
<rule name="no-marginal-whitespace" xsi:type="boolean">true</rule>
108109
</validation>
109110
<dataType>text</dataType>
110111
<label translate="true">Identifier</label>

app/code/Magento/Config/Model/Config/Structure/Element/Dependency/Field.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
* @api
1010
* @since 100.0.2
1111
*/
12+
13+
/**
14+
* Class Field
15+
*
16+
* Fields are used to describe possible values for a type/interface.
17+
*/
1218
class Field
1319
{
1420
/**
@@ -41,7 +47,7 @@ public function __construct(array $fieldData = [], $fieldPrefix = "")
4147
if (isset($fieldData['separator'])) {
4248
$this->_values = explode($fieldData['separator'], $fieldData['value']);
4349
} else {
44-
$this->_values = [$fieldData['value']];
50+
$this->_values = [isset($fieldData['value']) ? $fieldData['value'] : ''];
4551
}
4652
$fieldId = $fieldPrefix . (isset(
4753
$fieldData['dependPath']

app/code/Magento/Config/Test/Unit/Model/Config/Structure/Element/Dependency/FieldTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class FieldTest extends \PHPUnit\Framework\TestCase
1212
*/
1313
const SIMPLE_VALUE = 'someValue';
1414

15+
const EMPTY_VALUE = '';
16+
1517
const COMPLEX_VALUE1 = 'value_1';
1618

1719
const COMPLEX_VALUE2 = 'value_2';
@@ -150,8 +152,19 @@ public function getValuesDataProvider()
150152
return [
151153
[$this->_getSimpleData(), true, [self::SIMPLE_VALUE]],
152154
[$this->_getSimpleData(), false, [self::SIMPLE_VALUE]],
155+
[$this->_getSimpleEmptyData(), false, [static::EMPTY_VALUE]],
153156
[$this->_getComplexData(), true, $complexDataValues],
154157
[$this->_getComplexData(), false, $complexDataValues]
155158
];
156159
}
160+
161+
/**
162+
* Providing a field data with no field value
163+
*
164+
* @return array
165+
*/
166+
protected function _getSimpleEmptyData(): array
167+
{
168+
return ['dependPath' => ['section_2', 'group_3', 'field_4']];
169+
}
157170
}

app/code/Magento/PageCache/Model/Layout/LayoutPlugin.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
/**
99
* Class LayoutPlugin
10+
*
11+
* Plugin for Magento\Framework\View\Layout
1012
*/
1113
class LayoutPlugin
1214
{
@@ -20,22 +22,31 @@ class LayoutPlugin
2022
*/
2123
protected $response;
2224

25+
/**
26+
* @var \Magento\Framework\App\MaintenanceMode
27+
*/
28+
private $maintenanceMode;
29+
2330
/**
2431
* Constructor
2532
*
2633
* @param \Magento\Framework\App\ResponseInterface $response
27-
* @param \Magento\PageCache\Model\Config $config
34+
* @param \Magento\PageCache\Model\Config $config
35+
* @param \Magento\Framework\App\MaintenanceMode $maintenanceMode
2836
*/
2937
public function __construct(
3038
\Magento\Framework\App\ResponseInterface $response,
31-
\Magento\PageCache\Model\Config $config
39+
\Magento\PageCache\Model\Config $config,
40+
\Magento\Framework\App\MaintenanceMode $maintenanceMode
3241
) {
3342
$this->response = $response;
3443
$this->config = $config;
44+
$this->maintenanceMode = $maintenanceMode;
3545
}
3646

3747
/**
3848
* Set appropriate Cache-Control headers
49+
*
3950
* We have to set public headers in order to tell Varnish and Builtin app that page should be cached
4051
*
4152
* @param \Magento\Framework\View\Layout $subject
@@ -44,7 +55,7 @@ public function __construct(
4455
*/
4556
public function afterGenerateXml(\Magento\Framework\View\Layout $subject, $result)
4657
{
47-
if ($subject->isCacheable() && $this->config->isEnabled()) {
58+
if ($subject->isCacheable() && !$this->maintenanceMode->isOn() && $this->config->isEnabled()) {
4859
$this->response->setPublicHeaders($this->config->getTtl());
4960
}
5061
return $result;
@@ -68,6 +79,7 @@ public function afterGetOutput(\Magento\Framework\View\Layout $subject, $result)
6879
if ($isVarnish && $isEsiBlock) {
6980
continue;
7081
}
82+
// phpcs:ignore
7183
$tags = array_merge($tags, $block->getIdentities());
7284
}
7385
}

0 commit comments

Comments
 (0)