Browse Source

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

tags/2.0.0-beta
Klimov Paul 12 years ago
parent
commit
4a164f8afa
  1. 42
      framework/yii/console/controllers/MessageController.php
  2. 13
      tests/unit/framework/console/controllers/MessageControllerTest.php

42
framework/yii/console/controllers/MessageController.php

@ -224,11 +224,51 @@ class MessageController extends Controller
* Message string can be used with plural forms format. Check i18n section
* 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;
EOD;
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";
}
}
}

13
tests/unit/framework/console/controllers/MessageControllerTest.php

@ -151,20 +151,25 @@ class MessageControllerTest extends TestCase
// Tests:
public function testEmptyArgs()
public function testActionTemplate()
{
$this->setExpectedException('CException', 'usageError');
$this->runMessageControllerAction('index', array());
$configFileName = $this->configFileName;
$this->runMessageControllerAction('template', array($configFileName));
$this->assertTrue(file_exists($configFileName), 'Unable to create config file template!');
}
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'));
}
public function testCreateTranslation()
{
$this->markTestIncomplete('MessageController is incomplete');
$language = 'en';
$category = 'test_category';

Loading…
Cancel
Save