Skip to content

Commit cc5cd56

Browse files
author
Bohdan Korablov
committed
MAGETWO-57820: [GITHUB] php bin/magento i18n:pack creates unwanted dir #6260
1 parent 5c6b2d6 commit cc5cd56

File tree

4 files changed

+46
-10
lines changed

4 files changed

+46
-10
lines changed

setup/src/Magento/Setup/Module/I18n/Context.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ private function getComponentName($componentType, $path)
9595
* @param array $value
9696
* @return string
9797
* @throws \InvalidArgumentException
98+
* @throws UnregisteredComponentException
9899
*/
99100
public function buildPathToLocaleDirectoryByContext($type, $value)
100101
{
@@ -111,6 +112,11 @@ public function buildPathToLocaleDirectoryByContext($type, $value)
111112
default:
112113
throw new \InvalidArgumentException(sprintf('Invalid context given: "%s".', $type));
113114
}
115+
116+
if (null === $path) {
117+
throw new UnregisteredComponentException();
118+
}
119+
114120
return $path . '/' . self::LOCALE_DIRECTORY . '/';
115121
}
116122
}

setup/src/Magento/Setup/Module/I18n/Pack/Writer/File/AbstractFile.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Setup\Module\I18n\Factory;
1111
use Magento\Setup\Module\I18n\Locale;
1212
use Magento\Setup\Module\I18n\Pack\WriterInterface;
13+
use Magento\Setup\Module\I18n\UnregisteredComponentException;
1314

1415
/**
1516
* Abstract pack writer
@@ -120,6 +121,8 @@ protected function _buildPackFilesData(Dictionary $dictionary)
120121
$path = $this->_context->buildPathToLocaleDirectoryByContext($phrase->getContextType(), $context);
121122
} catch (\InvalidArgumentException $e) {
122123
throw new \InvalidArgumentException($e->getMessage() . ' Row #' . ($key + 1) . '.');
124+
} catch (UnregisteredComponentException $e) {
125+
continue;
123126
}
124127
$filename = $path . $this->_locale . '.' . $this->_getFileExtension();
125128
$files[$filename][$phrase->getPhrase()] = $phrase;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Setup\Module\I18n;
7+
8+
/**
9+
* This exception should be thrown when Component not found for install language pack
10+
*/
11+
class UnregisteredComponentException extends \Exception
12+
{
13+
}

setup/src/Magento/Setup/Test/Unit/Module/I18n/ContextTest.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function testGetContextByPath($context, $path, $pathValues)
4141
{
4242
$this->componentRegistrar->expects($this->any())
4343
->method('getPaths')
44-
->will($this->returnValueMap($pathValues));
44+
->willReturnMap($pathValues);
4545
$this->context = new Context($this->componentRegistrar);
4646
$this->assertEquals($context, $this->context->getContextByPath($path));
4747
}
@@ -108,10 +108,8 @@ public function testBuildPathToLocaleDirectoryByContext($path, $context, $regist
108108
$paths[$module[1]] = $module[2];
109109
}
110110
$this->componentRegistrar->expects($this->any())
111-
->method('getPaths')
112-
->with(ComponentRegistrar::MODULE)
113-
->willReturn($paths);
114-
$this->componentRegistrar->expects($this->any())->method('getPath')->will($this->returnValueMap($registrar));
111+
->method('getPath')
112+
->willReturnMap($registrar);
115113
$this->context = new Context($this->componentRegistrar);
116114
$this->assertEquals($path, $this->context->buildPathToLocaleDirectoryByContext($context[0], $context[1]));
117115
}
@@ -127,7 +125,11 @@ public function dataProviderPathToLocaleDirectoryByContext()
127125
[Context::CONTEXT_TYPE_MODULE, 'Magento_Module'],
128126
[[ComponentRegistrar::MODULE, 'Magento_Module', BP . '/app/code/Magento/Module']]
129127
],
130-
['/i18n/', [Context::CONTEXT_TYPE_THEME, 'theme/test.phtml'], []],
128+
[
129+
BP . '/app/design/frontend/Magento/luma/i18n/',
130+
[Context::CONTEXT_TYPE_THEME, 'rontend/Magento/luma'],
131+
[[ComponentRegistrar::THEME, 'rontend/Magento/luma', BP . '/app/design/frontend/Magento/luma']]
132+
],
131133
[BP . '/lib/web/i18n/', [Context::CONTEXT_TYPE_LIB, 'lib/web/module/test.phtml'], []],
132134
];
133135
}
@@ -138,11 +140,23 @@ public function dataProviderPathToLocaleDirectoryByContext()
138140
*/
139141
public function testBuildPathToLocaleDirectoryByContextWithInvalidType()
140142
{
141-
$this->componentRegistrar->expects($this->any())
142-
->method('getPaths')
143-
->with(ComponentRegistrar::MODULE)
144-
->willReturn(['module' => '/path/to/module']);
143+
$this->componentRegistrar->expects($this->never())
144+
->method('getPath');
145145
$this->context = new Context($this->componentRegistrar);
146146
$this->context->buildPathToLocaleDirectoryByContext('invalid_type', 'Magento_Module');
147147
}
148+
149+
/**
150+
* @expectedException \Magento\Setup\Module\I18n\UnregisteredComponentException
151+
*/
152+
public function testBuildPathToLocaleDirectoryByContextWithUnregisteredComponent()
153+
{
154+
$moduleName = 'Magento_Module';
155+
$this->componentRegistrar->expects($this->once())
156+
->method('getPath')
157+
->with(ComponentRegistrar::MODULE, $moduleName)
158+
->willReturn(null);
159+
$this->context = new Context($this->componentRegistrar);
160+
$this->context->buildPathToLocaleDirectoryByContext(ComponentRegistrar::MODULE, $moduleName);
161+
}
148162
}

0 commit comments

Comments
 (0)