Skip to content

Commit c53d060

Browse files
author
He, Joan(johe)
committed
Merge pull request #340 from magento-extensibility/MAGETWO-47952-functional-test-admin-session
[Extensibility] Bug fix and functional test
2 parents d1847bd + 20a1ccc commit c53d060

File tree

16 files changed

+656
-383
lines changed

16 files changed

+656
-383
lines changed

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)