Skip to content

Commit 05e63b2

Browse files
committed
Merge branch 'develop' of github.corp.magento.com:magento2/magento2ce into MAGETWO-48544
2 parents 76fc4da + c53d060 commit 05e63b2

File tree

83 files changed

+3964
-544
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+3964
-544
lines changed

app/code/Magento/Backend/Model/Locale/Manager.php

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,30 @@ class Manager
2626
* @var \Magento\Framework\TranslateInterface
2727
*/
2828
protected $_translator;
29+
30+
/**
31+
* @var \Magento\Backend\App\ConfigInterface
32+
*/
33+
protected $_backendConfig;
2934

3035
/**
3136
* Constructor
3237
*
3338
* @param \Magento\Backend\Model\Session $session
3439
* @param \Magento\Backend\Model\Auth\Session $authSession
3540
* @param \Magento\Framework\TranslateInterface $translator
41+
* @param \Magento\Backend\App\ConfigInterface $backendConfig
3642
*/
3743
public function __construct(
3844
\Magento\Backend\Model\Session $session,
3945
\Magento\Backend\Model\Auth\Session $authSession,
40-
\Magento\Framework\TranslateInterface $translator
46+
\Magento\Framework\TranslateInterface $translator,
47+
\Magento\Backend\App\ConfigInterface $backendConfig
4148
) {
4249
$this->_session = $session;
4350
$this->_authSession = $authSession;
4451
$this->_translator = $translator;
52+
$this->_backendConfig = $backendConfig;
4553
}
4654

4755
/**
@@ -53,28 +61,40 @@ public function __construct(
5361
public function switchBackendInterfaceLocale($localeCode)
5462
{
5563
$this->_session->setSessionLocale(null);
56-
64+
5765
$this->_authSession->getUser()->setInterfaceLocale($localeCode);
58-
66+
5967
$this->_translator->setLocale($localeCode)->loadData(null, true);
60-
68+
6169
return $this;
6270
}
6371

72+
/**
73+
* Get general interface locale
74+
*
75+
* @return string
76+
*/
77+
public function getGeneralLocale()
78+
{
79+
return $this->_backendConfig->getValue('general/locale/code');
80+
}
81+
6482
/**
6583
* Get user interface locale stored in session data
6684
*
6785
* @return string
6886
*/
6987
public function getUserInterfaceLocale()
7088
{
71-
$interfaceLocale = \Magento\Framework\Locale\Resolver::DEFAULT_LOCALE;
72-
7389
$userData = $this->_authSession->getUser();
90+
$interfaceLocale = \Magento\Framework\Locale\Resolver::DEFAULT_LOCALE;
91+
7492
if ($userData && $userData->getInterfaceLocale()) {
7593
$interfaceLocale = $userData->getInterfaceLocale();
94+
} elseif ($this->getGeneralLocale()) {
95+
$interfaceLocale = $this->getGeneralLocale();
7696
}
77-
97+
7898
return $interfaceLocale;
7999
}
80100
}

app/code/Magento/Backend/Test/Unit/Model/Locale/ManagerTest.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ManagerTest extends \PHPUnit_Framework_TestCase
1515
protected $_model;
1616

1717
/**
18-
* @var \Magento\Framework\TranslateInterface
18+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\TranslateInterface
1919
*/
2020
protected $_translator;
2121

@@ -25,9 +25,14 @@ class ManagerTest extends \PHPUnit_Framework_TestCase
2525
protected $_session;
2626

2727
/**
28-
* @var \Magento\Backend\Model\Auth\Session
28+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Backend\Model\Auth\Session
2929
*/
3030
protected $_authSession;
31+
32+
/**
33+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Backend\App\ConfigInterface
34+
*/
35+
protected $_backendConfig;
3136

3237
protected function setUp()
3338
{
@@ -40,7 +45,9 @@ protected function setUp()
4045
'',
4146
false
4247
);
43-
48+
49+
$this->_backendConfig = $this->getMockForAbstractClass('Magento\Backend\App\ConfigInterface', [], '', false);
50+
4451
$userMock = new \Magento\Framework\DataObject();
4552

4653
$this->_authSession->expects($this->any())->method('getUser')->will($this->returnValue($userMock));
@@ -54,7 +61,8 @@ protected function setUp()
5461
$this->_model = new \Magento\Backend\Model\Locale\Manager(
5562
$this->_session,
5663
$this->_authSession,
57-
$this->_translator
64+
$this->_translator,
65+
$this->_backendConfig
5866
);
5967
}
6068

@@ -102,4 +110,17 @@ public function testGetUserInterfaceLocale()
102110

103111
$this->assertEquals($locale, 'de_DE');
104112
}
113+
114+
/**
115+
* @covers \Magento\Backend\Model\Locale\Manager::getUserInterfaceLocale
116+
*/
117+
public function testGetUserInterfaceGeneralLocale()
118+
{
119+
$this->_backendConfig->expects($this->any())
120+
->method('getValue')
121+
->with('general/locale/code')
122+
->willReturn('test_locale');
123+
$locale = $this->_model->getUserInterfaceLocale();
124+
$this->assertEquals($locale, 'test_locale');
125+
}
105126
}

app/code/Magento/Cms/etc/webapi.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<route url="/V1/cmsPage/:pageId" method="GET">
1212
<service class="Magento\Cms\Api\PageRepositoryInterface" method="getById"/>
1313
<resources>
14-
<resource ref="Magento_Cms::page"/>
14+
<resource ref="anonymous"/>
1515
</resources>
1616
</route>
1717
<route url="/V1/cmsPage/search" method="GET">
@@ -42,7 +42,7 @@
4242
<route url="/V1/cmsBlock/:blockId" method="GET">
4343
<service class="Magento\Cms\Api\BlockRepositoryInterface" method="getById"/>
4444
<resources>
45-
<resource ref="Magento_Cms::block"/>
45+
<resource ref="anonymous"/>
4646
</resources>
4747
</route>
4848
<route url="/V1/cmsBlock/search" method="GET">

app/code/Magento/Config/Controller/Adminhtml/System/AbstractConfig.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ protected function _isAllowed()
7272
*/
7373
protected function _saveState($configState = [])
7474
{
75-
$adminUser = $this->_auth->getUser();
7675
if (is_array($configState)) {
76+
$configState = $this->sanitizeConfigState($configState);
77+
$adminUser = $this->_auth->getUser();
7778
$extra = $adminUser->getExtra();
7879
if (!is_array($extra)) {
7980
$extra = [];
@@ -88,4 +89,25 @@ protected function _saveState($configState = [])
8889
}
8990
return true;
9091
}
92+
93+
/**
94+
* Sanitize config state data
95+
*
96+
* @param array $configState
97+
* @return array
98+
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
99+
*/
100+
protected function sanitizeConfigState($configState)
101+
{
102+
$sectionList = $this->_configStructure->getSectionList();
103+
$sanitizedConfigState = $configState;
104+
foreach ($configState as $sectionId => $value) {
105+
if (array_key_exists($sectionId, $sectionList)) {
106+
$sanitizedConfigState[$sectionId] = (bool)$sanitizedConfigState[$sectionId] ? '1' : '0';
107+
} else {
108+
unset($sanitizedConfigState[$sectionId]);
109+
}
110+
}
111+
return $sanitizedConfigState;
112+
}
91113
}

app/code/Magento/Config/Model/Config/Structure.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ class Structure implements \Magento\Config\Model\Config\Structure\SearchInterfac
5151
*/
5252
protected $_elements;
5353

54+
/**
55+
* List of config sections
56+
*
57+
* @var array
58+
*/
59+
protected $sectionList;
60+
5461
/**
5562
* @param \Magento\Config\Model\Config\Structure\Data $structureData
5663
* @param \Magento\Config\Model\Config\Structure\Element\Iterator\Tab $tabIterator
@@ -87,6 +94,26 @@ public function getTabs()
8794
return $this->_tabIterator;
8895
}
8996

97+
/**
98+
* Retrieve config section list
99+
*
100+
* @return array
101+
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
102+
*/
103+
public function getSectionList()
104+
{
105+
if (empty($this->sectionList)) {
106+
foreach ($this->_data['sections'] as $sectionId => $section) {
107+
if (array_key_exists('children', $section) && is_array($section['children'])) {
108+
foreach ($section['children'] as $childId => $child) {
109+
$this->sectionList[$sectionId . '_' . $childId] = true;
110+
}
111+
}
112+
}
113+
}
114+
return $this->sectionList;
115+
}
116+
90117
/**
91118
* Find element by path
92119
*

app/code/Magento/Config/Test/Unit/Controller/Adminhtml/System/Config/SaveTest.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ protected function setUp()
124124
$this->_cacheMock = $this->getMock('Magento\Framework\App\Cache\Type\Layout', [], [], '', false);
125125

126126
$configStructureMock->expects($this->any())->method('getElement')->willReturn($this->_sectionMock);
127+
$configStructureMock->expects($this->any())->method('getSectionList')->willReturn(
128+
[
129+
'some_key_0' => '0',
130+
'some_key_1' => '1'
131+
]
132+
);
127133

128134
$helperMock->expects($this->any())->method('getUrl')->willReturnArgument(0);
129135

@@ -219,21 +225,29 @@ public function testIndexActionWithAllowedSection()
219225
public function testIndexActionSaveState()
220226
{
221227
$this->_sectionCheckerMock->expects($this->any())->method('isSectionAllowed')->will($this->returnValue(false));
222-
$data = ['some_key' => 'some_value'];
228+
$inputData = [
229+
'some_key' => 'some_value',
230+
'some_key_0' => '0',
231+
'some_key_1' => 'some_value_1',
232+
];
233+
$extraData = [
234+
'some_key_0' => '0',
235+
'some_key_1' => '1',
236+
];
223237

224238
$userMock = $this->getMock('Magento\User\Model\User', [], [], '', false, false);
225-
$userMock->expects($this->once())->method('saveExtra')->with(['configState' => $data]);
239+
$userMock->expects($this->once())->method('saveExtra')->with(['configState' => $extraData]);
226240
$this->_authMock->expects($this->once())->method('getUser')->will($this->returnValue($userMock));
227-
228241
$this->_requestMock->expects(
229242
$this->any()
230243
)->method(
231244
'getPost'
232245
)->with(
233246
'config_state'
234247
)->will(
235-
$this->returnValue($data)
248+
$this->returnValue($inputData)
236249
);
250+
237251
$this->assertEquals($this->resultRedirect, $this->_controller->execute());
238252
}
239253

app/code/Magento/Config/Test/Unit/Model/Config/StructureTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,55 @@ public function testGetTabsBuildsSectionTree()
128128
$this->assertEquals($this->_tabIteratorMock, $model->getTabs());
129129
}
130130

131+
public function testGetSectionList()
132+
{
133+
$this->_structureDataMock = $this->getMock(
134+
'Magento\Config\Model\Config\Structure\Data',
135+
[],
136+
[],
137+
'',
138+
false
139+
);
140+
$this->_structureDataMock->expects(
141+
$this->any()
142+
)->method(
143+
'get'
144+
)->will(
145+
$this->returnValue(
146+
[
147+
'sections' => [
148+
'section1' => [
149+
'children' => [
150+
'child_id_1' => 'child_data',
151+
'child_id_2' => 'child_data',
152+
'child_id_3' => 'child_data'
153+
]
154+
],
155+
'section2' => [
156+
'children' => [
157+
'child_id_1' => 'child_data'
158+
]
159+
],
160+
]
161+
]
162+
)
163+
);
164+
$expected = [
165+
'section1_child_id_1' => true,
166+
'section1_child_id_2' => true,
167+
'section1_child_id_3' => true,
168+
'section2_child_id_1' => true
169+
];
170+
$model = new \Magento\Config\Model\Config\Structure(
171+
$this->_structureDataMock,
172+
$this->_tabIteratorMock,
173+
$this->_flyweightFactory,
174+
$this->_scopeDefinerMock
175+
);
176+
177+
$this->assertEquals($expected, $model->getSectionList());
178+
}
179+
131180
/**
132181
* @param string $path
133182
* @param string $expectedType

app/code/Magento/Paypal/Model/Api/Nvp.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,7 @@ public function call($methodName, array $request)
12261226
$http->close();
12271227

12281228
if (!$this->_validateResponse($methodName, $response)) {
1229-
$this->_logger->critical(new \Exception(__("PayPal response hasn't required fields.")));
1229+
$this->_logger->critical(new \Exception(__('PayPal response hasn\'t required fields.')));
12301230
throw new \Magento\Framework\Exception\LocalizedException(
12311231
__('Something went wrong while processing your order.')
12321232
);

app/code/Magento/Paypal/Model/Payflow/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function __call($method, $args)
5353
return isset($this->_data[$key]);
5454
}
5555
throw new \Magento\Framework\Exception\LocalizedException(
56-
__("Invalid method %1::%2(%3)", get_class($this), $method, print_r($args, 1))
56+
__("Invalid method %1::%2", get_class($this), $method)
5757
);
5858
}
5959
}

0 commit comments

Comments
 (0)