2009-02-13 06:22:34 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* ExtractTaskTest file
|
2009-02-13 06:22:34 +00:00
|
|
|
*
|
2009-03-19 21:10:13 +00:00
|
|
|
* Test Case for i18n extraction shell task
|
2009-02-13 06:22:34 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2009-02-13 06:22:34 +00:00
|
|
|
*
|
2010-01-26 22:15:15 +00:00
|
|
|
* CakePHP : Rapid Development Framework (http://cakephp.org)
|
2012-03-13 02:46:46 +00:00
|
|
|
* Copyright 2005-2012, Cake Software Foundation, Inc.
|
2009-02-13 06:22:34 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2012-03-13 02:46:46 +00:00
|
|
|
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc.
|
2009-11-06 06:00:11 +00:00
|
|
|
* @link http://cakephp.org CakePHP Project
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Console.Command.Task
|
2009-02-13 06:22:34 +00:00
|
|
|
* @since CakePHP v 1.2.0.7726
|
2009-11-06 06:51:51 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2009-02-13 06:22:34 +00:00
|
|
|
*/
|
|
|
|
|
2010-12-09 03:45:18 +00:00
|
|
|
App::uses('Folder', 'Utility');
|
2012-05-25 16:27:40 +00:00
|
|
|
App::uses('ConsoleOutput', 'Console');
|
|
|
|
App::uses('ConsoleInput', 'Console');
|
2010-12-09 03:45:18 +00:00
|
|
|
App::uses('ShellDispatcher', 'Console');
|
|
|
|
App::uses('Shell', 'Console');
|
|
|
|
App::uses('ExtractTask', 'Console/Command/Task');
|
2010-01-17 00:41:52 +00:00
|
|
|
|
2009-03-13 16:06:18 +00:00
|
|
|
/**
|
|
|
|
* ExtractTaskTest class
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Console.Command.Task
|
2009-03-13 16:06:18 +00:00
|
|
|
*/
|
|
|
|
class ExtractTaskTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-13 16:06:18 +00:00
|
|
|
/**
|
|
|
|
* setUp method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function setUp() {
|
2011-09-03 22:21:27 +00:00
|
|
|
parent::setUp();
|
2010-10-07 02:52:42 +00:00
|
|
|
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
|
|
|
|
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
|
|
|
|
|
2010-10-24 19:27:04 +00:00
|
|
|
$this->Task = $this->getMock(
|
|
|
|
'ExtractTask',
|
|
|
|
array('in', 'out', 'err', '_stop'),
|
|
|
|
array($out, $out, $in)
|
|
|
|
);
|
2010-10-29 04:40:04 +00:00
|
|
|
$this->path = TMP . 'tests' . DS . 'extract_task_test';
|
|
|
|
$Folder = new Folder($this->path . DS . 'locale', true);
|
2009-02-13 06:22:34 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-13 16:06:18 +00:00
|
|
|
/**
|
|
|
|
* tearDown method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function tearDown() {
|
2010-10-07 02:52:42 +00:00
|
|
|
parent::tearDown();
|
2010-10-24 19:27:04 +00:00
|
|
|
unset($this->Task);
|
2010-10-29 04:40:04 +00:00
|
|
|
|
|
|
|
$Folder = new Folder($this->path);
|
|
|
|
$Folder->delete();
|
2011-07-07 06:40:27 +00:00
|
|
|
CakePlugin::unload();
|
2009-02-13 06:22:34 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-13 16:06:18 +00:00
|
|
|
/**
|
|
|
|
* testExecute method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testExecute() {
|
2009-03-13 16:06:18 +00:00
|
|
|
$this->Task->interactive = false;
|
2009-02-13 06:22:34 +00:00
|
|
|
|
2011-04-17 10:35:21 +00:00
|
|
|
$this->Task->params['paths'] = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Pages';
|
2010-10-29 04:40:04 +00:00
|
|
|
$this->Task->params['output'] = $this->path . DS;
|
2012-06-07 21:37:09 +00:00
|
|
|
$this->Task->params['extract-core'] = 'no';
|
2010-10-24 19:27:04 +00:00
|
|
|
$this->Task->expects($this->never())->method('err');
|
|
|
|
$this->Task->expects($this->any())->method('in')
|
|
|
|
->will($this->returnValue('y'));
|
|
|
|
$this->Task->expects($this->never())->method('_stop');
|
2010-06-21 03:23:56 +00:00
|
|
|
|
2009-03-13 16:06:18 +00:00
|
|
|
$this->Task->execute();
|
2010-10-29 04:40:04 +00:00
|
|
|
$this->assertTrue(file_exists($this->path . DS . 'default.pot'));
|
|
|
|
$result = file_get_contents($this->path . DS . 'default.pot');
|
2009-02-13 06:22:34 +00:00
|
|
|
|
2012-06-07 21:37:09 +00:00
|
|
|
$this->assertFalse(file_exists($this->path . DS . 'cake.pot'));
|
|
|
|
|
2009-03-13 16:06:18 +00:00
|
|
|
$pattern = '/"Content-Type\: text\/plain; charset\=utf-8/';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2009-03-13 16:06:18 +00:00
|
|
|
$pattern = '/"Content-Transfer-Encoding\: 8bit/';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2009-03-13 16:06:18 +00:00
|
|
|
$pattern = '/"Plural-Forms\: nplurals\=INTEGER; plural\=EXPRESSION;/';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2009-02-13 06:22:34 +00:00
|
|
|
|
2009-08-06 21:14:25 +00:00
|
|
|
// home.ctp
|
2009-03-13 16:06:18 +00:00
|
|
|
$pattern = '/msgid "Your tmp directory is writable."\nmsgstr ""\n/';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2012-02-07 02:25:11 +00:00
|
|
|
|
2009-03-13 16:06:18 +00:00
|
|
|
$pattern = '/msgid "Your tmp directory is NOT writable."\nmsgstr ""\n/';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2012-02-07 02:25:11 +00:00
|
|
|
|
2009-03-13 16:06:18 +00:00
|
|
|
$pattern = '/msgid "The %s is being used for caching. To change the config edit ';
|
|
|
|
$pattern .= 'APP\/config\/core.php "\nmsgstr ""\n/';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2012-02-07 02:25:11 +00:00
|
|
|
|
2009-03-13 16:06:18 +00:00
|
|
|
$pattern = '/msgid "Your cache is NOT working. Please check ';
|
|
|
|
$pattern .= 'the settings in APP\/config\/core.php"\nmsgstr ""\n/';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2012-02-07 02:25:11 +00:00
|
|
|
|
2009-03-13 16:06:18 +00:00
|
|
|
$pattern = '/msgid "Your database configuration file is present."\nmsgstr ""\n/';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2012-02-07 02:25:11 +00:00
|
|
|
|
2009-03-13 16:06:18 +00:00
|
|
|
$pattern = '/msgid "Your database configuration file is NOT present."\nmsgstr ""\n/';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2012-03-11 04:32:02 +00:00
|
|
|
|
2009-03-13 16:06:18 +00:00
|
|
|
$pattern = '/msgid "Rename config\/database.php.default to ';
|
|
|
|
$pattern .= 'config\/database.php"\nmsgstr ""\n/';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2012-02-07 02:25:11 +00:00
|
|
|
|
2009-03-13 16:06:18 +00:00
|
|
|
$pattern = '/msgid "Cake is able to connect to the database."\nmsgstr ""\n/';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2012-02-07 02:25:11 +00:00
|
|
|
|
2009-03-13 16:06:18 +00:00
|
|
|
$pattern = '/msgid "Cake is NOT able to connect to the database."\nmsgstr ""\n/';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2012-02-07 02:25:11 +00:00
|
|
|
|
2009-03-13 16:06:18 +00:00
|
|
|
$pattern = '/msgid "Editing this Page"\nmsgstr ""\n/';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2012-02-07 02:25:11 +00:00
|
|
|
|
2011-03-21 05:56:07 +00:00
|
|
|
$pattern = '/msgid "To change the content of this page, create: APP\/views\/pages\/home\.ctp/';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2009-02-13 06:22:34 +00:00
|
|
|
|
2011-03-21 05:56:07 +00:00
|
|
|
$pattern = '/To change its layout, create: APP\/views\/layouts\/default\.ctp\./s';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2009-08-06 21:14:25 +00:00
|
|
|
// extract.ctp
|
2012-02-07 02:25:11 +00:00
|
|
|
$pattern = '/\#: (\\\\|\/)extract\.ctp:15;6\n';
|
2010-02-12 13:52:58 +00:00
|
|
|
$pattern .= 'msgid "You have %d new message."\nmsgid_plural "You have %d new messages."/';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2010-02-12 13:52:58 +00:00
|
|
|
|
2012-02-07 02:25:11 +00:00
|
|
|
$pattern = '/msgid "You have %d new message."\nmsgstr ""/';
|
|
|
|
$this->assertNotRegExp($pattern, $result, 'No duplicate msgid');
|
|
|
|
|
2010-02-12 13:52:58 +00:00
|
|
|
$pattern = '/\#: (\\\\|\/)extract\.ctp:7\n';
|
|
|
|
$pattern .= 'msgid "You deleted %d message."\nmsgid_plural "You deleted %d messages."/';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2010-02-12 13:52:58 +00:00
|
|
|
|
|
|
|
$pattern = '/\#: (\\\\|\/)extract\.ctp:14\n';
|
2011-03-21 05:56:07 +00:00
|
|
|
$pattern .= '\#: (\\\\|\/)home\.ctp:99\n';
|
2010-02-12 13:52:58 +00:00
|
|
|
$pattern .= 'msgid "Editing this Page"\nmsgstr ""/';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2012-08-30 22:48:32 +00:00
|
|
|
$pattern = '/\#: (\\\\|\/)extract\.ctp:22\nmsgid "';
|
2011-04-25 17:22:14 +00:00
|
|
|
$pattern .= 'Hot features!';
|
|
|
|
$pattern .= '\\\n - No Configuration: Set-up the database and let the magic begin';
|
|
|
|
$pattern .= '\\\n - Extremely Simple: Just look at the name...It\'s Cake';
|
|
|
|
$pattern .= '\\\n - Active, Friendly Community: Join us #cakephp on IRC. We\'d love to help you get started';
|
|
|
|
$pattern .= '"\nmsgstr ""/';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-03-21 05:56:07 +00:00
|
|
|
|
2012-08-30 22:48:32 +00:00
|
|
|
$this->assertContains('msgid "double \\"quoted\\""', $result, 'Strings with quotes not handled correctly');
|
|
|
|
$this->assertContains("msgid \"single 'quoted'\"", $result, 'Strings with quotes not handled correctly');
|
|
|
|
|
2009-09-15 03:43:59 +00:00
|
|
|
// extract.ctp - reading the domain.pot
|
2010-10-29 04:40:04 +00:00
|
|
|
$result = file_get_contents($this->path . DS . 'domain.pot');
|
2009-09-15 03:43:59 +00:00
|
|
|
|
|
|
|
$pattern = '/msgid "You have %d new message."\nmsgid_plural "You have %d new messages."/';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertNotRegExp($pattern, $result);
|
2009-09-15 03:43:59 +00:00
|
|
|
$pattern = '/msgid "You deleted %d message."\nmsgid_plural "You deleted %d messages."/';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertNotRegExp($pattern, $result);
|
2009-09-15 03:43:59 +00:00
|
|
|
|
|
|
|
$pattern = '/msgid "You have %d new message \(domain\)."\nmsgid_plural "You have %d new messages \(domain\)."/';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2009-09-15 03:43:59 +00:00
|
|
|
$pattern = '/msgid "You deleted %d message \(domain\)."\nmsgid_plural "You deleted %d messages \(domain\)."/';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2010-10-29 04:40:04 +00:00
|
|
|
}
|
2009-09-15 03:43:59 +00:00
|
|
|
|
2010-10-29 04:40:04 +00:00
|
|
|
/**
|
|
|
|
* test exclusions
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testExtractWithExclude() {
|
2010-10-29 04:40:04 +00:00
|
|
|
$this->Task->interactive = false;
|
|
|
|
|
2011-04-17 10:35:21 +00:00
|
|
|
$this->Task->params['paths'] = CAKE . 'Test' . DS . 'test_app' . DS . 'View';
|
2010-10-29 04:40:04 +00:00
|
|
|
$this->Task->params['output'] = $this->path . DS;
|
2011-05-15 04:10:09 +00:00
|
|
|
$this->Task->params['exclude'] = 'Pages,Layouts';
|
2012-06-07 21:37:09 +00:00
|
|
|
$this->Task->params['extract-core'] = 'no';
|
2010-10-29 04:40:04 +00:00
|
|
|
|
|
|
|
$this->Task->expects($this->any())->method('in')
|
|
|
|
->will($this->returnValue('y'));
|
|
|
|
|
|
|
|
$this->Task->execute();
|
|
|
|
$this->assertTrue(file_exists($this->path . DS . 'default.pot'));
|
|
|
|
$result = file_get_contents($this->path . DS . 'default.pot');
|
|
|
|
|
|
|
|
$pattern = '/\#: .*extract\.ctp:6\n/';
|
|
|
|
$this->assertNotRegExp($pattern, $result);
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2010-10-29 04:40:04 +00:00
|
|
|
$pattern = '/\#: .*default\.ctp:26\n/';
|
|
|
|
$this->assertNotRegExp($pattern, $result);
|
2009-02-13 06:22:34 +00:00
|
|
|
}
|
2010-06-07 02:39:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* test extract can read more than one path.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testExtractMultiplePaths() {
|
2010-06-07 02:39:04 +00:00
|
|
|
$this->Task->interactive = false;
|
|
|
|
|
2011-04-17 10:35:21 +00:00
|
|
|
$this->Task->params['paths'] =
|
|
|
|
CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Pages,' .
|
|
|
|
CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Posts';
|
|
|
|
|
2010-10-29 04:40:04 +00:00
|
|
|
$this->Task->params['output'] = $this->path . DS;
|
2012-06-07 21:37:09 +00:00
|
|
|
$this->Task->params['extract-core'] = 'no';
|
2010-10-24 19:27:04 +00:00
|
|
|
$this->Task->expects($this->never())->method('err');
|
|
|
|
$this->Task->expects($this->never())->method('_stop');
|
2010-06-07 02:39:04 +00:00
|
|
|
$this->Task->execute();
|
|
|
|
|
2010-10-29 04:40:04 +00:00
|
|
|
$result = file_get_contents($this->path . DS . 'default.pot');
|
2010-06-07 02:39:04 +00:00
|
|
|
|
|
|
|
$pattern = '/msgid "Add User"/';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2010-06-07 02:39:04 +00:00
|
|
|
}
|
2011-05-27 20:19:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests that it is possible to exclude plugin paths by enabling the param option for the ExtractTask
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testExtractExcludePlugins() {
|
|
|
|
App::build(array(
|
2012-02-18 12:31:29 +00:00
|
|
|
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
2011-05-27 20:19:15 +00:00
|
|
|
));
|
|
|
|
$this->out = $this->getMock('ConsoleOutput', array(), array(), '', false);
|
|
|
|
$this->in = $this->getMock('ConsoleInput', array(), array(), '', false);
|
|
|
|
$this->Task = $this->getMock('ExtractTask',
|
2011-05-28 02:48:56 +00:00
|
|
|
array('_isExtractingApp', '_extractValidationMessages', 'in', 'out', 'err', 'clear', '_stop'),
|
2011-05-27 20:19:15 +00:00
|
|
|
array($this->out, $this->out, $this->in)
|
|
|
|
);
|
2011-05-28 02:48:56 +00:00
|
|
|
$this->Task->expects($this->exactly(2))->method('_isExtractingApp')->will($this->returnValue(true));
|
2011-05-27 20:19:15 +00:00
|
|
|
|
|
|
|
$this->Task->params['paths'] = CAKE . 'Test' . DS . 'test_app' . DS;
|
|
|
|
$this->Task->params['output'] = $this->path . DS;
|
|
|
|
$this->Task->params['exclude-plugins'] = true;
|
|
|
|
|
|
|
|
$this->Task->execute();
|
|
|
|
$result = file_get_contents($this->path . DS . 'default.pot');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertNotRegExp('#TestPlugin#', $result);
|
2011-07-07 06:27:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that is possible to extract messages form a single plugin
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testExtractPlugin() {
|
|
|
|
App::build(array(
|
2012-02-18 12:31:29 +00:00
|
|
|
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
2011-07-07 06:27:55 +00:00
|
|
|
));
|
|
|
|
|
|
|
|
$this->out = $this->getMock('ConsoleOutput', array(), array(), '', false);
|
|
|
|
$this->in = $this->getMock('ConsoleInput', array(), array(), '', false);
|
|
|
|
$this->Task = $this->getMock('ExtractTask',
|
|
|
|
array('_isExtractingApp', '_extractValidationMessages', 'in', 'out', 'err', 'clear', '_stop'),
|
|
|
|
array($this->out, $this->out, $this->in)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->Task->params['output'] = $this->path . DS;
|
|
|
|
$this->Task->params['plugin'] = 'TestPlugin';
|
|
|
|
|
|
|
|
$this->Task->execute();
|
|
|
|
$result = file_get_contents($this->path . DS . 'default.pot');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertNotRegExp('#Pages#', $result);
|
2011-07-07 06:27:55 +00:00
|
|
|
$this->assertContains('translate.ctp:1', $result);
|
|
|
|
$this->assertContains('This is a translatable string', $result);
|
2011-05-27 20:19:15 +00:00
|
|
|
}
|
2011-05-28 02:48:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests that the task will inspect application models and extract the validation messages from them
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testExtractModelValidation() {
|
|
|
|
App::build(array(
|
2011-06-20 05:06:31 +00:00
|
|
|
'Model' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Model' . DS),
|
2012-02-18 12:31:29 +00:00
|
|
|
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
2011-06-20 06:04:25 +00:00
|
|
|
), App::RESET);
|
2011-05-28 02:48:56 +00:00
|
|
|
$this->out = $this->getMock('ConsoleOutput', array(), array(), '', false);
|
|
|
|
$this->in = $this->getMock('ConsoleInput', array(), array(), '', false);
|
|
|
|
$this->Task = $this->getMock('ExtractTask',
|
|
|
|
array('_isExtractingApp', 'in', 'out', 'err', 'clear', '_stop'),
|
|
|
|
array($this->out, $this->out, $this->in)
|
|
|
|
);
|
|
|
|
$this->Task->expects($this->exactly(2))->method('_isExtractingApp')->will($this->returnValue(true));
|
|
|
|
|
|
|
|
$this->Task->params['paths'] = CAKE . 'Test' . DS . 'test_app' . DS;
|
|
|
|
$this->Task->params['output'] = $this->path . DS;
|
2012-06-07 21:37:09 +00:00
|
|
|
$this->Task->params['extract-core'] = 'no';
|
2011-05-28 02:48:56 +00:00
|
|
|
$this->Task->params['exclude-plugins'] = true;
|
|
|
|
$this->Task->params['ignore-model-validation'] = false;
|
|
|
|
|
|
|
|
$this->Task->execute();
|
|
|
|
$result = file_get_contents($this->path . DS . 'default.pot');
|
|
|
|
|
2011-10-18 22:41:19 +00:00
|
|
|
$pattern = preg_quote('#Model' . DS . 'PersisterOne.php:validation for field title#', '\\');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-05-28 02:48:56 +00:00
|
|
|
|
2011-10-18 22:41:19 +00:00
|
|
|
$pattern = preg_quote('#Model' . DS . 'PersisterOne.php:validation for field body#', '\\');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-05-28 02:48:56 +00:00
|
|
|
|
|
|
|
$pattern = '#msgid "Post title is required"#';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-05-28 02:48:56 +00:00
|
|
|
|
2011-07-31 01:03:56 +00:00
|
|
|
$pattern = '#msgid "You may enter up to %s chars \(minimum is %s chars\)"#';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-07-31 01:03:56 +00:00
|
|
|
|
2011-05-28 02:48:56 +00:00
|
|
|
$pattern = '#msgid "Post body is required"#';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-05-28 02:48:56 +00:00
|
|
|
|
|
|
|
$pattern = '#msgid "Post body is super required"#';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-05-28 02:48:56 +00:00
|
|
|
}
|
2011-06-20 05:06:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests that the task will inspect application models and extract the validation messages from them
|
|
|
|
* while using a custom validation domain for the messages set on the model itself
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testExtractModelValidationWithDomainInModel() {
|
|
|
|
App::build(array(
|
|
|
|
'Model' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPlugin' . DS . 'Model' . DS)
|
|
|
|
));
|
|
|
|
$this->out = $this->getMock('ConsoleOutput', array(), array(), '', false);
|
|
|
|
$this->in = $this->getMock('ConsoleInput', array(), array(), '', false);
|
|
|
|
$this->Task = $this->getMock('ExtractTask',
|
|
|
|
array('_isExtractingApp', 'in', 'out', 'err', 'clear', '_stop'),
|
|
|
|
array($this->out, $this->out, $this->in)
|
|
|
|
);
|
|
|
|
$this->Task->expects($this->exactly(2))->method('_isExtractingApp')->will($this->returnValue(true));
|
|
|
|
|
|
|
|
$this->Task->params['paths'] = CAKE . 'Test' . DS . 'test_app' . DS;
|
|
|
|
$this->Task->params['output'] = $this->path . DS;
|
2012-06-07 21:37:09 +00:00
|
|
|
$this->Task->params['extract-core'] = 'no';
|
2011-06-20 05:06:31 +00:00
|
|
|
$this->Task->params['exclude-plugins'] = true;
|
|
|
|
$this->Task->params['ignore-model-validation'] = false;
|
|
|
|
|
|
|
|
$this->Task->execute();
|
|
|
|
$result = file_get_contents($this->path . DS . 'test_plugin.pot');
|
|
|
|
|
2011-12-16 06:52:07 +00:00
|
|
|
$pattern = preg_quote('#Plugin' . DS . 'TestPlugin' . DS . 'Model' . DS . 'TestPluginPost.php:validation for field title#', '\\');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-06-20 05:06:31 +00:00
|
|
|
|
2011-12-16 06:52:07 +00:00
|
|
|
$pattern = preg_quote('#Plugin' . DS . 'TestPlugin' . DS . 'Model' . DS . 'TestPluginPost.php:validation for field body#', '\\');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-06-20 05:06:31 +00:00
|
|
|
|
|
|
|
$pattern = '#msgid "Post title is required"#';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-06-20 05:06:31 +00:00
|
|
|
|
|
|
|
$pattern = '#msgid "Post body is required"#';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-06-20 05:06:31 +00:00
|
|
|
|
|
|
|
$pattern = '#msgid "Post body is super required"#';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-06-20 05:06:31 +00:00
|
|
|
}
|
|
|
|
|
2011-07-07 06:40:27 +00:00
|
|
|
/**
|
|
|
|
* Test that the extract shell can obtain validation messages from models inside a specific plugin
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testExtractModelValidationInPlugin() {
|
|
|
|
App::build(array(
|
2012-02-18 12:31:29 +00:00
|
|
|
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
2011-07-07 06:40:27 +00:00
|
|
|
));
|
|
|
|
$this->out = $this->getMock('ConsoleOutput', array(), array(), '', false);
|
|
|
|
$this->in = $this->getMock('ConsoleInput', array(), array(), '', false);
|
|
|
|
$this->Task = $this->getMock('ExtractTask',
|
|
|
|
array('_isExtractingApp', 'in', 'out', 'err', 'clear', '_stop'),
|
|
|
|
array($this->out, $this->out, $this->in)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->Task->params['output'] = $this->path . DS;
|
|
|
|
$this->Task->params['ignore-model-validation'] = false;
|
|
|
|
$this->Task->params['plugin'] = 'TestPlugin';
|
|
|
|
|
|
|
|
$this->Task->execute();
|
|
|
|
$result = file_get_contents($this->path . DS . 'test_plugin.pot');
|
|
|
|
|
2012-03-11 04:32:02 +00:00
|
|
|
$pattern = preg_quote('#Model' . DS . 'TestPluginPost.php:validation for field title#', '\\');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-07-07 06:40:27 +00:00
|
|
|
|
2012-03-11 04:32:02 +00:00
|
|
|
$pattern = preg_quote('#Model' . DS . 'TestPluginPost.php:validation for field body#', '\\');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-07-07 06:40:27 +00:00
|
|
|
|
|
|
|
$pattern = '#msgid "Post title is required"#';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-07-07 06:40:27 +00:00
|
|
|
|
|
|
|
$pattern = '#msgid "Post body is required"#';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-07-07 06:40:27 +00:00
|
|
|
|
|
|
|
$pattern = '#msgid "Post body is super required"#';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-07-07 06:40:27 +00:00
|
|
|
|
|
|
|
$pattern = '#Plugin/TestPlugin/Model/TestPluginPost.php:validation for field title#';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertNotRegExp($pattern, $result);
|
2011-07-07 06:40:27 +00:00
|
|
|
}
|
2012-05-25 16:01:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that the extract shell overwrites existing files with the overwrite parameter
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testExtractOverwrite() {
|
|
|
|
$this->Task->interactive = false;
|
|
|
|
|
|
|
|
$this->Task->params['paths'] = CAKE . 'Test' . DS . 'test_app' . DS;
|
|
|
|
$this->Task->params['output'] = $this->path . DS;
|
2012-06-07 21:37:09 +00:00
|
|
|
$this->Task->params['extract-core'] = 'no';
|
2012-05-25 16:01:56 +00:00
|
|
|
$this->Task->params['overwrite'] = true;
|
|
|
|
|
|
|
|
file_put_contents($this->path . DS . 'default.pot', 'will be overwritten');
|
|
|
|
$this->assertTrue(file_exists($this->path . DS . 'default.pot'));
|
|
|
|
$original = file_get_contents($this->path . DS . 'default.pot');
|
|
|
|
|
|
|
|
$this->Task->execute();
|
|
|
|
$result = file_get_contents($this->path . DS . 'default.pot');
|
|
|
|
$this->assertNotEquals($original, $result);
|
|
|
|
}
|
2012-06-07 21:37:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
2009-02-13 06:22:34 +00:00
|
|
|
}
|