Commit 4a164f8a by Klimov Paul

Action "template" has been added to "yii\console\controllers\MessageController".

parent 3c9b1578
...@@ -224,11 +224,51 @@ class MessageController extends Controller ...@@ -224,11 +224,51 @@ class MessageController extends Controller
* Message string can be used with plural forms format. Check i18n section * Message string can be used with plural forms format. Check i18n section
* of the guide for details. * of the guide for details.
* *
* NOTE, this file must be saved in UTF-8 encoding. * NOTE: this file must be saved in UTF-8 encoding.
*/ */
return $array; return $array;
EOD; EOD;
file_put_contents($fileName, $content); file_put_contents($fileName, $content);
} }
/**
* Creates template of configuration file for [[actionIndex]].
* @param string $configFile output file name.
* @throws \yii\console\Exception on failure.
*/
public function actionTemplate($configFile)
{
$template = <<<EOD
<?php
/**
* Configuration file for the "yii {$this->id}" console command.
*/
return array(
'sourcePath' => __DIR__,
'messagePath' => __DIR__ . DIRECTORY_SEPARATOR . 'messages',
'languages' => array(),
'fileTypes' => array('php'),
'overwrite' => true,
'exclude' => array(
'.svn',
'.gitignore',
'.gitkeep',
'.hgignore',
'.hgkeep',
'/messages',
),
);
EOD;
if (file_exists($configFile)) {
if (!$this->confirm("File '{$configFile}' already exists. Do you wish to overwrite it?")) {
return;
}
}
if (!file_put_contents($configFile, $template)) {
throw new Exception("Unable to write template file '{$configFile}'.");
} else {
echo "Configuration file template created at '{$configFile}'.\n\n";
}
}
} }
...@@ -151,20 +151,25 @@ class MessageControllerTest extends TestCase ...@@ -151,20 +151,25 @@ class MessageControllerTest extends TestCase
// Tests: // Tests:
public function testEmptyArgs() public function testActionTemplate()
{ {
$this->setExpectedException('CException', 'usageError'); $configFileName = $this->configFileName;
$this->runMessageControllerAction('index', array()); $this->runMessageControllerAction('template', array($configFileName));
$this->assertTrue(file_exists($configFileName), 'Unable to create config file template!');
} }
public function testConfigFileNotExist() public function testConfigFileNotExist()
{ {
$this->setExpectedException('CException', 'usageError'); $this->markTestIncomplete('MessageController is incomplete');
$this->setExpectedException('yii\\console\\Exception');
$this->runMessageControllerAction('index', array('not_existing_file.php')); $this->runMessageControllerAction('index', array('not_existing_file.php'));
} }
public function testCreateTranslation() public function testCreateTranslation()
{ {
$this->markTestIncomplete('MessageController is incomplete');
$language = 'en'; $language = 'en';
$category = 'test_category'; $category = 'test_category';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment