Skip to content

Commit eaa80bb

Browse files
committed
Completing support for extracting model validation messages from application plugins
1 parent d2519ae commit eaa80bb

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

lib/Cake/Console/Command/Task/ExtractTask.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ public function execute() {
132132
CakePlugin::load($plugin);
133133
}
134134
$this->_paths = array(CakePlugin::path($plugin));
135+
$this->params['plugin'] = $plugin;
135136
} else {
136137
$defaultPath = APP;
137138
$message = __d('cake_console', "What is the path you would like to extract?\n[Q]uit [D]one");
@@ -157,7 +158,7 @@ public function execute() {
157158
$this->_exclude = array_merge($this->_exclude, App::path('plugins'));
158159
}
159160

160-
if (!empty($this->params['ignore-model-validation']) || !$this->_isExtractingApp()) {
161+
if (!empty($this->params['ignore-model-validation']) || (!$this->_isExtractingApp() && empty($plugin))) {
161162
$this->_extractValidation = false;
162163
}
163164
if (!empty($this->params['validation-domain'])) {
@@ -354,10 +355,16 @@ protected function _extractValidationMessages() {
354355
if (!$this->_extractValidation) {
355356
return;
356357
}
357-
$models = App::objects('Model', null, false);
358358
App::uses('AppModel', 'Model');
359+
$plugin = null;
360+
if (!empty($this->params['plugin'])) {
361+
App::uses($this->params['plugin'] . 'AppModel', $this->params['plugin'] . '.Model');
362+
$plugin = $this->params['plugin'] . '.';
363+
}
364+
$models = App::objects($plugin . 'Model', null, false);
365+
359366
foreach ($models as $model) {
360-
App::uses($model, 'Model');
367+
App::uses($model, $plugin . 'Model');
361368
$reflection = new ReflectionClass($model);
362369
$properties = $reflection->getDefaultProperties();
363370
$validate = $properties['validate'];

lib/Cake/Test/Case/Console/Command/Task/ExtractTaskTest.php

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public function tearDown() {
6161
$Folder = new Folder($this->path);
6262
$Folder->delete();
6363
App::build();
64+
CakePlugin::unload();
6465
}
6566

6667
/**
@@ -255,7 +256,6 @@ public function testExtractPlugin() {
255256
$this->assertNoPattern('#Pages#', $result);
256257
$this->assertContains('translate.ctp:1', $result);
257258
$this->assertContains('This is a translatable string', $result);
258-
CakePlugin::unload();
259259
}
260260

261261
/**
@@ -342,4 +342,46 @@ public function testExtractModelValidationWithDomainInModel() {
342342
$this->assertPattern($pattern, $result);
343343
}
344344

345+
346+
/**
347+
* Test that the extract shell can obtain validation messages from models inside a specific plugin
348+
*
349+
* @return void
350+
*/
351+
public function testExtractModelValidationInPlugin() {
352+
App::build(array(
353+
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
354+
));
355+
$this->out = $this->getMock('ConsoleOutput', array(), array(), '', false);
356+
$this->in = $this->getMock('ConsoleInput', array(), array(), '', false);
357+
$this->Task = $this->getMock('ExtractTask',
358+
array('_isExtractingApp', 'in', 'out', 'err', 'clear', '_stop'),
359+
array($this->out, $this->out, $this->in)
360+
);
361+
362+
$this->Task->params['output'] = $this->path . DS;
363+
$this->Task->params['ignore-model-validation'] = false;
364+
$this->Task->params['plugin'] = 'TestPlugin';
365+
366+
$this->Task->execute();
367+
$result = file_get_contents($this->path . DS . 'test_plugin.pot');
368+
369+
$pattern = '#Model/TestPluginPost.php:validation for field title#';
370+
$this->assertPattern($pattern, $result);
371+
372+
$pattern = '#Model/TestPluginPost.php:validation for field body#';
373+
$this->assertPattern($pattern, $result);
374+
375+
$pattern = '#msgid "Post title is required"#';
376+
$this->assertPattern($pattern, $result);
377+
378+
$pattern = '#msgid "Post body is required"#';
379+
$this->assertPattern($pattern, $result);
380+
381+
$pattern = '#msgid "Post body is super required"#';
382+
$this->assertPattern($pattern, $result);
383+
384+
$pattern = '#Plugin/TestPlugin/Model/TestPluginPost.php:validation for field title#';
385+
$this->assertNoPattern($pattern, $result);
386+
}
345387
}

0 commit comments

Comments
 (0)