Skip to content

Commit 334ddd7

Browse files
author
Bohdan Korablov
committed
MAGETWO-56317: [GitHub] -[2.1.0] underscore in site url breaks admin redirect - The page isn't redirecting properly #5809
1 parent acdbd8e commit 334ddd7

File tree

3 files changed

+94
-54
lines changed

3 files changed

+94
-54
lines changed

lib/internal/Magento/Framework/Validator/Url.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function isValid($value, array $allowedSchemes = [])
2525
$isValid = false;
2626
}
2727

28-
if (!empty($allowedSchemes)) {
28+
if ($isValid && !empty($allowedSchemes)) {
2929
$url = parse_url($value);
3030
if (empty($url['scheme']) || !in_array($url['scheme'], $allowedSchemes)) {
3131
$isValid = false;

setup/src/Magento/Setup/Console/Command/InstallStoreConfigurationCommand.php

Lines changed: 55 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616
use Magento\Setup\Model\ObjectManagerProvider;
1717
use Magento\Framework\ObjectManagerInterface;
1818
use Magento\Framework\Exception\LocalizedException;
19-
use Magento\Store\Model\Store;
20-
use Magento\Framework\Validator\Locale;
21-
use Magento\Framework\Validator\Timezone;
22-
use Magento\Framework\Validator\Currency;
23-
use Magento\Framework\Validator\Url;
19+
use Magento\Framework\Validator\Locale as LocaleValidator;
20+
use Magento\Framework\Validator\Timezone as TimezoneValidator;
21+
use Magento\Framework\Validator\Currency as CurrencyValidator;
22+
use Magento\Framework\Validator\Url as UrlValidator;
2423

2524
/**
2625
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -43,24 +42,57 @@ class InstallStoreConfigurationCommand extends AbstractSetupCommand
4342
* Object Manager
4443
*
4544
* @var ObjectManagerInterface
45+
* @deprecated
4646
*/
4747
private $objectManager;
4848

49+
/**
50+
* @var LocaleValidator
51+
*/
52+
private $localeValidator;
53+
54+
/**
55+
* @var TimezoneValidator
56+
*/
57+
private $timezoneValidator;
58+
59+
/**
60+
* @var CurrencyValidator
61+
*/
62+
private $currencyValidator;
63+
64+
/**
65+
* @var UrlValidator
66+
*/
67+
private $urlValidator;
68+
4969
/**
5070
* Inject dependencies
5171
*
5272
* @param InstallerFactory $installerFactory
5373
* @param DeploymentConfig $deploymentConfig
5474
* @param ObjectManagerProvider $objectManagerProvider
75+
* @param LocaleValidator $localeValidator,
76+
* @param TimezoneValidator $timezoneValidator,
77+
* @param CurrencyValidator $currencyValidator,
78+
* @param UrlValidator $urlValidator
5579
*/
5680
public function __construct(
5781
InstallerFactory $installerFactory,
5882
DeploymentConfig $deploymentConfig,
59-
ObjectManagerProvider $objectManagerProvider
83+
ObjectManagerProvider $objectManagerProvider,
84+
LocaleValidator $localeValidator,
85+
TimezoneValidator $timezoneValidator,
86+
CurrencyValidator $currencyValidator,
87+
UrlValidator $urlValidator
6088
) {
6189
$this->installerFactory = $installerFactory;
6290
$this->deploymentConfig = $deploymentConfig;
6391
$this->objectManager = $objectManagerProvider->get();
92+
$this->localeValidator = $localeValidator;
93+
$this->timezoneValidator = $timezoneValidator;
94+
$this->currencyValidator = $currencyValidator;
95+
$this->urlValidator = $urlValidator;
6496
parent::__construct();
6597
}
6698

@@ -193,25 +225,31 @@ public function validate(InputInterface $input)
193225
}
194226
break;
195227
case StoreConfigurationDataMapper::KEY_LANGUAGE:
196-
/** @var Locale $lists */
197-
$lists = $this->objectManager->get(\Magento\Framework\Validator\Locale::class);
198-
$errorMsg = $this->validateCodes($lists, $value, StoreConfigurationDataMapper::KEY_LANGUAGE);
228+
$errorMsg = $this->validateCodes(
229+
$this->localeValidator,
230+
$value,
231+
StoreConfigurationDataMapper::KEY_LANGUAGE
232+
);
199233
if ($errorMsg !== '') {
200234
$errors[] = $errorMsg;
201235
}
202236
break;
203237
case StoreConfigurationDataMapper::KEY_TIMEZONE:
204-
/** @var Timezone $lists */
205-
$lists = $this->objectManager->get(\Magento\Framework\Validator\Timezone::class);
206-
$errorMsg = $this->validateCodes($lists, $value, StoreConfigurationDataMapper::KEY_TIMEZONE);
238+
$errorMsg = $this->validateCodes(
239+
$this->timezoneValidator,
240+
$value,
241+
StoreConfigurationDataMapper::KEY_TIMEZONE
242+
);
207243
if ($errorMsg !== '') {
208244
$errors[] = $errorMsg;
209245
}
210246
break;
211247
case StoreConfigurationDataMapper::KEY_CURRENCY:
212-
/** @var Currency $lists */
213-
$lists = $this->objectManager->get(\Magento\Framework\Validator\Currency::class);
214-
$errorMsg = $this->validateCodes($lists, $value, StoreConfigurationDataMapper::KEY_CURRENCY);
248+
$errorMsg = $this->validateCodes(
249+
$this->currencyValidator,
250+
$value,
251+
StoreConfigurationDataMapper::KEY_CURRENCY
252+
);
215253
if ($errorMsg !== '') {
216254
$errors[] = $errorMsg;
217255
}
@@ -291,7 +329,7 @@ private function validateBinaryValue($value, $key)
291329
/**
292330
* Validate codes for languages, currencies or timezones
293331
*
294-
* @param Locale|Timezone|Currency $lists
332+
* @param LocaleValidator|TimezoneValidator|CurrencyValidator $lists
295333
* @param string $code
296334
* @param string $type
297335
* @return string
@@ -316,12 +354,9 @@ private function validateCodes($lists, $code, $type)
316354
*/
317355
private function validateUrl($url, $option, array $allowedSchemes)
318356
{
319-
/** @var Url $validator */
320-
$validator = $this->objectManager->get(Url::class);
321-
322357
$errorMsg = '';
323358

324-
if (!$validator->isValid($url, $allowedSchemes)) {
359+
if (!$this->urlValidator->isValid($url, $allowedSchemes)) {
325360
$errorTemplate = '<error>Command option \'%s\': Invalid URL \'%s\'.'
326361
. ' Domain Name should contain only letters, digits and hyphen.'
327362
. ' And you should use only following schemes: \'%s\'.</error>';

setup/src/Magento/Setup/Test/Unit/Console/Command/InstallStoreConfigurationCommandTest.php

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
use Magento\Framework\ObjectManagerInterface;
1313
use Magento\Setup\Model\StoreConfigurationDataMapper;
1414
use Magento\Framework\Validator\Url as UrlValidator;
15+
use Magento\Framework\Validator\Locale as LocaleValidator;
16+
use Magento\Framework\Validator\Timezone as TimezoneValidator;
17+
use Magento\Framework\Validator\Currency as CurrencyValidator;
1518

1619
/**
1720
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -38,13 +41,38 @@ class InstallStoreConfigurationCommandTest extends \PHPUnit_Framework_TestCase
3841
*/
3942
private $objectManager;
4043

44+
/**
45+
* @var LocaleValidator|\PHPUnit_Framework_MockObject_MockObject
46+
*/
47+
private $localeValidatorMock;
48+
49+
/**
50+
* @var TimezoneValidator|\PHPUnit_Framework_MockObject_MockObject
51+
*/
52+
private $timezoneValidatorMock;
53+
54+
/**
55+
* @var CurrencyValidator|\PHPUnit_Framework_MockObject_MockObject
56+
*/
57+
private $currencyValidatorMock;
58+
59+
/**
60+
* @var UrlValidator|\PHPUnit_Framework_MockObject_MockObject
61+
*/
62+
private $urlValidatorMock;
63+
4164
/**
4265
* @var InstallStoreConfigurationCommand
4366
*/
4467
private $command;
4568

4669
protected function setUp()
4770
{
71+
$this->urlValidatorMock = $this->getMock(UrlValidator::class, [], [], '', false);
72+
$this->localeValidatorMock = $this->getMock(LocaleValidator::class, [], [], '', false);
73+
$this->timezoneValidatorMock = $this->getMock(TimezoneValidator::class, [], [], '', false);
74+
$this->currencyValidatorMock = $this->getMock(CurrencyValidator::class, [], [], '', false);
75+
4876
$this->installerFactory = $this->getMock(\Magento\Setup\Model\InstallerFactory::class, [], [], '', false);
4977
$this->deploymentConfig = $this->getMock(\Magento\Framework\App\DeploymentConfig::class, [], [], '', false);
5078
$this->installer = $this->getMock(\Magento\Setup\Model\Installer::class, [], [], '', false);
@@ -65,7 +93,11 @@ protected function setUp()
6593
$this->command = new InstallStoreConfigurationCommand(
6694
$this->installerFactory,
6795
$this->deploymentConfig,
68-
$objectManagerProvider
96+
$objectManagerProvider,
97+
$this->localeValidatorMock,
98+
$this->timezoneValidatorMock,
99+
$this->currencyValidatorMock,
100+
$this->urlValidatorMock
69101
);
70102
}
71103

@@ -105,38 +137,11 @@ public function testExecuteNotInstalled()
105137
*/
106138
public function testExecuteInvalidData(array $option, $error)
107139
{
108-
$validator = $this->getMock(UrlValidator::class, [], [], '', false);
109-
$validator->expects($this->any())->method('isValid')->willReturn(false);
110-
$validator->expects($this->any())->method('getAllowedSchemes')->willReturn(['http', 'https']);
111-
112-
$localeLists= $this->getMock(\Magento\Framework\Validator\Locale::class, [], [], '', false);
113-
$localeLists->expects($this->any())->method('isValid')->will($this->returnValue(false));
114-
$timezoneLists= $this->getMock(\Magento\Framework\Validator\Timezone::class, [], [], '', false);
115-
$timezoneLists->expects($this->any())->method('isValid')->will($this->returnValue(false));
116-
$currencyLists= $this->getMock(\Magento\Framework\Validator\Currency::class, [], [], '', false);
117-
$currencyLists->expects($this->any())->method('isValid')->will($this->returnValue(false));
118-
119-
$returnValueMapOM = [
120-
[
121-
UrlValidator::class,
122-
$validator
123-
],
124-
[
125-
\Magento\Framework\Validator\Locale::class,
126-
$localeLists
127-
],
128-
[
129-
\Magento\Framework\Validator\Timezone::class,
130-
$timezoneLists
131-
],
132-
[
133-
\Magento\Framework\Validator\Currency::class,
134-
$currencyLists
135-
],
136-
];
137-
$this->objectManager->expects($this->any())
138-
->method('get')
139-
->will($this->returnValueMap($returnValueMapOM));
140+
$this->localeValidatorMock->expects($this->any())->method('isValid')->willReturn(false);
141+
$this->timezoneValidatorMock->expects($this->any())->method('isValid')->willReturn(false);
142+
$this->currencyValidatorMock->expects($this->any())->method('isValid')->willReturn(false);
143+
$this->urlValidatorMock->expects($this->any())->method('isValid')->willReturn(false);
144+
140145
$this->deploymentConfig->expects($this->once())
141146
->method('isAvailable')
142147
->will($this->returnValue(true));

0 commit comments

Comments
 (0)