Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
adereksisusanto committed May 8, 2024
1 parent 4e1c729 commit 6b1259f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
10 changes: 5 additions & 5 deletions src/TranslationsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,21 +324,21 @@ public function initializeConfig(): array
return $this->config;
}

private function get(array|string $key, mixed $default = null): string|array
private function get(array|string $key, mixed $default = null): mixed
{
if (is_array($key)) {
$config = [];
foreach ($key as $k => $default) {
foreach ($key as $k => $v) {
if (is_numeric($k)) {
[$k, $default] = [$default, null];
[$k, $v] = [$v, null];
}
$config[$k] = Str::replace('/', '\\', Arr::get($this->config, $k, $default));
$config[$k] = Arr::get($this->config, $k, $v);
}

return $config;
}

return Str::replace('/', '\\', Arr::get($this->config, $key, $default));
return Arr::get($this->config, $key, $default);
}

private function set(array|string $key, mixed $value = null): void
Expand Down
24 changes: 12 additions & 12 deletions tests/TranslationsManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,31 @@
$translations = TranslationsUI::getTranslations('en');
expect($translations)->toBe([
'en.json' => ['title' => 'My title'],
'en\auth.php' => ['test' => 'Test'],
'en\book\create.php' => ['nested' => 'Nested test'],
'en/auth.php' => ['test' => 'Test'],
'en/book/create.php' => ['nested' => 'Nested test'],
]);

$translations = TranslationsUI::getTranslations('');
expect($translations)->toBe([
'en.json' => ['title' => 'My title'],
'en\auth.php' => ['test' => 'Test'],
'en\book\create.php' => ['nested' => 'Nested test'],
'en/auth.php' => ['test' => 'Test'],
'en/book/create.php' => ['nested' => 'Nested test'],
]);
});

it('it excludes the correct files', function () {
createPhpLanguageFile('en\auth.php', [
createPhpLanguageFile('en/auth.php', [
'test' => 'Test',
]);
createPhpLanguageFile('en\validation.php', [
createPhpLanguageFile('en/validation.php', [
'test' => 'Test1',
]);
createJsonLanguageFile('en.json', [
'title' => 'My title',
]);

// Update to include nested folder
createPhpLanguageFile('en\book\create.php', [
createPhpLanguageFile('en/book/create.php', [
'nested' => 'Nested test',
]);

Expand All @@ -99,9 +99,9 @@
});

test('export creates a new translation file with the correct content', function () {
createDirectoryIfNotExits(lang_path('en\auth.php'));
createDirectoryIfNotExits(lang_path('en/auth.php'));
// Update to include nested folder
createDirectoryIfNotExits(lang_path('en\book\create.php'));
createDirectoryIfNotExits(lang_path('en/book/create.php'));

$translation = Translation::factory([
'source' => true,
Expand All @@ -126,15 +126,15 @@
])->has(Phrase::factory()->state([
'phrase_id' => null,
'translation_file_id' => TranslationFile::factory([
'name' => 'book\create',
'name' => 'book/create',
'extension' => 'php',
]),
]))->create();

TranslationsUI::export();

$fileName = lang_path('en\\'.$translation->phrases[0]->file->name.'.'.$translation->phrases[0]->file->extension);
$nestedFileName = lang_path('en\\'.$nestedTranslation->phrases[0]->file->name.'.'.$nestedTranslation->phrases[0]->file->extension);
$fileName = lang_path('en/'.$translation->phrases[0]->file->name.'.'.$translation->phrases[0]->file->extension);
$nestedFileName = lang_path('en/'.$nestedTranslation->phrases[0]->file->name.'.'.$nestedTranslation->phrases[0]->file->extension);

$fileNameInDisk = File::allFiles(lang_path($translation->language->code))[0]->getPathname();
$nestedFileNameInDisk = File::allFiles(lang_path($nestedTranslation->language->code))[1]->getPathname();
Expand Down

0 comments on commit 6b1259f

Please sign in to comment.