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 = <<