2009-02-13 06:22:34 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-19 14:10:13 -07:00
|
|
|
* ExtractTaskTest file
|
2009-02-13 06:22:34 +00:00
|
|
|
*
|
2009-03-19 14:10:13 -07:00
|
|
|
* Test Case for i18n extraction shell task
|
2009-02-13 06:22:34 +00:00
|
|
|
*
|
2010-01-26 17:15:15 -05:00
|
|
|
* CakePHP : Rapid Development Framework (http://cakephp.org)
|
2013-02-08 21:28:17 +09:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2009-02-13 06:22:34 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
2013-02-08 21:22:51 +09:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2009-02-13 06:22:34 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2013-02-08 21:28:17 +09:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2009-11-06 17:00:11 +11:00
|
|
|
* @link http://cakephp.org CakePHP Project
|
2011-07-26 01:46:14 -04:30
|
|
|
* @package Cake.Test.Case.Console.Command.Task
|
2009-02-13 06:22:34 +00:00
|
|
|
* @since CakePHP v 1.2.0.7726
|
2013-05-31 00:11:14 +02:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
2009-02-13 06:22:34 +00:00
|
|
|
*/
|
|
|
|
|
2010-12-08 23:15:18 -04:30
|
|
|
App::uses('Folder', 'Utility');
|
2012-05-25 23:27:40 +07:00
|
|
|
App::uses('ConsoleOutput', 'Console');
|
|
|
|
App::uses('ConsoleInput', 'Console');
|
2010-12-08 23:15:18 -04:30
|
|
|
App::uses('ShellDispatcher', 'Console');
|
|
|
|
App::uses('Shell', 'Console');
|
|
|
|
App::uses('ExtractTask', 'Console/Command/Task');
|
2010-01-16 19:41:52 -05:00
|
|
|
|
2009-03-13 16:06:18 +00:00
|
|
|
/**
|
|
|
|
* ExtractTaskTest class
|
|
|
|
*
|
2011-07-26 01:46:14 -04:30
|
|
|
* @package Cake.Test.Case.Console.Command.Task
|
2009-03-13 16:06:18 +00:00
|
|
|
*/
|
|
|
|
class ExtractTaskTest extends CakeTestCase {
|
2009-07-24 21:18:37 +02:00
|
|
|
|
2009-03-13 16:06:18 +00:00
|
|
|
/**
|
|
|
|
* setUp method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 13:19:38 +10:00
|
|
|
public function setUp() {
|
2011-09-03 23:21:27 +01:00
|
|
|
parent::setUp();
|
2010-10-06 22:52:42 -04:00
|
|
|
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
|
|
|
|
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
|
|
|
|
|
2010-10-24 15:27:04 -04:00
|
|
|
$this->Task = $this->getMock(
|
|
|
|
'ExtractTask',
|
|
|
|
array('in', 'out', 'err', '_stop'),
|
|
|
|
array($out, $out, $in)
|
|
|
|
);
|
2010-10-29 00:40:04 -04:00
|
|
|
$this->path = TMP . 'tests' . DS . 'extract_task_test';
|
2013-01-23 13:45:50 +01:00
|
|
|
new Folder($this->path . DS . 'locale', true);
|
2009-02-13 06:22:34 +00:00
|
|
|
}
|
2009-07-24 21:18:37 +02:00
|
|
|
|
2009-03-13 16:06:18 +00:00
|
|
|
/**
|
|
|
|
* tearDown method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 13:19:38 +10:00
|
|
|
public function tearDown() {
|
2010-10-06 22:52:42 -04:00
|
|
|
parent::tearDown();
|
2010-10-24 15:27:04 -04:00
|
|
|
unset($this->Task);
|
2010-10-29 00:40:04 -04:00
|
|
|
|
|
|
|
$Folder = new Folder($this->path);
|
|
|
|
$Folder->delete();
|
2011-07-07 02:10:27 -04:30
|
|
|
CakePlugin::unload();
|
2009-02-13 06:22:34 +00:00
|
|
|
}
|
2009-07-24 21:18:37 +02:00
|
|
|
|
2009-03-13 16:06:18 +00:00
|
|
|
/**
|
|
|
|
* testExecute method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 13:19:38 +10: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 12:35:21 +02:00
|
|
|
$this->Task->params['paths'] = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Pages';
|
2010-10-29 00:40:04 -04:00
|
|
|
$this->Task->params['output'] = $this->path . DS;
|
2012-06-07 22:37:09 +01:00
|
|
|
$this->Task->params['extract-core'] = 'no';
|
2010-10-24 15:27:04 -04: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-20 23:23:56 -04:00
|
|
|
|
2009-03-13 16:06:18 +00:00
|
|
|
$this->Task->execute();
|
2010-10-29 00:40:04 -04: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 22:37:09 +01: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-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2009-03-13 16:06:18 +00:00
|
|
|
$pattern = '/"Content-Transfer-Encoding\: 8bit/';
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2009-03-13 16:06:18 +00:00
|
|
|
$pattern = '/"Plural-Forms\: nplurals\=INTEGER; plural\=EXPRESSION;/';
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2009-02-13 06:22:34 +00:00
|
|
|
|
2009-08-06 18:14:25 -03:00
|
|
|
// home.ctp
|
2009-03-13 16:06:18 +00:00
|
|
|
$pattern = '/msgid "Your tmp directory is writable."\nmsgstr ""\n/';
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2012-02-06 21:25:11 -05:00
|
|
|
|
2009-03-13 16:06:18 +00:00
|
|
|
$pattern = '/msgid "Your tmp directory is NOT writable."\nmsgstr ""\n/';
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2012-02-06 21:25:11 -05: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-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2012-02-06 21:25:11 -05: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-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2012-02-06 21:25:11 -05:00
|
|
|
|
2009-03-13 16:06:18 +00:00
|
|
|
$pattern = '/msgid "Your database configuration file is present."\nmsgstr ""\n/';
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2012-02-06 21:25:11 -05:00
|
|
|
|
2009-03-13 16:06:18 +00:00
|
|
|
$pattern = '/msgid "Your database configuration file is NOT present."\nmsgstr ""\n/';
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2012-03-10 23:32:02 -05: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-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2012-02-06 21:25:11 -05:00
|
|
|
|
2009-03-13 16:06:18 +00:00
|
|
|
$pattern = '/msgid "Cake is able to connect to the database."\nmsgstr ""\n/';
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2012-02-06 21:25:11 -05:00
|
|
|
|
2009-03-13 16:06:18 +00:00
|
|
|
$pattern = '/msgid "Cake is NOT able to connect to the database."\nmsgstr ""\n/';
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2012-02-06 21:25:11 -05:00
|
|
|
|
2009-03-13 16:06:18 +00:00
|
|
|
$pattern = '/msgid "Editing this Page"\nmsgstr ""\n/';
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2012-02-06 21:25:11 -05:00
|
|
|
|
2011-03-21 01:26:07 -04:30
|
|
|
$pattern = '/msgid "To change the content of this page, create: APP\/views\/pages\/home\.ctp/';
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2009-02-13 06:22:34 +00:00
|
|
|
|
2011-03-21 01:26:07 -04:30
|
|
|
$pattern = '/To change its layout, create: APP\/views\/layouts\/default\.ctp\./s';
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-04-17 12:35:21 +02:00
|
|
|
|
2009-08-06 18:14:25 -03:00
|
|
|
// extract.ctp
|
2016-02-03 14:52:15 +02:00
|
|
|
$pattern = '/\#: extract\.ctp:15;6\n';
|
2010-02-12 11:52:58 -02:00
|
|
|
$pattern .= 'msgid "You have %d new message."\nmsgid_plural "You have %d new messages."/';
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2010-02-12 11:52:58 -02:00
|
|
|
|
2012-02-06 21:25:11 -05:00
|
|
|
$pattern = '/msgid "You have %d new message."\nmsgstr ""/';
|
|
|
|
$this->assertNotRegExp($pattern, $result, 'No duplicate msgid');
|
|
|
|
|
2016-02-03 14:52:15 +02:00
|
|
|
$pattern = '/\#: extract\.ctp:7\n';
|
2010-02-12 11:52:58 -02:00
|
|
|
$pattern .= 'msgid "You deleted %d message."\nmsgid_plural "You deleted %d messages."/';
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2010-02-12 11:52:58 -02:00
|
|
|
|
2016-02-03 14:52:15 +02:00
|
|
|
$pattern = '/\#: extract\.ctp:14\n';
|
|
|
|
$pattern .= '\#: home\.ctp:68\n';
|
2010-02-12 11:52:58 -02:00
|
|
|
$pattern .= 'msgid "Editing this Page"\nmsgstr ""/';
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-04-17 12:35:21 +02:00
|
|
|
|
2016-02-03 14:52:15 +02:00
|
|
|
$pattern = '/\#: extract\.ctp:22\nmsgid "';
|
2011-04-25 19:22:14 +02: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-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-03-21 01:26:07 -04:30
|
|
|
|
2012-08-30 23:48:32 +01: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');
|
|
|
|
|
2016-02-03 14:52:15 +02:00
|
|
|
$pattern = '/\#: extract\.ctp:36\nmsgid "letter"/';
|
2014-12-25 14:28:44 +02:00
|
|
|
$this->assertRegExp($pattern, $result, 'Strings with context should not overwrite strings without context');
|
|
|
|
|
2016-02-03 14:52:15 +02:00
|
|
|
$pattern = '/\#: extract\.ctp:37;39\nmsgctxt "A"\nmsgid "letter"/';
|
2014-12-25 14:28:44 +02:00
|
|
|
$this->assertRegExp($pattern, $result, 'Should contain string with context "A"');
|
|
|
|
|
2016-02-03 14:52:15 +02:00
|
|
|
$pattern = '/\#: extract\.ctp:38\nmsgctxt "B"\nmsgid "letter"/';
|
2014-12-25 14:28:44 +02:00
|
|
|
$this->assertRegExp($pattern, $result, 'Should contain string with context "B"');
|
|
|
|
|
2016-02-03 14:52:15 +02:00
|
|
|
$pattern = '/\#: extract\.ctp:40\nmsgid "%d letter"\nmsgid_plural "%d letters"/';
|
2014-12-25 14:28:44 +02:00
|
|
|
$this->assertRegExp($pattern, $result, 'Plural strings with context should not overwrite strings without context');
|
|
|
|
|
2016-02-03 14:52:15 +02:00
|
|
|
$pattern = '/\#: extract\.ctp:41\nmsgctxt "A"\nmsgid "%d letter"\nmsgid_plural "%d letters"/';
|
2014-12-25 14:28:44 +02:00
|
|
|
$this->assertRegExp($pattern, $result, 'Should contain plural string with context "A"');
|
2014-06-08 11:54:28 +02:00
|
|
|
|
2009-09-15 00:43:59 -03:00
|
|
|
// extract.ctp - reading the domain.pot
|
2010-10-29 00:40:04 -04:00
|
|
|
$result = file_get_contents($this->path . DS . 'domain.pot');
|
2009-09-15 00:43:59 -03:00
|
|
|
|
|
|
|
$pattern = '/msgid "You have %d new message."\nmsgid_plural "You have %d new messages."/';
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertNotRegExp($pattern, $result);
|
2009-09-15 00:43:59 -03:00
|
|
|
$pattern = '/msgid "You deleted %d message."\nmsgid_plural "You deleted %d messages."/';
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertNotRegExp($pattern, $result);
|
2009-09-15 00:43:59 -03:00
|
|
|
|
|
|
|
$pattern = '/msgid "You have %d new message \(domain\)."\nmsgid_plural "You have %d new messages \(domain\)."/';
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2009-09-15 00:43:59 -03:00
|
|
|
$pattern = '/msgid "You deleted %d message \(domain\)."\nmsgid_plural "You deleted %d messages \(domain\)."/';
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2010-10-29 00:40:04 -04:00
|
|
|
}
|
2009-09-15 00:43:59 -03:00
|
|
|
|
2013-08-25 23:04:05 +02:00
|
|
|
/**
|
|
|
|
* testExtractCategory method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testExtractCategory() {
|
|
|
|
$this->Task->interactive = false;
|
|
|
|
|
|
|
|
$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->params['merge'] = 'no';
|
|
|
|
$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');
|
|
|
|
|
|
|
|
$this->Task->execute();
|
2015-02-22 22:39:38 -05:00
|
|
|
$this->assertTrue(file_exists($this->path . DS . 'LC_NUMERIC' . DS . 'default.pot'));
|
|
|
|
$this->assertFalse(file_exists($this->path . DS . 'LC_TIME' . DS . 'default.pot'));
|
2013-08-25 23:04:05 +02:00
|
|
|
|
|
|
|
$result = file_get_contents($this->path . DS . 'default.pot');
|
|
|
|
|
|
|
|
$pattern = '/\#: .*extract\.ctp:31\n/';
|
|
|
|
$this->assertNotRegExp($pattern, $result);
|
2015-02-22 22:39:38 -05:00
|
|
|
|
|
|
|
$pattern = '/\#: .*extract\.ctp:33\n/';
|
|
|
|
$this->assertNotRegExp($pattern, $result);
|
2013-08-25 23:04:05 +02:00
|
|
|
}
|
|
|
|
|
2015-07-14 00:04:04 -03:00
|
|
|
/**
|
2015-07-13 00:54:11 -03:00
|
|
|
* testExtractWithoutLocations method
|
2015-07-12 23:08:50 -03:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2015-07-13 00:54:11 -03:00
|
|
|
public function testExtractWithoutLocations() {
|
2015-07-12 23:08:50 -03:00
|
|
|
$this->Task->interactive = false;
|
|
|
|
|
|
|
|
$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->params['merge'] = 'no';
|
2015-07-13 19:47:26 -03:00
|
|
|
$this->Task->params['no-location'] = true;
|
2015-07-12 23:08:50 -03: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');
|
|
|
|
|
|
|
|
$this->Task->execute();
|
2015-07-12 23:30:14 -03:00
|
|
|
$this->assertTrue(file_exists($this->path . DS . 'default.pot'));
|
2015-07-12 23:08:50 -03:00
|
|
|
|
|
|
|
$result = file_get_contents($this->path . DS . 'default.pot');
|
|
|
|
|
|
|
|
$pattern = '/\n\#: .*\n/';
|
|
|
|
$this->assertNotRegExp($pattern, $result);
|
|
|
|
}
|
|
|
|
|
2010-10-29 00:40:04 -04:00
|
|
|
/**
|
|
|
|
* test exclusions
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 22:02:32 +02:00
|
|
|
public function testExtractWithExclude() {
|
2010-10-29 00:40:04 -04:00
|
|
|
$this->Task->interactive = false;
|
|
|
|
|
2011-04-17 12:35:21 +02:00
|
|
|
$this->Task->params['paths'] = CAKE . 'Test' . DS . 'test_app' . DS . 'View';
|
2010-10-29 00:40:04 -04:00
|
|
|
$this->Task->params['output'] = $this->path . DS;
|
2011-05-14 23:40:09 -04:30
|
|
|
$this->Task->params['exclude'] = 'Pages,Layouts';
|
2012-06-07 22:37:09 +01:00
|
|
|
$this->Task->params['extract-core'] = 'no';
|
2010-10-29 00:40:04 -04: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 12:35:21 +02:00
|
|
|
|
2010-10-29 00:40:04 -04:00
|
|
|
$pattern = '/\#: .*default\.ctp:26\n/';
|
|
|
|
$this->assertNotRegExp($pattern, $result);
|
2009-02-13 06:22:34 +00:00
|
|
|
}
|
2010-06-06 22:39:04 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* test extract can read more than one path.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 22:02:32 +02:00
|
|
|
public function testExtractMultiplePaths() {
|
2010-06-06 22:39:04 -04:00
|
|
|
$this->Task->interactive = false;
|
|
|
|
|
2011-04-17 12:35:21 +02: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 00:40:04 -04:00
|
|
|
$this->Task->params['output'] = $this->path . DS;
|
2012-06-07 22:37:09 +01:00
|
|
|
$this->Task->params['extract-core'] = 'no';
|
2010-10-24 15:27:04 -04:00
|
|
|
$this->Task->expects($this->never())->method('err');
|
|
|
|
$this->Task->expects($this->never())->method('_stop');
|
2010-06-06 22:39:04 -04:00
|
|
|
$this->Task->execute();
|
|
|
|
|
2010-10-29 00:40:04 -04:00
|
|
|
$result = file_get_contents($this->path . DS . 'default.pot');
|
2010-06-06 22:39:04 -04:00
|
|
|
|
|
|
|
$pattern = '/msgid "Add User"/';
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2010-06-06 22:39:04 -04:00
|
|
|
}
|
2011-05-27 15:49:15 -04:30
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 04:31:29 -08:00
|
|
|
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
2011-05-27 15:49:15 -04:30
|
|
|
));
|
|
|
|
$this->out = $this->getMock('ConsoleOutput', array(), array(), '', false);
|
|
|
|
$this->in = $this->getMock('ConsoleInput', array(), array(), '', false);
|
|
|
|
$this->Task = $this->getMock('ExtractTask',
|
2011-05-27 22:18:56 -04:30
|
|
|
array('_isExtractingApp', '_extractValidationMessages', 'in', 'out', 'err', 'clear', '_stop'),
|
2011-05-27 15:49:15 -04:30
|
|
|
array($this->out, $this->out, $this->in)
|
|
|
|
);
|
2011-05-27 22:18:56 -04:30
|
|
|
$this->Task->expects($this->exactly(2))->method('_isExtractingApp')->will($this->returnValue(true));
|
2011-05-27 15:49:15 -04:30
|
|
|
|
|
|
|
$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-15 16:07:56 -08:00
|
|
|
$this->assertNotRegExp('#TestPlugin#', $result);
|
2011-07-07 01:57:55 -04:30
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that is possible to extract messages form a single plugin
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testExtractPlugin() {
|
|
|
|
App::build(array(
|
2012-02-18 04:31:29 -08:00
|
|
|
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
2011-07-07 01:57:55 -04:30
|
|
|
));
|
|
|
|
|
|
|
|
$this->out = $this->getMock('ConsoleOutput', array(), array(), '', false);
|
|
|
|
$this->in = $this->getMock('ConsoleInput', array(), array(), '', false);
|
|
|
|
$this->Task = $this->getMock('ExtractTask',
|
2013-07-06 19:58:38 +07:00
|
|
|
array('_isExtractingApp', 'in', 'out', 'err', 'clear', '_stop'),
|
2011-07-07 01:57:55 -04:30
|
|
|
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-15 16:07:56 -08:00
|
|
|
$this->assertNotRegExp('#Pages#', $result);
|
2011-07-07 01:57:55 -04:30
|
|
|
$this->assertContains('translate.ctp:1', $result);
|
|
|
|
$this->assertContains('This is a translatable string', $result);
|
2013-07-06 19:58:38 +07:00
|
|
|
$this->assertContains('I can haz plugin model validation message', $result);
|
2011-05-27 15:49:15 -04:30
|
|
|
}
|
2011-05-27 22:18:56 -04:30
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 00:36:31 -04:30
|
|
|
'Model' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Model' . DS),
|
2012-02-18 04:31:29 -08:00
|
|
|
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
2011-06-20 01:34:25 -04:30
|
|
|
), App::RESET);
|
2011-05-27 22:18:56 -04:30
|
|
|
$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 22:37:09 +01:00
|
|
|
$this->Task->params['extract-core'] = 'no';
|
2011-05-27 22:18:56 -04:30
|
|
|
$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');
|
|
|
|
|
2012-10-25 17:37:35 +02:00
|
|
|
$pattern = preg_quote('#Model/PersisterOne.php:validation for field title#', '\\');
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-05-27 22:18:56 -04:30
|
|
|
|
2012-10-25 17:37:35 +02:00
|
|
|
$pattern = preg_quote('#Model/PersisterOne.php:validation for field body#', '\\');
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-05-27 22:18:56 -04:30
|
|
|
|
|
|
|
$pattern = '#msgid "Post title is required"#';
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-05-27 22:18:56 -04:30
|
|
|
|
2011-07-31 06:33:56 +05:30
|
|
|
$pattern = '#msgid "You may enter up to %s chars \(minimum is %s chars\)"#';
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-07-31 06:33:56 +05:30
|
|
|
|
2011-05-27 22:18:56 -04:30
|
|
|
$pattern = '#msgid "Post body is required"#';
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-05-27 22:18:56 -04:30
|
|
|
|
|
|
|
$pattern = '#msgid "Post body is super required"#';
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2014-01-29 12:59:49 +01:00
|
|
|
|
|
|
|
$this->assertContains('msgid "double \\"quoted\\" validation"', $result, 'Strings with quotes not handled correctly');
|
|
|
|
$this->assertContains("msgid \"single 'quoted' validation\"", $result, 'Strings with quotes not handled correctly');
|
2011-05-27 22:18:56 -04:30
|
|
|
}
|
2011-06-20 00:36:31 -04:30
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 22:37:09 +01:00
|
|
|
$this->Task->params['extract-core'] = 'no';
|
2011-06-20 00:36:31 -04:30
|
|
|
$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');
|
|
|
|
|
2012-10-25 17:37:35 +02:00
|
|
|
$pattern = preg_quote('#Plugin/TestPlugin/Model/TestPluginPost.php:validation for field title#', '\\');
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-06-20 00:36:31 -04:30
|
|
|
|
2012-10-25 17:37:35 +02:00
|
|
|
$pattern = preg_quote('#Plugin/TestPlugin/Model/TestPluginPost.php:validation for field body#', '\\');
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-06-20 00:36:31 -04:30
|
|
|
|
|
|
|
$pattern = '#msgid "Post title is required"#';
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-06-20 00:36:31 -04:30
|
|
|
|
|
|
|
$pattern = '#msgid "Post body is required"#';
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-06-20 00:36:31 -04:30
|
|
|
|
|
|
|
$pattern = '#msgid "Post body is super required"#';
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-06-20 00:36:31 -04:30
|
|
|
}
|
|
|
|
|
2011-07-07 02:10:27 -04:30
|
|
|
/**
|
|
|
|
* 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 04:31:29 -08:00
|
|
|
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
2011-07-07 02:10:27 -04:30
|
|
|
));
|
|
|
|
$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-10-25 17:37:35 +02:00
|
|
|
$pattern = preg_quote('#Model/TestPluginPost.php:validation for field title#', '\\');
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-07-07 02:10:27 -04:30
|
|
|
|
2012-10-25 17:37:35 +02:00
|
|
|
$pattern = preg_quote('#Model/TestPluginPost.php:validation for field body#', '\\');
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-07-07 02:10:27 -04:30
|
|
|
|
|
|
|
$pattern = '#msgid "Post title is required"#';
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-07-07 02:10:27 -04:30
|
|
|
|
|
|
|
$pattern = '#msgid "Post body is required"#';
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-07-07 02:10:27 -04:30
|
|
|
|
|
|
|
$pattern = '#msgid "Post body is super required"#';
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertRegExp($pattern, $result);
|
2011-07-07 02:10:27 -04:30
|
|
|
|
|
|
|
$pattern = '#Plugin/TestPlugin/Model/TestPluginPost.php:validation for field title#';
|
2011-11-15 16:07:56 -08:00
|
|
|
$this->assertNotRegExp($pattern, $result);
|
2011-07-07 02:10:27 -04:30
|
|
|
}
|
2012-05-25 17:01:56 +01: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 22:37:09 +01:00
|
|
|
$this->Task->params['extract-core'] = 'no';
|
2012-05-25 17:01:56 +01: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 22:37:09 +01: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
|
|
|
}
|