Skip to content
Permalink
Browse files

add check, that default locale must be on whitelist

  • Loading branch information
Aleš
Aleš committed Sep 4, 2019
1 parent 6468881 commit 63da2f04d11118d9409d9aa1eb9b9b2a1af920e8
Showing with 10 additions and 1 deletion.
  1. +7 −1 src/DI/TranslationExtension.php
  2. +3 −0 tests/Tests/DI/TranslationExtension.phpt
@@ -36,7 +36,13 @@ public function getConfigSchema(): Nette\Schema\Schema
}),
'default' => Expect::string('en'),
'fallback' => Expect::array()->default(null),
]),
])->assert(function (stdClass $locales): bool {
if ($locales->whitelist !== null && !in_array($locales->default, $locales->whitelist, true)) {
throw new Contributte\Translation\Exceptions\InvalidArgument('If you set whitelist, default locale must be on him.');
}
return true;
}),
'localeResolvers' => Expect::array()->default(null),
'loaders' => Expect::array()->default([
'neon' => Contributte\Translation\Loaders\Neon::class,
@@ -21,6 +21,9 @@ class TranslationExtension extends Tests\TestAbstract
Tester\Assert::exception(function (): void {
$this->createContainer(['locales' => ['whitelist' => ['en', 'en']]]);
}, Contributte\Translation\Exceptions\InvalidArgument::class, 'Whitelist settings have not unique values.');
Tester\Assert::exception(function (): void {
$this->createContainer(['locales' => ['whitelist' => ['en'], 'default' => 'cs']]);
}, Contributte\Translation\Exceptions\InvalidArgument::class, 'If you set whitelist, default locale must be on him.');
Tester\Assert::exception(function (): void {
$this->createContainer(['localeResolvers' => [stdClass::class]]);
}, Contributte\Translation\Exceptions\InvalidArgument::class, 'Resolver must implement interface "' . Contributte\Translation\LocalesResolvers\ResolverInterface::class . '".');

0 comments on commit 63da2f0

Please sign in to comment.
You can’t perform that action at this time.