Skip to content

Commit 4d5990a

Browse files
author
Korshenko, Olexii(okorshenko)
committed
Merge pull request #713 from magento-api/API-M11-Bug-Fixes
[API] M11 Bug Fixes
2 parents e49166d + 1be6dda commit 4d5990a

File tree

14 files changed

+239
-156
lines changed

14 files changed

+239
-156
lines changed

app/code/Magento/Email/Model/Template/Filter.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@ public function setUseAbsoluteLinks($flag)
214214

215215
/**
216216
* Setter whether SID is allowed in store directive
217-
* Doesn't set anything intentionally, since SID is not allowed in any kind of emails
218217
*
219218
* @param bool $flag
220219
* @return $this

dev/tests/static/testsuite/Magento/Test/Integrity/Phrase/AbstractTestCase.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ protected function _createPhraseError($phrase)
2222
return "\nPhrase: {$phrase['phrase']} \nFile: {$phrase['file']} \nLine: {$phrase['line']}";
2323
}
2424

25+
/**
26+
* @param array $phrase
27+
* @return string
28+
*/
29+
protected function _createMissedPhraseError($phrase)
30+
{
31+
return "\nMissed Phrase: File: {$phrase['file']} \nLine: {$phrase['line']}";
32+
}
33+
2534
/**
2635
* @return \RegexIterator
2736
*/

dev/tests/static/testsuite/Magento/Test/Integrity/Phrase/ArgumentsTest.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,39 @@ protected function setUp()
4444

4545
public function testArguments()
4646
{
47-
$errors = [];
47+
$incorrectNumberOfArgumentsErrors = [];
48+
$missedPhraseErrors = [];
4849
foreach ($this->_getFiles() as $file) {
4950
if (in_array($file, $this->blackList)) {
5051
continue;
5152
}
5253
$this->_phraseCollector->parse($file);
5354
foreach ($this->_phraseCollector->getPhrases() as $phrase) {
55+
if (empty(trim($phrase['phrase'], "'\"\t\n\r\0\x0B"))) {
56+
$missedPhraseErrors[] = $this->_createMissedPhraseError($phrase);
57+
}
5458
if (preg_match_all('/%(\d+)/', $phrase['phrase'], $matches) || $phrase['arguments']) {
5559
$placeholdersInPhrase = array_unique($matches[1]);
5660
if (count($placeholdersInPhrase) != $phrase['arguments']) {
57-
$errors[] = $this->_createPhraseError($phrase);
61+
$incorrectNumberOfArgumentsErrors[] = $this->_createPhraseError($phrase);
5862
}
5963
}
6064
}
6165
}
6266
$this->assertEmpty(
63-
$errors,
67+
$missedPhraseErrors,
68+
sprintf(
69+
"\n%d missed phrases were discovered: \n%s",
70+
count($missedPhraseErrors),
71+
implode("\n\n", $missedPhraseErrors)
72+
)
73+
);
74+
$this->assertEmpty(
75+
$incorrectNumberOfArgumentsErrors,
6476
sprintf(
6577
"\n%d usages of inconsistency the number of arguments and placeholders were discovered: \n%s",
66-
count($errors),
67-
implode("\n\n", $errors)
78+
count($incorrectNumberOfArgumentsErrors),
79+
implode("\n\n", $incorrectNumberOfArgumentsErrors)
6880
)
6981
);
7082
}

lib/internal/Magento/Framework/Backup/Filesystem/Rollback/Fs.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function run()
5454
new \Magento\Framework\Archive\Gz();
5555
new \Magento\Framework\Archive\Helper\File('');
5656
new \Magento\Framework\Archive\Helper\File\Gz('');
57-
new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase(''));
57+
new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase('dummy'));
5858

5959
$fsHelper->rm($this->_snapshot->getRootDir(), $this->_snapshot->getIgnorePaths());
6060
$archiver->unpack($snapshotPath, $this->_snapshot->getRootDir());

lib/internal/Magento/Framework/HTTP/Client.php

Lines changed: 0 additions & 58 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\HTTP;
8+
9+
/**
10+
* Factory for HTTP client classes
11+
*
12+
* @author Magento Core Team <core@magentocommerce.com>
13+
*/
14+
class ClientFactory
15+
{
16+
/**
17+
* Object Manager instance
18+
*
19+
* @var \Magento\Framework\ObjectManagerInterface
20+
*/
21+
protected $_objectManager = null;
22+
23+
/**
24+
* Instance name to create
25+
*
26+
* @var string
27+
*/
28+
protected $_instanceName = null;
29+
30+
/**
31+
* Factory constructor (default creates Curl client)
32+
*
33+
* @param \Magento\Framework\ObjectManagerInterface $objectManager
34+
* @param string $instanceName
35+
*/
36+
public function __construct(
37+
\Magento\Framework\ObjectManagerInterface $objectManager,
38+
$instanceName = 'Magento\Framework\HTTP\Client\Curl'
39+
) {
40+
$this->_objectManager = $objectManager;
41+
$this->_instanceName = $instanceName;
42+
}
43+
44+
/**
45+
* Create class instance with specified parameters
46+
*
47+
* @param array $data
48+
* @return \Magento\Framework\Flag
49+
*/
50+
public function create(array $data = [])
51+
{
52+
return $this->_objectManager->create($this->_instanceName, $data);
53+
}
54+
}

lib/internal/Magento/Framework/Test/Unit/TranslateTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,15 @@ public function setUp()
6868
$this->resource = $this->getMock('\Magento\Framework\Translate\ResourceInterface', [], [], '', false);
6969
$this->locale = $this->getMock('\Magento\Framework\Locale\ResolverInterface', [], [], '', false);
7070
$this->appState = $this->getMock('\Magento\Framework\App\State', [], [], '', false);
71-
$this->request = $this->getMock('\Magento\Framework\App\RequestInterface', [], [], '', false);
71+
$this->request = $this->getMockForAbstractClass(
72+
'\Magento\Framework\App\RequestInterface',
73+
[],
74+
'',
75+
false,
76+
false,
77+
true,
78+
['getParam', 'getControllerModule']
79+
);
7280
$this->csvParser = $this->getMock('\Magento\Framework\File\Csv', [], [], '', false);
7381
$this->packDictionary = $this->getMock('\Magento\Framework\App\Language\Dictionary', [], [], '', false);
7482
$this->directory = $this->getMock('\Magento\Framework\Filesystem\Directory\ReadInterface', [], [], '', false);

lib/internal/Magento/Framework/Translate.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ protected function setConfig($config)
204204
if (!isset($this->_config['theme'])) {
205205
$this->_config['theme'] = $this->_viewDesign->getDesignTheme()->getId();
206206
}
207+
if (!isset($this->_config['module'])) {
208+
$this->_config['module'] = $this->getControllerModuleName();
209+
}
207210
return $this;
208211
}
209212

@@ -232,14 +235,39 @@ protected function getConfig($key)
232235
return null;
233236
}
234237

238+
/**
239+
* Retrieve name of the current module
240+
* @return mixed
241+
*/
242+
protected function getControllerModuleName()
243+
{
244+
return $this->request->getControllerModule();
245+
}
246+
235247
/**
236248
* Load data from module translation files
237249
*
238250
* @return $this
239251
*/
240252
protected function _loadModuleTranslation()
241253
{
242-
foreach ($this->_moduleList->getNames() as $module) {
254+
$currentModule = $this->getControllerModuleName();
255+
$allModulesExceptCurrent = array_diff($this->_moduleList->getNames(), [$currentModule]);
256+
257+
$this->loadModuleTranslationByModulesList($allModulesExceptCurrent);
258+
$this->loadModuleTranslationByModulesList([$currentModule]);
259+
return $this;
260+
}
261+
262+
/**
263+
* Load data from module translation files by list of modules
264+
*
265+
* @param array $modules
266+
* @return $this
267+
*/
268+
protected function loadModuleTranslationByModulesList(array $modules)
269+
{
270+
foreach ($modules as $module) {
243271
$moduleFilePath = $this->_getModuleTranslationFile($module, $this->getLocale());
244272
$this->_addData($this->_getFileData($moduleFilePath));
245273
}
@@ -428,6 +456,9 @@ protected function getCacheId($forceReload = false)
428456
if (isset($this->_config['theme'])) {
429457
$this->_cacheId .= '_' . $this->_config['theme'];
430458
}
459+
if (isset($this->_config['module'])) {
460+
$this->_cacheId .= '_' . $this->_config['module'];
461+
}
431462
}
432463
return $this->_cacheId;
433464
}

setup/src/Magento/Setup/Module/I18n/Dictionary/Phrase.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,4 +237,41 @@ public function getKey()
237237
{
238238
return $this->getPhrase() . '::' . $this->getContextType();
239239
}
240+
241+
/**
242+
* Compile PHP string based on quotes type it enclosed with
243+
*
244+
* @return string
245+
*/
246+
public function getCompiledPhrase()
247+
{
248+
return $this->getCompiledString($this->getPhrase());
249+
}
250+
251+
/**
252+
* Compile PHP string based on quotes type it enclosed with
253+
*
254+
* @return string
255+
*/
256+
public function getCompiledTranslation()
257+
{
258+
return $this->getCompiledString($this->getTranslation());
259+
}
260+
261+
/**
262+
* Compile PHP string based on quotes type it enclosed with
263+
*
264+
* @param string $string
265+
* @return string
266+
*
267+
* @SuppressWarnings(PHPMD.EvalExpression)
268+
*/
269+
private function getCompiledString($string)
270+
{
271+
$encloseQuote = $this->getQuote() == Phrase::QUOTE_DOUBLE ? Phrase::QUOTE_DOUBLE : Phrase::QUOTE_SINGLE;
272+
273+
$evalString = 'return ' . $encloseQuote . $string . $encloseQuote . ';';
274+
$result = @eval($evalString);
275+
return is_string($result) ? $result : $string;
276+
}
240277
}

setup/src/Magento/Setup/Module/I18n/Dictionary/Writer/Csv.php

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ public function __construct($outputFilename)
4141
*/
4242
public function write(Phrase $phrase)
4343
{
44-
$fields = [$phrase->getPhrase(), $phrase->getTranslation()];
45-
$encloseQuote = $phrase->getQuote() == Phrase::QUOTE_DOUBLE ? Phrase::QUOTE_DOUBLE : Phrase::QUOTE_SINGLE;
46-
$fields[0] = $this->compileString($fields[0], $encloseQuote);
47-
$fields[1] = $this->compileString($fields[1], $encloseQuote);
44+
$fields = [$phrase->getCompiledPhrase(), $phrase->getCompiledTranslation()];
4845
if (($contextType = $phrase->getContextType()) && ($contextValue = $phrase->getContextValueAsString())) {
4946
$fields[] = $contextType;
5047
$fields[] = $contextValue;
@@ -53,22 +50,6 @@ public function write(Phrase $phrase)
5350
fputcsv($this->_fileHandler, $fields, ',', '"');
5451
}
5552

56-
/**
57-
* Compile PHP string based on quotes type it enclosed with
58-
*
59-
* @param string $string
60-
* @param string $encloseQuote
61-
* @return string
62-
*
63-
* @SuppressWarnings(PHPMD.EvalExpression)
64-
*/
65-
protected function compileString($string, $encloseQuote)
66-
{
67-
$evalString = 'return ' . $encloseQuote . $string . $encloseQuote . ';';
68-
$result = @eval($evalString);
69-
return is_string($result) ? $result : $string;
70-
}
71-
7253
/**
7354
* Close file handler
7455
*

0 commit comments

Comments
 (0)