You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
2.2 KiB
87 lines
2.2 KiB
10 years ago
|
<?php
|
||
|
namespace yiiunit\framework\console\controllers;
|
||
|
|
||
|
|
||
|
use Yii;
|
||
|
use yii\helpers\FileHelper;
|
||
|
use yii\i18n\GettextPoFile;
|
||
|
|
||
|
/**
|
||
|
* Tests that [[\yii\console\controllers\MessageController]] works as expected with PO message format.
|
||
|
*/
|
||
|
class POMessageControllerTest extends BaseMessageControllerTest
|
||
|
{
|
||
|
protected $messagePath;
|
||
|
protected $catalog = 'messages';
|
||
|
|
||
|
public function setUp()
|
||
|
{
|
||
|
parent::setUp();
|
||
10 years ago
|
|
||
|
if (defined('HHVM_VERSION')) {
|
||
|
$this->markTestSkipped('POMessageControllerTest can not run on HHVM because it relies on saving and re-including PHP files which is not supported by HHVM.');
|
||
|
}
|
||
|
|
||
10 years ago
|
$this->messagePath = Yii::getAlias('@yiiunit/runtime/test_messages');
|
||
|
FileHelper::createDirectory($this->messagePath, 0777);
|
||
|
}
|
||
|
|
||
|
public function tearDown()
|
||
|
{
|
||
|
parent::tearDown();
|
||
|
FileHelper::removeDirectory($this->messagePath);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @inheritdoc
|
||
|
*/
|
||
|
protected function getDefaultConfig()
|
||
|
{
|
||
|
return [
|
||
|
'format' => 'po',
|
||
|
'languages' => [$this->language],
|
||
|
'sourcePath' => $this->sourcePath,
|
||
|
'messagePath' => $this->messagePath,
|
||
|
'overwrite' => true,
|
||
|
];
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @return string message file path
|
||
|
*/
|
||
|
protected function getMessageFilePath()
|
||
|
{
|
||
|
return $this->messagePath . '/' . $this->language . '/' . $this->catalog . '.po';
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @inheritdoc
|
||
|
*/
|
||
|
protected function saveMessages($messages, $category)
|
||
|
{
|
||
|
$messageFilePath = $this->getMessageFilePath();
|
||
|
FileHelper::createDirectory(dirname($messageFilePath), 0777);
|
||
|
$gettext = new GettextPoFile();
|
||
|
|
||
|
$data = [];
|
||
|
foreach ($messages as $message => $translation) {
|
||
|
$data[$category . chr(4) . $message] = $translation;
|
||
|
}
|
||
|
|
||
|
$gettext->save($messageFilePath, $data);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @inheritdoc
|
||
|
*/
|
||
10 years ago
|
protected function loadMessages($category)
|
||
10 years ago
|
{
|
||
|
$messageFilePath = $this->getMessageFilePath();
|
||
10 years ago
|
if (!file_exists($messageFilePath)) {
|
||
10 years ago
|
return [];
|
||
|
}
|
||
10 years ago
|
|
||
|
$gettext = new GettextPoFile();
|
||
|
return $gettext->load($messageFilePath, $category);
|
||
|
}
|
||
10 years ago
|
}
|