Skip to content

Commit 63bf941

Browse files
author
Sergii Kovalenko
committed
Merge branch '2.3-develop' of https://github.com/magento/magento2ce into MAGETWO-88054
2 parents 23ef24c + 8478bdb commit 63bf941

File tree

8 files changed

+70
-24
lines changed

8 files changed

+70
-24
lines changed

app/code/Magento/Config/App/Config/Type/System.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public function get($path = '')
141141
$pathParts = explode('/', $path);
142142
if (count($pathParts) === 1 && $pathParts[0] !== 'default') {
143143
if (!isset($this->data[$pathParts[0]])) {
144-
$data = $this->reader->read();
144+
$data = $this->readData();
145145
$this->data = array_replace_recursive($data, $this->data);
146146
}
147147
return $this->data[$pathParts[0]];
@@ -171,7 +171,7 @@ private function loadAllData()
171171
{
172172
$cachedData = $this->cache->load($this->configType);
173173
if ($cachedData === false) {
174-
$data = $this->reader->read();
174+
$data = $this->readData();
175175
} else {
176176
$data = $this->serializer->unserialize($cachedData);
177177
}
@@ -188,7 +188,7 @@ private function loadDefaultScopeData($scopeType)
188188
{
189189
$cachedData = $this->cache->load($this->configType . '_' . $scopeType);
190190
if ($cachedData === false) {
191-
$data = $this->reader->read();
191+
$data = $this->readData();
192192
$this->cacheData($data);
193193
} else {
194194
$data = [$scopeType => $this->serializer->unserialize($cachedData)];
@@ -216,7 +216,7 @@ private function loadScopeData($scopeType, $scopeId)
216216
if (is_array($this->availableDataScopes) && !isset($this->availableDataScopes[$scopeType][$scopeId])) {
217217
return [$scopeType => [$scopeId => []]];
218218
}
219-
$data = $this->reader->read();
219+
$data = $this->readData();
220220
$this->cacheData($data);
221221
} else {
222222
$data = [$scopeType => [$scopeId => $this->serializer->unserialize($cachedData)]];
@@ -282,6 +282,21 @@ private function getDataByPathParts($data, $pathParts)
282282
return $data;
283283
}
284284

285+
/**
286+
* The freshly read data.
287+
*
288+
* @return array
289+
*/
290+
private function readData(): array
291+
{
292+
$this->data = $this->reader->read();
293+
$this->data = $this->postProcessor->process(
294+
$this->data
295+
);
296+
297+
return $this->data;
298+
}
299+
285300
/**
286301
* Clean cache and global variables cache
287302
*

app/code/Magento/Config/App/Config/Type/System/Reader.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,13 @@ class Reader
2727
*/
2828
private $preProcessor;
2929

30-
/**
31-
* @var \Magento\Framework\App\Config\Spi\PostProcessorInterface
32-
*/
33-
private $postProcessor;
34-
3530
/**
3631
* Reader constructor.
3732
* @param \Magento\Framework\App\Config\ConfigSourceInterface $source
3833
* @param \Magento\Store\Model\Config\Processor\Fallback $fallback
3934
* @param \Magento\Framework\App\Config\Spi\PreProcessorInterface $preProcessor
4035
* @param \Magento\Framework\App\Config\Spi\PostProcessorInterface $postProcessor
36+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
4137
*/
4238
public function __construct(
4339
\Magento\Framework\App\Config\ConfigSourceInterface $source,
@@ -48,7 +44,6 @@ public function __construct(
4844
$this->source = $source;
4945
$this->fallback = $fallback;
5046
$this->preProcessor = $preProcessor;
51-
$this->postProcessor = $postProcessor;
5247
}
5348

5449
/**
@@ -60,11 +55,9 @@ public function __construct(
6055
*/
6156
public function read()
6257
{
63-
return $this->postProcessor->process(
64-
$this->fallback->process(
65-
$this->preProcessor->process(
66-
$this->source->get()
67-
)
58+
return $this->fallback->process(
59+
$this->preProcessor->process(
60+
$this->source->get()
6861
)
6962
);
7063
}

app/code/Magento/Config/Test/Unit/App/Config/Type/System/ReaderTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ public function testGetCachedWithLoadDefaultScopeData()
8484
->method('process')
8585
->with($data)
8686
->willReturn($data);
87-
$this->postProcessor->expects($this->once())
88-
->method('process')
89-
->with($data)
90-
->willReturn($data);
9187
$this->assertEquals($data, $this->model->read());
9288
}
9389
}

app/code/Magento/Config/Test/Unit/App/Config/Type/SystemTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,12 @@ public function testGetNotCached()
170170
$this->reader->expects($this->once())
171171
->method('read')
172172
->willReturn($data);
173+
$this->postProcessor->expects($this->once())
174+
->method('process')
175+
->with($data)
176+
->willReturn($data);
173177

174178
$this->assertEquals($url, $this->configType->get($path));
179+
$this->assertEquals($url, $this->configType->get($path));
175180
}
176181
}

app/code/Magento/Store/Model/Config/Placeholder.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ protected function _processPlaceholders($value, $data)
9191
if ($url) {
9292
$value = str_replace('{{' . $placeholder . '}}', $url, $value);
9393
} elseif (strpos($value, $this->urlPlaceholder) !== false) {
94-
// localhost is replaced for cli requests, for http requests method getDistroBaseUrl is used
95-
$value = str_replace($this->urlPlaceholder, 'http://localhost/', $value);
94+
$distroBaseUrl = $this->request->getDistroBaseUrl();
95+
96+
$value = str_replace($this->urlPlaceholder, $distroBaseUrl, $value);
9697
}
9798

9899
if (null !== $this->_getPlaceholder($value)) {

app/code/Magento/Store/Test/Unit/Model/Config/PlaceholderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ protected function setUp()
2323
{
2424
$this->_requestMock = $this->createMock(\Magento\Framework\App\Request\Http::class);
2525
$this->_requestMock->expects(
26-
$this->any()
26+
$this->once()
2727
)->method(
2828
'getDistroBaseUrl'
2929
)->will(

app/code/Magento/Translation/Model/Js/DataProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function getData($themePath)
113113
}
114114
} catch (\Exception $e) {
115115
throw new LocalizedException(
116-
sprintf(__('Error while translating phrase "%s" in file %s.'), $phrase, $filePath[0])
116+
__('Error while translating phrase "%s" in file %s.', $phrase, $filePath[0])
117117
);
118118
}
119119
}
@@ -145,7 +145,7 @@ protected function getPhrases($content)
145145
}
146146
if (false === $result) {
147147
throw new LocalizedException(
148-
sprintf(__('Error while generating js translation dictionary: "%s"'), error_get_last())
148+
__('Error while generating js translation dictionary: "%s"', error_get_last())
149149
);
150150
}
151151
}

app/code/Magento/Translation/Test/Unit/Model/Js/DataProviderTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Translation\Test\Unit\Model\Js;
78

89
use Magento\Framework\App\State;
@@ -148,4 +149,39 @@ public function testGetData()
148149

149150
$this->assertEquals($expectedResult, $this->model->getData($themePath));
150151
}
152+
153+
/**
154+
* @expectedException \Magento\Framework\Exception\LocalizedException
155+
*/
156+
public function testGetDataThrowingException()
157+
{
158+
$themePath = 'blank';
159+
$areaCode = 'adminhtml';
160+
161+
$patterns = ['~\$\.mage\.__\(([\'"])(.+?)\1\)~'];
162+
163+
$this->fileReadMock->expects($this->once())
164+
->method('readAll')
165+
->willReturn('content1$.mage.__("hello1")content1');
166+
167+
$this->appStateMock->expects($this->once())
168+
->method('getAreaCode')
169+
->willReturn($areaCode);
170+
$this->filesUtilityMock->expects($this->any())
171+
->method('getJsFiles')
172+
->willReturn(['test']);
173+
$this->filesUtilityMock->expects($this->any())
174+
->method('getStaticHtmlFiles')
175+
->willReturn(['test']);
176+
177+
$this->configMock->expects($this->any())
178+
->method('getPatterns')
179+
->willReturn($patterns);
180+
181+
$this->translateMock->expects($this->once())
182+
->method('render')
183+
->willThrowException(new \Exception('Test exception'));
184+
185+
$this->model->getData($themePath);
186+
}
151187
}

0 commit comments

Comments
 (0)