From 4a164f8afaae31a2e0fedf063788943d8ead3ddf Mon Sep 17 00:00:00 2001 From: Klimov Paul Date: Sun, 9 Jun 2013 16:07:03 +0300 Subject: [PATCH] Action "template" has been added to "yii\console\controllers\MessageController". --- .../yii/console/controllers/MessageController.php | 42 +++++++++++++++++++++- .../console/controllers/MessageControllerTest.php | 13 ++++--- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/framework/yii/console/controllers/MessageController.php b/framework/yii/console/controllers/MessageController.php index 828f25f..04bb65d 100644 --- a/framework/yii/console/controllers/MessageController.php +++ b/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 = <<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"; + } + } } diff --git a/tests/unit/framework/console/controllers/MessageControllerTest.php b/tests/unit/framework/console/controllers/MessageControllerTest.php index 82bb393..396ec79 100644 --- a/tests/unit/framework/console/controllers/MessageControllerTest.php +++ b/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';