fixed Unable to locate message source for category 'yii/bootstrap5'

This commit is contained in:
Simon Karlen 2022-01-05 11:19:41 +01:00
parent cb48dd6e45
commit 08b4af53d2
No known key found for this signature in database
GPG Key ID: 0630C27D666EBCC3
2 changed files with 83 additions and 0 deletions

View File

@ -70,11 +70,21 @@ class TestCase extends \PHPUnit\Framework\TestCase
'id' => 'testapp', 'id' => 'testapp',
'basePath' => __DIR__, 'basePath' => __DIR__,
'vendorPath' => dirname(__DIR__) . '/vendor', 'vendorPath' => dirname(__DIR__) . '/vendor',
'language' => 'en-US',
'aliases' => [ 'aliases' => [
'@bower' => '@vendor/bower-asset', '@bower' => '@vendor/bower-asset',
'@npm' => '@vendor/npm-asset', '@npm' => '@vendor/npm-asset',
], ],
'components' => [ 'components' => [
'i18n' => [
'translations' => [
'yii/bootstrap5*' => [
'class' => 'yii\i18n\GettextMessageSource',
'sourceLanguage' => 'en-US',
'basePath' => '@yii/bootstrap5/messages',
],
],
],
'request' => [ 'request' => [
'cookieValidationKey' => 'wefJDF8sfdsfSDefwqdxj9oq', 'cookieValidationKey' => 'wefJDF8sfdsfSDefwqdxj9oq',
'scriptFile' => __DIR__ . '/index.php', 'scriptFile' => __DIR__ . '/index.php',

73
tests/TranslationTest.php Normal file
View File

@ -0,0 +1,73 @@
<?php
/**
* @package yii2-bootstrap5
* @author Simon Karlen <simi.albi@gmail.com>
*/
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' => '<strong>Heilige Guacamole!</strong> Das ist ein deutscher Test.',
'options' => [
'class' => ['alert-warning']
]
]);
$expectedHtml = <<<HTML
<div id="w0" class="alert-warning alert alert-dismissible" role="alert">
<strong>Heilige Guacamole!</strong> Das ist ein deutscher Test.
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Schliessen"></button>
</div>
HTML;
$this->assertEqualsWithoutLE($expectedHtml, $html);
}
public function testTranslatedBreadcrumb()
{
Breadcrumbs::$counter = 0;
$out = Breadcrumbs::widget([
'links' => [
['label' => 'Library', 'url' => '#'],
['label' => 'Data']
]
]);
$expected = <<<HTML
<nav aria-label="breadcrumb"><ol id="w0" class="breadcrumb"><li class="breadcrumb-item"><a href="/">Start</a></li>
<li class="breadcrumb-item"><a href="#">Library</a></li>
<li class="breadcrumb-item active" aria-current="page">Data</li>
</ol></nav>
HTML;
$this->assertEqualsWithoutLE($expected, $out);
}
}