Permalink
Browse files

Adding cake core message extraction in cake extract

  • Loading branch information...
1 parent 43b37cd commit c8e58b50ba4b67af2966e4d3cdae867d44ec7c40 Jelle Henkens committed Jun 7, 2012
@@ -106,6 +106,13 @@ class ExtractTask extends AppShell {
protected $_validationDomain = 'default';
/**
+ * Holds whether this call should extract the CakePHP Lib messages
+ *
+ * @var boolean
+ */
+ protected $_extractCore = false;
+
+/**
* Method to interact with the User and get path selections.
*
* @return void
@@ -137,6 +144,7 @@ protected function _getPaths() {
$this->out();
}
}
+
/**
* Execution method always used for tasks
*
@@ -162,6 +170,21 @@ public function execute() {
$this->_getPaths();
}
+ if (isset($this->params['extract-core'])) {
+ $this->_extractCore = !(strtolower($this->params['extract-core']) === 'no');
+ } else {
+ $response = $this->in(__d('cake_console', 'Would you like to extract the messages from the CakePHP core?'), array('y', 'n'), 'n');
+ $this->_extractCore = strtolower($response) === 'y';
+ }
+
+ if ($this->_extractCore) {
+ $this->_paths[] = CAKE;
+ $this->_exclude = array_merge($this->_exclude, array(
+ CAKE . 'Test',
+ CAKE . 'Console' . DS . 'Templates'
+ ));
+ }
+
if (!empty($this->params['exclude-plugins']) && $this->_isExtractingApp()) {
$this->_exclude = array_merge($this->_exclude, App::path('plugins'));
}
@@ -307,6 +330,10 @@ public function getOptionParser() {
'boolean' => true,
'default' => false,
'help' => __d('cake_console', 'Always overwrite existing .pot files.')
+ ))
+ ->addOption('extract-core', array(
+ 'help' => __d('cake_console', 'Extract messages from the CakePHP core libs.'),
+ 'choices' => array('yes', 'no')
));
}
@@ -76,6 +76,7 @@ public function testExecute() {
$this->Task->params['paths'] = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Pages';
$this->Task->params['output'] = $this->path . DS;
+ $this->Task->params['extract-core'] = 'no';
$this->Task->expects($this->never())->method('err');
$this->Task->expects($this->any())->method('in')
->will($this->returnValue('y'));
@@ -85,6 +86,8 @@ public function testExecute() {
$this->assertTrue(file_exists($this->path . DS . 'default.pot'));
$result = file_get_contents($this->path . DS . 'default.pot');
+ $this->assertFalse(file_exists($this->path . DS . 'cake.pot'));
+
$pattern = '/"Content-Type\: text\/plain; charset\=utf-8/';
$this->assertRegExp($pattern, $result);
$pattern = '/"Content-Transfer-Encoding\: 8bit/';
@@ -182,6 +185,7 @@ public function testExtractWithExclude() {
$this->Task->params['paths'] = CAKE . 'Test' . DS . 'test_app' . DS . 'View';
$this->Task->params['output'] = $this->path . DS;
$this->Task->params['exclude'] = 'Pages,Layouts';
+ $this->Task->params['extract-core'] = 'no';
$this->Task->expects($this->any())->method('in')
->will($this->returnValue('y'));
@@ -210,6 +214,7 @@ public function testExtractMultiplePaths() {
CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Posts';
$this->Task->params['output'] = $this->path . DS;
+ $this->Task->params['extract-core'] = 'no';
$this->Task->expects($this->never())->method('err');
$this->Task->expects($this->never())->method('_stop');
$this->Task->execute();
@@ -293,6 +298,7 @@ public function testExtractModelValidation() {
$this->Task->params['paths'] = CAKE . 'Test' . DS . 'test_app' . DS;
$this->Task->params['output'] = $this->path . DS;
+ $this->Task->params['extract-core'] = 'no';
$this->Task->params['exclude-plugins'] = true;
$this->Task->params['ignore-model-validation'] = false;
@@ -338,6 +344,7 @@ public function testExtractModelValidationWithDomainInModel() {
$this->Task->params['paths'] = CAKE . 'Test' . DS . 'test_app' . DS;
$this->Task->params['output'] = $this->path . DS;
+ $this->Task->params['extract-core'] = 'no';
$this->Task->params['exclude-plugins'] = true;
$this->Task->params['ignore-model-validation'] = false;
@@ -412,6 +419,7 @@ public function testExtractOverwrite() {
$this->Task->params['paths'] = CAKE . 'Test' . DS . 'test_app' . DS;
$this->Task->params['output'] = $this->path . DS;
+ $this->Task->params['extract-core'] = 'no';
$this->Task->params['overwrite'] = true;
file_put_contents($this->path . DS . 'default.pot', 'will be overwritten');
@@ -422,4 +430,33 @@ public function testExtractOverwrite() {
$result = file_get_contents($this->path . DS . 'default.pot');
$this->assertNotEquals($original, $result);
}
+
+/**
+ * Test that the extract shell scans the core libs
+ *
+ * @return void
+ */
+ public function testExtractCore() {
+ $this->Task->interactive = false;
+
+ $this->Task->params['paths'] = CAKE . 'Test' . DS . 'test_app' . DS;
+ $this->Task->params['output'] = $this->path . DS;
+ $this->Task->params['extract-core'] = 'yes';
+
+ $this->Task->execute();
+ $this->assertTrue(file_exists($this->path . DS . 'cake.pot'));
+ $result = file_get_contents($this->path . DS . 'cake.pot');
+
+ $pattern = '/msgid "Yesterday, %s"\nmsgstr ""\n/';
+ $this->assertRegExp($pattern, $result);
+
+ $this->assertTrue(file_exists($this->path . DS . 'cake_dev.pot'));
+ $result = file_get_contents($this->path . DS . 'cake_dev.pot');
+
+ $pattern = '/#: Console\/Templates\//';
+ $this->assertNotRegExp($pattern, $result);
+
+ $pattern = '/#: Test\//';
+ $this->assertNotRegExp($pattern, $result);
+ }
}

0 comments on commit c8e58b5

Please sign in to comment.