From 08b4af53d2ad76ddb054f51ce07b13eb46093ba5 Mon Sep 17 00:00:00 2001 From: Simon Karlen Date: Wed, 5 Jan 2022 11:19:41 +0100 Subject: [PATCH] fixed `Unable to locate message source for category 'yii/bootstrap5'` --- tests/TestCase.php | 10 ++++++ tests/TranslationTest.php | 73 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 tests/TranslationTest.php diff --git a/tests/TestCase.php b/tests/TestCase.php index e2eae23..d4ad53a 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -70,11 +70,21 @@ class TestCase extends \PHPUnit\Framework\TestCase 'id' => 'testapp', 'basePath' => __DIR__, 'vendorPath' => dirname(__DIR__) . '/vendor', + 'language' => 'en-US', 'aliases' => [ '@bower' => '@vendor/bower-asset', '@npm' => '@vendor/npm-asset', ], 'components' => [ + 'i18n' => [ + 'translations' => [ + 'yii/bootstrap5*' => [ + 'class' => 'yii\i18n\GettextMessageSource', + 'sourceLanguage' => 'en-US', + 'basePath' => '@yii/bootstrap5/messages', + ], + ], + ], 'request' => [ 'cookieValidationKey' => 'wefJDF8sfdsfSDefwqdxj9oq', 'scriptFile' => __DIR__ . '/index.php', diff --git a/tests/TranslationTest.php b/tests/TranslationTest.php new file mode 100644 index 0000000..8a38020 --- /dev/null +++ b/tests/TranslationTest.php @@ -0,0 +1,73 @@ + + */ + +namespace yiiunit\extensions\bootstrap5; + +use yii\bootstrap5\Alert; +use yii\bootstrap5\Breadcrumbs; + +class TranslationTest extends TestCase +{ + protected function setUp() + { + $this->mockWebApplication([ + 'language' => 'de-CH', + 'sourceLanguage' => 'en-US', + 'components' => [ + 'i18n' => [ + 'translations' => [ + 'yii/bootstrap5*' => [ + 'class' => 'yii\i18n\GettextMessageSource', + 'sourceLanguage' => 'en-US', + 'basePath' => '@yii/bootstrap5/messages', + ], + ], + ], + ], + ]); + } + + public function testTranslatedAlert() + { + Alert::$counter = 0; + $html = Alert::widget([ + 'body' => 'Heilige Guacamole! Das ist ein deutscher Test.', + 'options' => [ + 'class' => ['alert-warning'] + ] + ]); + + $expectedHtml = << + +Heilige Guacamole! Das ist ein deutscher Test. + + + +HTML; + + $this->assertEqualsWithoutLE($expectedHtml, $html); + } + + public function testTranslatedBreadcrumb() + { + Breadcrumbs::$counter = 0; + $out = Breadcrumbs::widget([ + 'links' => [ + ['label' => 'Library', 'url' => '#'], + ['label' => 'Data'] + ] + ]); + + $expected = << +HTML; + $this->assertEqualsWithoutLE($expected, $out); + } +}