-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5b300e8
commit 5222493
Showing
7 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace yii1tech\i18n\fallback\test; | ||
|
||
use CPhpMessageSource; | ||
use Yii; | ||
use yii1tech\i18n\fallback\MessageSourceFallbackBehavior; | ||
|
||
class MessageSourceFallbackBehaviorTest extends TestCase | ||
{ | ||
/** | ||
* @param \yii1tech\i18n\fallback\MessageSourceFallbackBehavior|array $behavior | ||
* @return void | ||
*/ | ||
protected function attachMessageSourceBehavior($behavior): void | ||
{ | ||
Yii::app()->getComponent('messages')->attachBehavior('fallbackBehavior', $behavior); | ||
} | ||
|
||
public function testFallbackToDifferentSource(): void | ||
{ | ||
$this->attachMessageSourceBehavior([ | ||
'class' => MessageSourceFallbackBehavior::class, | ||
'fallbackMessageSource' => [ | ||
'class' => CPhpMessageSource::class, | ||
'basePath' => __DIR__ . '/messages/fallback', | ||
'forceTranslation' => true, | ||
], | ||
]); | ||
|
||
$this->assertSame('title-main-en_us', Yii::t('content', 'title')); | ||
$this->assertSame('header-fallback-en_us', Yii::t('content', 'header')); | ||
} | ||
|
||
public function testFallbackToDifferentLanguage(): void | ||
{ | ||
$messageSource = Yii::app()->getComponent('messages'); | ||
|
||
$this->attachMessageSourceBehavior([ | ||
'class' => MessageSourceFallbackBehavior::class, | ||
'fallbackLanguage' => 'en_us', | ||
'fallbackMessageSource' => [ | ||
'class' => get_class($messageSource), | ||
'basePath' => $messageSource->basePath, | ||
'forceTranslation' => true, | ||
], | ||
]); | ||
|
||
Yii::app()->setLanguage('es'); | ||
|
||
$this->assertSame('title-main-es', Yii::t('content', 'title')); | ||
$this->assertSame('description-main-en_us', Yii::t('content', 'description')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
// ensure we get report on all possible php errors | ||
error_reporting(-1); | ||
|
||
define('YII_ENABLE_ERROR_HANDLER', false); | ||
define('YII_ENABLE_EXCEPTION_HANDLER', false); | ||
define('YII_DEBUG', true); | ||
|
||
$_SERVER['SCRIPT_NAME'] = '/' . __DIR__; | ||
$_SERVER['SCRIPT_FILENAME'] = __FILE__; | ||
|
||
require_once(__DIR__ . '/../vendor/autoload.php'); | ||
require_once(__DIR__ . '/../vendor/yiisoft/yii/framework/yii.php'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
return [ | ||
'title' => 'title-fallback-en_us', | ||
'header' => 'header-fallback-en_us', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
return [ | ||
'title' => 'title-main-en_us', | ||
'description' => 'description-main-en_us', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
return [ | ||
'title' => 'title-main-es', | ||
'keywords' => 'keywords-main-es', | ||
]; |