Skip to content

Commit 981d1f4

Browse files
author
Oleksii Korshenko
committed
Merge remote-tracking branch 'mainline/develop' into for-pr
2 parents 61da4e6 + 89e16e7 commit 981d1f4

File tree

8 files changed

+140
-18
lines changed

8 files changed

+140
-18
lines changed

app/code/Magento/Directory/Model/Currency.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ public function getOutputFormat()
330330
{
331331
$formatted = $this->formatTxt(0);
332332
$number = $this->formatTxt(0, ['display' => \Magento\Framework\Currency::NO_SYMBOL]);
333-
return str_replace($number, '%s', $formatted);
333+
return str_replace($this->trimUnicodeDirectionMark($number), '%s', $formatted);
334334
}
335335

336336
/**
@@ -402,4 +402,18 @@ public function saveRates($rates)
402402
$this->_getResource()->saveRates($rates);
403403
return $this;
404404
}
405+
406+
/**
407+
* This method removes LRM and RLM marks from string
408+
*
409+
* @param string $string
410+
* @return $this
411+
*/
412+
private function trimUnicodeDirectionMark($string)
413+
{
414+
if (preg_match('/^(\x{200E}|\x{200F})/u', $string, $match)) {
415+
$string = preg_replace('/^'.$match[1].'/u', '', $string);
416+
}
417+
return $string;
418+
}
405419
}

app/code/Magento/Directory/Test/Unit/Model/CurrencyTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,49 @@ public function testGetCurrencySymbol()
5252
->willReturn($currencyMock);
5353
$this->assertEquals($currencySymbol, $this->currency->getCurrencySymbol());
5454
}
55+
56+
/**
57+
* @dataProvider getOutputFormatDataProvider
58+
* @param $withCurrency
59+
* @param $noCurrency
60+
* @param $expected
61+
*/
62+
public function testGetOutputFormat($withCurrency, $noCurrency, $expected)
63+
{
64+
$currencyMock = $this->getMockBuilder('\Magento\Framework\Currency')
65+
->disableOriginalConstructor()
66+
->getMock();
67+
$currencyMock->expects($this->at(0))
68+
->method('toCurrency')
69+
->willReturn($withCurrency);
70+
$currencyMock->expects($this->at(1))
71+
->method('toCurrency')
72+
->willReturn($noCurrency);
73+
$this->localeCurrencyMock->expects($this->atLeastOnce())
74+
->method('getCurrency')
75+
->with($this->currencyCode)
76+
->willReturn($currencyMock);
77+
$this->assertEquals($expected, $this->currency->getOutputFormat());
78+
}
79+
80+
/**
81+
* Return data sets for testGetCurrencySymbol()
82+
*
83+
* @return array
84+
*/
85+
public function getOutputFormatDataProvider()
86+
{
87+
return [
88+
'no_unicode' => [
89+
'withCurrency' => '$0.00',
90+
'noCurrency' => '0.00',
91+
'expected' => '$%s',
92+
],
93+
'arabic_unicode' => [
94+
'withCurrency' => json_decode('"\u200E"') . '$0.00',
95+
'noCurrency' => json_decode('"\u200E"') . '0.00',
96+
'expected' => json_decode('"\u200E"') . '$%s',
97+
]
98+
];
99+
}
55100
}

app/code/Magento/Rule/Block/Editable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele
5454
'" value="' .
5555
$element->getValue() .
5656
'" data-form-part="' .
57-
$element->getDataFormPart() .
57+
$element->getData('data-form-part') .
5858
'"/> ' .
5959
htmlspecialchars(
6060
$valueName

app/code/Magento/Rule/Model/Condition/AbstractCondition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ public function getAttributeElement()
531531
'values' => $this->getAttributeSelectOptions(),
532532
'value' => $this->getAttribute(),
533533
'value_name' => $this->getAttributeName(),
534-
'data_form_part' => $this->getFormName()
534+
'data-form-part' => $this->getFormName()
535535
]
536536
)->setRenderer(
537537
$this->_layout->getBlockSingleton('Magento\Rule\Block\Editable')

dev/tests/integration/testsuite/Magento/Framework/Search/Adapter/Mysql/AdapterTest.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ class AdapterTest extends \PHPUnit_Framework_TestCase
3333
*/
3434
protected $objectManager;
3535

36-
/**
37-
* @var string
38-
*/
39-
protected $requestConfig = __DIR__ . '/../../_files/requests.xml';
40-
4136
/**
4237
* @var string
4338
*/
@@ -51,7 +46,7 @@ protected function setUp()
5146
$converter = $this->objectManager->create('Magento\Framework\Search\Request\Config\Converter');
5247

5348
$document = new \DOMDocument();
54-
$document->load($this->requestConfig);
49+
$document->load($this->getRequestConfigPath());
5550
$requestConfig = $converter->convert($document);
5651

5752
/** @var \Magento\Framework\Search\Request\Config $config */
@@ -66,6 +61,16 @@ protected function setUp()
6661
$this->adapter = $this->createAdapter();
6762
}
6863

64+
/**
65+
* Get request config path
66+
*
67+
* @return string
68+
*/
69+
protected function getRequestConfigPath()
70+
{
71+
return __DIR__ . '/../../_files/requests.xml';
72+
}
73+
6974
/**
7075
* Make sure that correct engine is set
7176
*/

lib/internal/Magento/Framework/Locale/Format.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99

1010
class Format implements \Magento\Framework\Locale\FormatInterface
1111
{
12+
/**
13+
* @var string
14+
*/
15+
private static $defaultNumberSet = 'latn';
16+
1217
/**
1318
* @var \Magento\Framework\App\ScopeResolverInterface
1419
*/
@@ -104,12 +109,18 @@ public function getPriceFormat($localeCode = null, $currencyCode = null)
104109
$currency = $this->_scopeResolver->getScope()->getCurrentCurrency();
105110
}
106111
$localeData = (new DataBundle())->get($localeCode);
107-
$format = $localeData['NumberElements']['latn']['patterns']['currencyFormat']
108-
?: explode(';', $localeData['NumberPatterns'][1])[0];
109-
$decimalSymbol = $localeData['NumberElements']['latn']['symbols']['decimal']
110-
?: $localeData['NumberElements'][0];
111-
$groupSymbol = $localeData['NumberElements']['latn']['symbols']['group']
112-
?: $localeData['NumberElements'][1];
112+
$defaultSet = $localeData['NumberElements']['default'] ?: self::$defaultNumberSet;
113+
$format = $localeData['NumberElements'][$defaultSet]['patterns']['currencyFormat']
114+
?: ($localeData['NumberElements'][self::$defaultNumberSet]['patterns']['currencyFormat']
115+
?: explode(';', $localeData['NumberPatterns'][1])[0]);
116+
117+
$decimalSymbol = $localeData['NumberElements'][$defaultSet]['symbols']['decimal']
118+
?: ($localeData['NumberElements'][self::$defaultNumberSet]['symbols']['decimal']
119+
?: $localeData['NumberElements'][0]);
120+
121+
$groupSymbol = $localeData['NumberElements'][$defaultSet]['symbols']['group']
122+
?: ($localeData['NumberElements'][self::$defaultNumberSet]['symbols']['group']
123+
?: $localeData['NumberElements'][1]);
113124

114125
$pos = strpos($format, ';');
115126
if ($pos !== false) {

setup/src/Magento/Setup/Controller/Install.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Zend\View\Model\ViewModel;
2121
use Magento\Setup\Console\Command\InstallCommand;
2222
use Magento\SampleData;
23+
use Magento\Framework\App\DeploymentConfig;
2324

2425
/**
2526
* Install controller
@@ -48,24 +49,32 @@ class Install extends AbstractActionController
4849
*/
4950
protected $sampleDataState;
5051

52+
/**
53+
* @var \Magento\Framework\App\DeploymentConfig
54+
*/
55+
private $deploymentConfig;
56+
5157
/**
5258
* Default Constructor
5359
*
5460
* @param WebLogger $logger
5561
* @param InstallerFactory $installerFactory
5662
* @param ProgressFactory $progressFactory
5763
* @param \Magento\Framework\Setup\SampleData\State $sampleDataState
64+
* @param \Magento\Framework\App\DeploymentConfig $deploymentConfig
5865
*/
5966
public function __construct(
6067
WebLogger $logger,
6168
InstallerFactory $installerFactory,
6269
ProgressFactory $progressFactory,
63-
\Magento\Framework\Setup\SampleData\State $sampleDataState
70+
\Magento\Framework\Setup\SampleData\State $sampleDataState,
71+
DeploymentConfig $deploymentConfig
6472
) {
6573
$this->log = $logger;
6674
$this->installer = $installerFactory->create($logger);
6775
$this->progressFactory = $progressFactory;
6876
$this->sampleDataState = $sampleDataState;
77+
$this->deploymentConfig = $deploymentConfig;
6978
}
7079

7180
/**
@@ -89,6 +98,7 @@ public function startAction()
8998
$this->log->clear();
9099
$json = new JsonModel;
91100
try {
101+
$this->checkForPriorInstall();
92102
$data = array_merge(
93103
$this->importDeploymentConfigForm(),
94104
$this->importUserConfigForm(),
@@ -106,6 +116,7 @@ public function startAction()
106116
$json->setVariable('messages', $this->installer->getInstallInfo()[Installer::INFO_MESSAGE]);
107117
} catch (\Exception $e) {
108118
$this->log->logError($e);
119+
$json->setVariable('messages', $e->getMessage());
109120
$json->setVariable('success', false);
110121
}
111122
return $json;
@@ -145,6 +156,19 @@ public function progressAction()
145156
return $json->setVariables(['progress' => $percent, 'success' => $success, 'console' => $contents]);
146157
}
147158

159+
/**
160+
* Checks for prior install
161+
*
162+
* @return void
163+
* @throws \Magento\Setup\Exception
164+
*/
165+
private function checkForPriorInstall()
166+
{
167+
if ($this->deploymentConfig->isAvailable()) {
168+
throw new \Magento\Setup\Exception('Magento application is already installed.');
169+
}
170+
}
171+
148172
/**
149173
* Maps data from request to format of deployment config model
150174
*

setup/src/Magento/Setup/Test/Unit/Controller/InstallTest.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,28 @@ class InstallTest extends \PHPUnit_Framework_TestCase
3535
*/
3636
private $sampleDataState;
3737

38+
/**
39+
* @var \Magento\Framework\App\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject
40+
*/
41+
private $deploymentConfig;
42+
3843
public function setUp()
3944
{
4045
$this->webLogger = $this->getMock('\Magento\Setup\Model\WebLogger', [], [], '', false);
4146
$installerFactory = $this->getMock('\Magento\Setup\Model\InstallerFactory', [], [], '', false);
4247
$this->installer = $this->getMock('\Magento\Setup\Model\Installer', [], [], '', false);
4348
$this->progressFactory = $this->getMock('\Magento\Setup\Model\Installer\ProgressFactory', [], [], '', false);
4449
$this->sampleDataState = $this->getMock('\Magento\Framework\Setup\SampleData\State', [], [], '', false);
50+
$this->deploymentConfig = $this->getMock('\Magento\Framework\App\DeploymentConfig', [], [], '', false);
4551

4652
$installerFactory->expects($this->once())->method('create')->with($this->webLogger)
4753
->willReturn($this->installer);
4854
$this->controller = new Install(
4955
$this->webLogger,
5056
$installerFactory,
5157
$this->progressFactory,
52-
$this->sampleDataState
58+
$this->sampleDataState,
59+
$this->deploymentConfig
5360
);
5461
}
5562

@@ -65,6 +72,7 @@ public function testStartAction()
6572
$this->webLogger->expects($this->once())->method('clear');
6673
$this->installer->expects($this->once())->method('install');
6774
$this->installer->expects($this->exactly(2))->method('getInstallInfo');
75+
$this->deploymentConfig->expects($this->once())->method('isAvailable')->willReturn(false);
6876
$jsonModel = $this->controller->startAction();
6977
$this->assertInstanceOf('\Zend\View\Model\JsonModel', $jsonModel);
7078
$variables = $jsonModel->getVariables();
@@ -74,9 +82,23 @@ public function testStartAction()
7482
$this->assertTrue($variables['success']);
7583
}
7684

77-
public function testStartActionException()
85+
public function testStartActionPriorInstallException()
86+
{
87+
$this->webLogger->expects($this->once())->method('clear');
88+
$this->installer->expects($this->never())->method('install');
89+
$this->installer->expects($this->never())->method('getInstallInfo');
90+
$this->deploymentConfig->expects($this->once())->method('isAvailable')->willReturn(true);
91+
$jsonModel = $this->controller->startAction();
92+
$this->assertInstanceOf('\Zend\View\Model\JsonModel', $jsonModel);
93+
$variables = $jsonModel->getVariables();
94+
$this->assertArrayHasKey('success', $variables);
95+
$this->assertArrayHasKey('messages', $variables);
96+
$this->assertFalse($variables['success']);
97+
}
98+
public function testStartActionInstallException()
7899
{
79100
$this->webLogger->expects($this->once())->method('clear');
101+
$this->deploymentConfig->expects($this->once())->method('isAvailable')->willReturn(false);
80102
$this->installer->expects($this->once())->method('install')
81103
->willThrowException($this->getMock('\Exception'));
82104
$jsonModel = $this->controller->startAction();
@@ -87,6 +109,7 @@ public function testStartActionWithSampleDataError()
87109
{
88110
$this->webLogger->expects($this->once())->method('clear');
89111
$this->webLogger->expects($this->never())->method('logError');
112+
$this->deploymentConfig->expects($this->once())->method('isAvailable')->willReturn(false);
90113
$this->installer->method('install');
91114
$this->sampleDataState->expects($this->once())->method('hasError')->willReturn(true);
92115
$jsonModel = $this->controller->startAction();

0 commit comments

Comments
 (0)