Skip to content

Commit

Permalink
Locale path for plugin (#73)
Browse files Browse the repository at this point in the history
* fix: locale path for plugin

* fix: retrocompatibility

* fix: retrocompatibility

* fix: tests

* fix: test coverage
  • Loading branch information
didoda authored Oct 21, 2022
1 parent 3b9fa79 commit a1978e8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
8 changes: 2 additions & 6 deletions src/Command/GettextCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,8 @@ private function setupPaths(Arguments $args): void
];
$this->templatePaths = array_merge($paths, App::path(View::NAME_TEMPLATE, $plugin));
$this->defaultDomain = $plugin;
foreach ($localesPaths as $path) {
if (strpos($path, sprintf('%s%s%s', DS, $plugin, DS)) > 0) {
$this->localePath = $path;
break;
}
}
$localePaths = App::path('locales', $plugin);
$this->localePath = (string)Hash::get($localePaths, '0');

return;
}
Expand Down
13 changes: 4 additions & 9 deletions tests/TestCase/Command/GettextCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ public function testBuildOptionParser(): void
*
* @return void
* @covers ::execute()
* @covers ::getPoResult()
* @covers ::getTemplatePaths()
* @covers ::getLocalePath()
*/
public function testExecute(): void
{
Expand All @@ -100,9 +97,6 @@ public function testExecute(): void
*
* @return void
* @covers ::execute()
* @covers ::getPoResult()
* @covers ::getTemplatePaths()
* @covers ::getLocalePath()
*/
public function testUpdateWithCi(): void
{
Expand Down Expand Up @@ -156,7 +150,7 @@ public function setupPathsProvider(): array
sprintf('%s/tests/test_app/plugins/Dummy/config', $base),
sprintf('%s/tests/test_app/plugins/Dummy/templates', $base),
], // template paths
sprintf('%s/tests/test_app/plugins/Dummy/Locale', $base), // locale path
sprintf('%s/tests/test_app/plugins/Dummy/resources/locales', $base), // locale path
],
];
}
Expand All @@ -172,10 +166,11 @@ public function setupPathsProvider(): array
* @return void
* @dataProvider setupPathsProvider
* @covers ::setupPaths()
* @covers ::getTemplatePaths()
* @covers ::getLocalePath()
*/
public function testSetupPaths($appPath, $startPath, $pluginName, array $expectedTemplatePaths, string $expectedLocalePath): void
{
$expectedPoName = 'default.po';
$options = [];
if (!empty($appPath)) {
$options['app'] = sprintf('%s/%s', getcwd(), $appPath);
Expand All @@ -185,7 +180,6 @@ public function testSetupPaths($appPath, $startPath, $pluginName, array $expecte
}
if (!empty($pluginName)) {
$options['plugin'] = $pluginName;
$expectedPoName = sprintf('%s.po', $pluginName);
}
$args = new Arguments([], $options, []);
$method = self::getMethod('setupPaths');
Expand Down Expand Up @@ -473,6 +467,7 @@ public function parseFileProvider(): array
* @return void
* @dataProvider parseFileProvider
* @covers ::parseFile()
* @covers ::getPoResult()
*/
public function testParseFile(string $file, string $extension, array $expected): void
{
Expand Down

0 comments on commit a1978e8

Please sign in to comment.