From a5e903f2523ca1661f99ce8de949b07d8faa3cb0 Mon Sep 17 00:00:00 2001 From: Klimov Paul Date: Sun, 9 Jun 2013 15:04:58 +0300 Subject: [PATCH 1/6] Unit test for "yii\console\controllers\MessageController" has been created. --- .../console/controllers/MessageControllerTest.php | 364 +++++++++++++++++++++ 1 file changed, 364 insertions(+) create mode 100644 tests/unit/framework/console/controllers/MessageControllerTest.php diff --git a/tests/unit/framework/console/controllers/MessageControllerTest.php b/tests/unit/framework/console/controllers/MessageControllerTest.php new file mode 100644 index 0000000..82bb393 --- /dev/null +++ b/tests/unit/framework/console/controllers/MessageControllerTest.php @@ -0,0 +1,364 @@ +sourcePath = Yii::getAlias('@yiiunit/runtime/test_source'); + $this->createDir($this->sourcePath); + $this->messagePath = Yii::getAlias('@yiiunit/runtime/test_messages'); + $this->createDir($this->messagePath); + $this->configFileName = Yii::getAlias('@yiiunit/runtime') . DIRECTORY_SEPARATOR . 'message_controller_test_config.php'; + } + + public function tearDown() + { + $this->removeDir($this->sourcePath); + $this->removeDir($this->messagePath); + if (file_exists($this->configFileName)) { + unlink($this->configFileName); + } + } + + /** + * Creates directory. + * @param $dirName directory full name + */ + protected function createDir($dirName) + { + if (!file_exists($dirName)) { + mkdir($dirName, 0777, true); + } + } + + /** + * Removes directory. + * @param $dirName directory full name + */ + protected function removeDir($dirName) + { + if (!empty($dirName) && file_exists($dirName)) { + $this->removeFileSystemObject($dirName); + } + } + + /** + * Removes file system object: directory or file. + * @param string $fileSystemObjectFullName file system object full name. + */ + protected function removeFileSystemObject($fileSystemObjectFullName) + { + if (!is_dir($fileSystemObjectFullName)) { + unlink($fileSystemObjectFullName); + } else { + $dirHandle = opendir($fileSystemObjectFullName); + while (($fileSystemObjectName = readdir($dirHandle)) !== false) { + if ($fileSystemObjectName==='.' || $fileSystemObjectName==='..') { + continue; + } + $this->removeFileSystemObject($fileSystemObjectFullName . DIRECTORY_SEPARATOR . $fileSystemObjectName); + } + closedir($dirHandle); + rmdir($fileSystemObjectFullName); + } + } + + /** + * Creates test message controller instance. + * @return MessageController message command instance. + */ + protected function createMessageController() + { + $module = $this->getMock('yii\\base\\Module', array('fake'), array('console')); + $command = new MessageController('message', $module); + return $command; + } + + /** + * Emulates running of the message controller action. + * @param string $actionId id of action to be run. + * @param array $args action arguments. + * @return string command output. + */ + protected function runMessageControllerAction($actionId, array $args=array()) + { + $controller = $this->createMessageController(); + ob_start(); + ob_implicit_flush(false); + $params = array( + \yii\console\Request::ANONYMOUS_PARAMS => $args + ); + $controller->run($actionId, $params); + return ob_get_clean(); + } + + /** + * Creates message command config file at {@link configFileName} + * @param array $config message command config. + */ + protected function composeConfigFile(array $config) + { + if (file_exists($this->configFileName)) { + unlink($this->configFileName); + } + $fileContent = 'configFileName, $fileContent); + } + + /** + * Creates source file with given content + * @param string $content file content + * @param string|null $name file self name + */ + protected function createSourceFile($content, $name = null) + { + if (empty($name)) { + $name = md5(uniqid()) . '.php'; + } + file_put_contents($this->sourcePath . DIRECTORY_SEPARATOR . $name, $content); + } + + /** + * Creates message file with given messages. + * @param string $name file name + * @param array $messages messages. + */ + protected function createMessageFile($name, array $messages = array()) + { + $fileName = $this->messagePath . DIRECTORY_SEPARATOR . $name; + if (file_exists($fileName)) { + unlink($fileName); + } else { + $dirName = dirname($fileName); + if (!file_exists($dirName)) { + mkdir($dirName, 0777, true); + } + } + $fileContent = 'setExpectedException('CException', 'usageError'); + $this->runMessageControllerAction('index', array()); + } + + public function testConfigFileNotExist() + { + $this->setExpectedException('CException', 'usageError'); + $this->runMessageControllerAction('index', array('not_existing_file.php')); + } + + public function testCreateTranslation() + { + $language = 'en'; + + $category = 'test_category'; + $message = 'test message'; + $sourceFileContent = "Yii::t('{$category}','{$message}')"; + $this->createSourceFile($sourceFileContent); + + $this->composeConfigFile(array( + 'languages' => array($language), + 'sourcePath' => $this->sourcePath, + 'messagePath' => $this->messagePath, + )); + $this->runMessageControllerAction('index', array($this->configFileName)); + + $this->assertTrue(file_exists($this->messagePath . DIRECTORY_SEPARATOR . $language), 'No language dir created!'); + $messageFileName = $this->messagePath . DIRECTORY_SEPARATOR . $language . DIRECTORY_SEPARATOR . $category . '.php'; + $this->assertTrue(file_exists($messageFileName), 'No message file created!'); + $messages = require($messageFileName); + $this->assertTrue(is_array($messages), 'Unable to compose messages!'); + $this->assertTrue(array_key_exists($message, $messages), 'Source message is missing!'); + } + + /** + * @depends testCreateTranslation + */ + public function testNothingNew() + { + $language = 'en'; + + $category = 'test_category'; + $message = 'test message'; + $sourceFileContent = "Yii::t('{$category}', '{$message}')"; + $this->createSourceFile($sourceFileContent); + + $this->composeConfigFile(array( + 'languages' => array($language), + 'sourcePath' => $this->sourcePath, + 'messagePath' => $this->messagePath, + )); + $this->runMessageControllerAction('index', array($this->configFileName)); + + $messageFileName = $this->messagePath . DIRECTORY_SEPARATOR . $language . DIRECTORY_SEPARATOR . $category . '.php'; + + // check file not overwritten: + $messageFileContent = file_get_contents($messageFileName); + $messageFileContent .= '// some not generated by command content'; + file_put_contents($messageFileName, $messageFileContent); + + $this->runMessageControllerAction('index', array($this->configFileName)); + + $this->assertEquals($messageFileContent, file_get_contents($messageFileName)); + } + + /** + * @depends testCreateTranslation + */ + public function testMerge() + { + $language = 'en'; + $category = 'test_category'; + $messageFileName = $language . DIRECTORY_SEPARATOR . $category . '.php'; + + $existingMessage = 'test existing message'; + $existingMessageContent = 'test existing message content'; + $this->createMessageFile($messageFileName, array( + $existingMessage => $existingMessageContent + )); + + $newMessage = 'test new message'; + $sourceFileContent = "Yii::t('{$category}', '{$existingMessage}')"; + $sourceFileContent .= "Yii::t('{$category}', '{$newMessage}')"; + $this->createSourceFile($sourceFileContent); + + $this->composeConfigFile(array( + 'languages' => array($language), + 'sourcePath' => $this->sourcePath, + 'messagePath' => $this->messagePath, + 'overwrite' => true, + )); + $this->runMessageControllerAction('index', array($this->configFileName)); + + $messages = require($this->messagePath . DIRECTORY_SEPARATOR . $messageFileName); + $this->assertTrue(array_key_exists($newMessage, $messages), 'Unable to add new message!'); + $this->assertTrue(array_key_exists($existingMessage, $messages), 'Unable to keep existing message!'); + $this->assertEquals('', $messages[$newMessage], 'Wrong new message content!'); + $this->assertEquals($existingMessageContent, $messages[$existingMessage], 'Unable to keep existing message content!'); + } + + /** + * @depends testMerge + */ + public function testNoLongerNeedTranslation() + { + $language = 'en'; + $category = 'test_category'; + $messageFileName = $language . DIRECTORY_SEPARATOR . $category . '.php'; + + $oldMessage = 'test old message'; + $oldMessageContent = 'test old message content'; + $this->createMessageFile($messageFileName, array( + $oldMessage => $oldMessageContent + )); + + $sourceFileContent = "Yii::t('{$category}', 'some new message')"; + $this->createSourceFile($sourceFileContent); + + $this->composeConfigFile(array( + 'languages' => array($language), + 'sourcePath' => $this->sourcePath, + 'messagePath' => $this->messagePath, + 'overwrite' => true, + 'removeOld' => false, + )); + $this->runMessageControllerAction('index', array($this->configFileName)); + + $messages = require($this->messagePath . DIRECTORY_SEPARATOR . $messageFileName); + + $this->assertTrue(array_key_exists($oldMessage, $messages), 'No longer needed message removed!'); + $this->assertEquals('@@' . $oldMessageContent . '@@', $messages[$oldMessage], 'No longer needed message content does not marked properly!'); + } + + /** + * @depends testMerge + */ + public function testMergeWithContentZero() + { + $language = 'en'; + $category = 'test_category'; + $messageFileName = $language . DIRECTORY_SEPARATOR . $category . '.php'; + + $zeroMessage = 'test zero message'; + $zeroMessageContent = '0'; + $falseMessage = 'test false message'; + $falseMessageContent = 'false'; + $this->createMessageFile($messageFileName, array( + $zeroMessage => $zeroMessageContent, + $falseMessage => $falseMessageContent, + )); + + $newMessage = 'test new message'; + $sourceFileContent = "Yii::t('{$category}', '{$zeroMessage}')"; + $sourceFileContent .= "Yii::t('{$category}', '{$falseMessage}')"; + $sourceFileContent .= "Yii::t('{$category}', '{$newMessage}')"; + $this->createSourceFile($sourceFileContent); + + $this->composeConfigFile(array( + 'languages' => array($language), + 'sourcePath' => $this->sourcePath, + 'messagePath' => $this->messagePath, + 'overwrite' => true, + )); + $this->runMessageControllerAction('index', array($this->configFileName)); + + $messages = require($this->messagePath . DIRECTORY_SEPARATOR . $messageFileName); + $this->assertTrue($zeroMessageContent === $messages[$zeroMessage], 'Message content "0" is lost!'); + $this->assertTrue($falseMessageContent === $messages[$falseMessage], 'Message content "false" is lost!'); + } + + /** + * @depends testCreateTranslation + */ + public function testMultiplyTranslators() + { + $language = 'en'; + $category = 'test_category'; + + $translators = array( + 'Yii::t', + 'Custom::translate', + ); + + $sourceMessages = array( + 'first message', + 'second message', + ); + $sourceFileContent = ''; + foreach ($sourceMessages as $key => $message) { + $sourceFileContent .= $translators[$key] . "('{$category}', '{$message}');\n"; + } + $this->createSourceFile($sourceFileContent); + + $this->composeConfigFile(array( + 'languages' => array($language), + 'sourcePath' => $this->sourcePath, + 'messagePath' => $this->messagePath, + 'translator' => $translators, + )); + $this->runMessageControllerAction('index', array($this->configFileName)); + + $messageFileName = $this->messagePath . DIRECTORY_SEPARATOR . $language . DIRECTORY_SEPARATOR . $category . '.php'; + $messages = require($messageFileName); + + foreach ($sourceMessages as $sourceMessage) { + $this->assertTrue(array_key_exists($sourceMessage, $messages)); + } + } +} From 3c9b157814f09bb1e35bc63fe8d9aa799afa76be Mon Sep 17 00:00:00 2001 From: Klimov Paul Date: Sun, 9 Jun 2013 15:11:34 +0300 Subject: [PATCH 2/6] Exception usage has been added to "yii\console\controllers\MessageController". --- .../yii/console/controllers/MessageController.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/framework/yii/console/controllers/MessageController.php b/framework/yii/console/controllers/MessageController.php index 44cf1b1..828f25f 100644 --- a/framework/yii/console/controllers/MessageController.php +++ b/framework/yii/console/controllers/MessageController.php @@ -9,6 +9,8 @@ namespace yii\console\controllers; use yii\console\Controller; +use yii\console\Exception; +use yii\helpers\FileHelper; /** * This command extracts messages to be translated from source files. @@ -26,6 +28,7 @@ class MessageController extends Controller * * @param string $config the path of the configuration file. You can find * an example in framework/messages/config.php. + * @throws \yii\console\Exception on failure. * * The file can be placed anywhere and must be a valid PHP script which * returns an array of name-value pairs. Each name-value pair represents @@ -58,25 +61,25 @@ class MessageController extends Controller public function actionIndex($config) { if (!is_file($config)) { - $this->usageError("the configuration file {$config} does not exist."); + throw new Exception("the configuration file {$config} does not exist."); } - $config = require_once($config); + $config = require($config); - $translator='Yii::t'; + $translator = 'Yii::t'; extract($config); if (!isset($sourcePath, $messagePath, $languages)) { - $this->usageError('The configuration file must specify "sourcePath", "messagePath" and "languages".'); + throw new Exception('The configuration file must specify "sourcePath", "messagePath" and "languages".'); } if (!is_dir($sourcePath)) { - $this->usageError("The source path $sourcePath is not a valid directory."); + throw new Exception("The source path {$sourcePath} is not a valid directory."); } if (!is_dir($messagePath)) { - $this->usageError("The message path $messagePath is not a valid directory."); + throw new Exception("The message path {$messagePath} is not a valid directory."); } if (empty($languages)) { - $this->usageError("Languages cannot be empty."); + throw new Exception("Languages cannot be empty."); } if (!isset($overwrite)) { @@ -96,7 +99,7 @@ class MessageController extends Controller if (isset($exclude)) { $options['exclude'] = $exclude; } - $files = CFileHelper::findFiles(realpath($sourcePath), $options); + $files = FileHelper::findFiles(realpath($sourcePath), $options); $messages = array(); foreach ($files as $file) { @@ -209,7 +212,7 @@ class MessageController extends Controller /** * Message translations. * - * This file is automatically generated by 'yii message' command. + * This file is automatically generated by 'yii {$this->id}' command. * It contains the localizable messages extracted from source code. * You may modify this file by translating the extracted messages. * From 4a164f8afaae31a2e0fedf063788943d8ead3ddf Mon Sep 17 00:00:00 2001 From: Klimov Paul Date: Sun, 9 Jun 2013 16:07:03 +0300 Subject: [PATCH 3/6] 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'; From 04848a45c92f48b30479aa2c7529ad0c2802b888 Mon Sep 17 00:00:00 2001 From: Klimov Paul Date: Sun, 9 Jun 2013 16:10:59 +0300 Subject: [PATCH 4/6] Default action of "yii\console\controllers\MessageController" has been renamed to "generate". --- .../yii/console/controllers/MessageController.php | 8 ++++++-- .../console/controllers/MessageControllerTest.php | 18 ++++++++---------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/framework/yii/console/controllers/MessageController.php b/framework/yii/console/controllers/MessageController.php index 04bb65d..21071bc 100644 --- a/framework/yii/console/controllers/MessageController.php +++ b/framework/yii/console/controllers/MessageController.php @@ -23,6 +23,10 @@ use yii\helpers\FileHelper; class MessageController extends Controller { /** + * @var string controller default action ID. + */ + public $defaultAction = 'generate'; + /** * Searches for messages to be translated in the specified * source files and compiles them into PHP arrays as message source. * @@ -58,7 +62,7 @@ class MessageController extends Controller * - sort: sort messages by key when merging, regardless of their translation * state (new, obsolete, translated.) */ - public function actionIndex($config) + public function actionGenerate($config) { if (!is_file($config)) { throw new Exception("the configuration file {$config} does not exist."); @@ -233,7 +237,7 @@ EOD; } /** - * Creates template of configuration file for [[actionIndex]]. + * Creates template of configuration file for [[actionGenerate]]. * @param string $configFile output file name. * @throws \yii\console\Exception on failure. */ diff --git a/tests/unit/framework/console/controllers/MessageControllerTest.php b/tests/unit/framework/console/controllers/MessageControllerTest.php index 396ec79..9b639d7 100644 --- a/tests/unit/framework/console/controllers/MessageControllerTest.php +++ b/tests/unit/framework/console/controllers/MessageControllerTest.php @@ -160,10 +160,8 @@ class MessageControllerTest extends TestCase public function testConfigFileNotExist() { - $this->markTestIncomplete('MessageController is incomplete'); - $this->setExpectedException('yii\\console\\Exception'); - $this->runMessageControllerAction('index', array('not_existing_file.php')); + $this->runMessageControllerAction('generate', array('not_existing_file.php')); } public function testCreateTranslation() @@ -182,7 +180,7 @@ class MessageControllerTest extends TestCase 'sourcePath' => $this->sourcePath, 'messagePath' => $this->messagePath, )); - $this->runMessageControllerAction('index', array($this->configFileName)); + $this->runMessageControllerAction('generate', array($this->configFileName)); $this->assertTrue(file_exists($this->messagePath . DIRECTORY_SEPARATOR . $language), 'No language dir created!'); $messageFileName = $this->messagePath . DIRECTORY_SEPARATOR . $language . DIRECTORY_SEPARATOR . $category . '.php'; @@ -209,7 +207,7 @@ class MessageControllerTest extends TestCase 'sourcePath' => $this->sourcePath, 'messagePath' => $this->messagePath, )); - $this->runMessageControllerAction('index', array($this->configFileName)); + $this->runMessageControllerAction('generate', array($this->configFileName)); $messageFileName = $this->messagePath . DIRECTORY_SEPARATOR . $language . DIRECTORY_SEPARATOR . $category . '.php'; @@ -218,7 +216,7 @@ class MessageControllerTest extends TestCase $messageFileContent .= '// some not generated by command content'; file_put_contents($messageFileName, $messageFileContent); - $this->runMessageControllerAction('index', array($this->configFileName)); + $this->runMessageControllerAction('generate', array($this->configFileName)); $this->assertEquals($messageFileContent, file_get_contents($messageFileName)); } @@ -249,7 +247,7 @@ class MessageControllerTest extends TestCase 'messagePath' => $this->messagePath, 'overwrite' => true, )); - $this->runMessageControllerAction('index', array($this->configFileName)); + $this->runMessageControllerAction('generate', array($this->configFileName)); $messages = require($this->messagePath . DIRECTORY_SEPARATOR . $messageFileName); $this->assertTrue(array_key_exists($newMessage, $messages), 'Unable to add new message!'); @@ -283,7 +281,7 @@ class MessageControllerTest extends TestCase 'overwrite' => true, 'removeOld' => false, )); - $this->runMessageControllerAction('index', array($this->configFileName)); + $this->runMessageControllerAction('generate', array($this->configFileName)); $messages = require($this->messagePath . DIRECTORY_SEPARATOR . $messageFileName); @@ -321,7 +319,7 @@ class MessageControllerTest extends TestCase 'messagePath' => $this->messagePath, 'overwrite' => true, )); - $this->runMessageControllerAction('index', array($this->configFileName)); + $this->runMessageControllerAction('generate', array($this->configFileName)); $messages = require($this->messagePath . DIRECTORY_SEPARATOR . $messageFileName); $this->assertTrue($zeroMessageContent === $messages[$zeroMessage], 'Message content "0" is lost!'); @@ -357,7 +355,7 @@ class MessageControllerTest extends TestCase 'messagePath' => $this->messagePath, 'translator' => $translators, )); - $this->runMessageControllerAction('index', array($this->configFileName)); + $this->runMessageControllerAction('generate', array($this->configFileName)); $messageFileName = $this->messagePath . DIRECTORY_SEPARATOR . $language . DIRECTORY_SEPARATOR . $category . '.php'; $messages = require($messageFileName); From 7c9f74722c2bb1aff1130cb2b082298012f38851 Mon Sep 17 00:00:00 2001 From: Klimov Paul Date: Tue, 11 Jun 2013 20:15:37 +0300 Subject: [PATCH 5/6] "yii\console\controllers\MessageController" has been fixed. --- .../yii/console/controllers/MessageController.php | 30 +++++++++++++--------- .../console/controllers/MessageControllerTest.php | 14 +++++----- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/framework/yii/console/controllers/MessageController.php b/framework/yii/console/controllers/MessageController.php index 21071bc..ff2de2b 100644 --- a/framework/yii/console/controllers/MessageController.php +++ b/framework/yii/console/controllers/MessageController.php @@ -55,7 +55,8 @@ class MessageController extends Controller * directory 'sourcePath/a/b'. * - translator: the name of the function for translating messages. * Defaults to 'Yii::t'. This is used as a mark to find messages to be - * translated. + * translated. Accepts both string for single function name or array for + * multiple function names. * - overwrite: if message file must be overwritten with the merged messages. * - removeOld: if message no longer needs translation it will be removed, * instead of being enclosed between a pair of '@@' marks. @@ -133,18 +134,23 @@ class MessageController extends Controller { echo "Extracting messages from $fileName...\n"; $subject = file_get_contents($fileName); - $n = preg_match_all( - '/\b' . $translator . '\s*\(\s*(\'.*?(? 0) { $merged[$message] = $translated[$message]; } else { $untranslated[] = $message; diff --git a/tests/unit/framework/console/controllers/MessageControllerTest.php b/tests/unit/framework/console/controllers/MessageControllerTest.php index 9b639d7..a4b45d4 100644 --- a/tests/unit/framework/console/controllers/MessageControllerTest.php +++ b/tests/unit/framework/console/controllers/MessageControllerTest.php @@ -17,6 +17,9 @@ class MessageControllerTest extends TestCase { $this->sourcePath = Yii::getAlias('@yiiunit/runtime/test_source'); $this->createDir($this->sourcePath); + if (!file_exists($this->sourcePath)) { + $this->markTestIncomplete('Unit tests runtime directory should have writable permissions!'); + } $this->messagePath = Yii::getAlias('@yiiunit/runtime/test_messages'); $this->createDir($this->messagePath); $this->configFileName = Yii::getAlias('@yiiunit/runtime') . DIRECTORY_SEPARATOR . 'message_controller_test_config.php'; @@ -81,8 +84,9 @@ class MessageControllerTest extends TestCase protected function createMessageController() { $module = $this->getMock('yii\\base\\Module', array('fake'), array('console')); - $command = new MessageController('message', $module); - return $command; + $messageController = new MessageController('message', $module); + $messageController->interactive = false; + return $messageController; } /** @@ -91,7 +95,7 @@ class MessageControllerTest extends TestCase * @param array $args action arguments. * @return string command output. */ - protected function runMessageControllerAction($actionId, array $args=array()) + protected function runMessageControllerAction($actionId, array $args = array()) { $controller = $this->createMessageController(); ob_start(); @@ -166,13 +170,11 @@ class MessageControllerTest extends TestCase public function testCreateTranslation() { - $this->markTestIncomplete('MessageController is incomplete'); - $language = 'en'; $category = 'test_category'; $message = 'test message'; - $sourceFileContent = "Yii::t('{$category}','{$message}')"; + $sourceFileContent = "Yii::t('{$category}', '{$message}')"; $this->createSourceFile($sourceFileContent); $this->composeConfigFile(array( From 014053f080a3ba695273f78817341f1a91397c90 Mon Sep 17 00:00:00 2001 From: Klimov Paul Date: Tue, 11 Jun 2013 20:18:06 +0300 Subject: [PATCH 6/6] Doc comments at "yii\console\controllers\MessageController" has been updated. --- framework/yii/console/controllers/MessageController.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/framework/yii/console/controllers/MessageController.php b/framework/yii/console/controllers/MessageController.php index ff2de2b..ccb4834 100644 --- a/framework/yii/console/controllers/MessageController.php +++ b/framework/yii/console/controllers/MessageController.php @@ -17,6 +17,13 @@ use yii\helpers\FileHelper; * The extracted messages are saved as PHP message source files * under the specified directory. * + * Usage: + * 1. Create a configuration file using 'template' action: + * yii message/template /path/to/myapp/messages/config.php + * 2. Edit the created config file, adjusting it for your web application needs. + * 3. Run the 'generate' action, using created config: + * yii message /path/to/myapp/messages/config.php + * * @author Qiang Xue * @since 2.0 */