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
|
|
|
*
|
2017-06-10 21:33:55 +00:00
|
|
|
* CakePHP : Rapid Development Framework (https://cakephp.org)
|
2017-06-10 22:10:52 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2009-02-13 06:22:34 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00: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.
|
|
|
|
*
|
2017-06-10 22:10:52 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2017-06-10 21:33:55 +00:00
|
|
|
* @link https://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
|
2017-06-10 22:23:14 +00:00
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License
|
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
|
|
|
|
*/
|
2022-12-28 07:03:39 +00:00
|
|
|
public function setUp() : void {
|
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';
|
2013-01-23 12:45:50 +00:00
|
|
|
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
|
|
|
|
*/
|
2022-12-28 07:03:39 +00:00
|
|
|
public function tearDown() : void {
|
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/';
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression($pattern, $result);
|
2009-03-13 16:06:18 +00:00
|
|
|
$pattern = '/"Content-Transfer-Encoding\: 8bit/';
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression($pattern, $result);
|
2009-03-13 16:06:18 +00:00
|
|
|
$pattern = '/"Plural-Forms\: nplurals\=INTEGER; plural\=EXPRESSION;/';
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression($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/';
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression($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/';
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression($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 ';
|
2017-06-10 21:31:29 +00:00
|
|
|
$pattern .= '%s\/core.php "\nmsgstr ""\n/';
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression($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 ';
|
2017-06-10 21:31:29 +00:00
|
|
|
$pattern .= 'the settings in %s\/core.php"\nmsgstr ""\n/';
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression($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/';
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression($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/';
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression($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/';
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression($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/';
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression($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/';
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression($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/';
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression($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/';
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression($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';
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression($pattern, $result);
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2009-08-06 21:14:25 +00:00
|
|
|
// extract.ctp
|
2016-02-03 12:52:15 +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."/';
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression($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 ""/';
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression($pattern, $result, 'No duplicate msgid');
|
2012-02-07 02:25:11 +00:00
|
|
|
|
2016-02-03 12:52:15 +00:00
|
|
|
$pattern = '/\#: extract\.ctp:7\n';
|
2010-02-12 13:52:58 +00:00
|
|
|
$pattern .= 'msgid "You deleted %d message."\nmsgid_plural "You deleted %d messages."/';
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression($pattern, $result);
|
2010-02-12 13:52:58 +00:00
|
|
|
|
2016-02-03 12:52:15 +00:00
|
|
|
$pattern = '/\#: extract\.ctp:14\n';
|
|
|
|
$pattern .= '\#: home\.ctp:68\n';
|
2010-02-12 13:52:58 +00:00
|
|
|
$pattern .= 'msgid "Editing this Page"\nmsgstr ""/';
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression($pattern, $result);
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2016-02-03 12:52:15 +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 ""/';
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression($pattern, $result);
|
2011-03-21 05:56:07 +00:00
|
|
|
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('msgid "double \\"quoted\\""', $result, 'Strings with quotes not handled correctly');
|
|
|
|
$this->assertStringContainsString("msgid \"single 'quoted'\"", $result, 'Strings with quotes not handled correctly');
|
2012-08-30 22:48:32 +00:00
|
|
|
|
2016-02-03 12:52:15 +00:00
|
|
|
$pattern = '/\#: extract\.ctp:36\nmsgid "letter"/';
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression($pattern, $result, 'Strings with context should not overwrite strings without context');
|
2014-12-25 12:28:44 +00:00
|
|
|
|
2016-02-03 12:52:15 +00:00
|
|
|
$pattern = '/\#: extract\.ctp:37;39\nmsgctxt "A"\nmsgid "letter"/';
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression($pattern, $result, 'Should contain string with context "A"');
|
2014-12-25 12:28:44 +00:00
|
|
|
|
2016-02-03 12:52:15 +00:00
|
|
|
$pattern = '/\#: extract\.ctp:38\nmsgctxt "B"\nmsgid "letter"/';
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression($pattern, $result, 'Should contain string with context "B"');
|
2014-12-25 12:28:44 +00:00
|
|
|
|
2016-02-03 12:52:15 +00:00
|
|
|
$pattern = '/\#: extract\.ctp:40\nmsgid "%d letter"\nmsgid_plural "%d letters"/';
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression($pattern, $result, 'Plural strings with context should not overwrite strings without context');
|
2014-12-25 12:28:44 +00:00
|
|
|
|
2016-02-03 12:52:15 +00:00
|
|
|
$pattern = '/\#: extract\.ctp:41\nmsgctxt "A"\nmsgid "%d letter"\nmsgid_plural "%d letters"/';
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression($pattern, $result, 'Should contain plural string with context "A"');
|
2014-06-08 09:54:28 +00:00
|
|
|
|
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."/';
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression($pattern, $result);
|
2009-09-15 03:43:59 +00:00
|
|
|
$pattern = '/msgid "You deleted %d message."\nmsgid_plural "You deleted %d messages."/';
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression($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\)."/';
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression($pattern, $result);
|
2009-09-15 03:43:59 +00:00
|
|
|
$pattern = '/msgid "You deleted %d message \(domain\)."\nmsgid_plural "You deleted %d messages \(domain\)."/';
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression($pattern, $result);
|
2010-10-29 04:40:04 +00:00
|
|
|
}
|
2009-09-15 03:43:59 +00:00
|
|
|
|
2013-08-25 21:04:05 +00: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-23 03:39:38 +00: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 21:04:05 +00:00
|
|
|
|
|
|
|
$result = file_get_contents($this->path . DS . 'default.pot');
|
|
|
|
|
|
|
|
$pattern = '/\#: .*extract\.ctp:31\n/';
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression($pattern, $result);
|
2015-02-23 03:39:38 +00:00
|
|
|
|
|
|
|
$pattern = '/\#: .*extract\.ctp:33\n/';
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression($pattern, $result);
|
2013-08-25 21:04:05 +00:00
|
|
|
}
|
|
|
|
|
2015-07-14 03:04:04 +00:00
|
|
|
/**
|
2015-07-13 03:54:11 +00:00
|
|
|
* testExtractWithoutLocations method
|
2015-07-13 02:08:50 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2015-07-13 03:54:11 +00:00
|
|
|
public function testExtractWithoutLocations() {
|
2015-07-13 02:08:50 +00: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 22:47:26 +00:00
|
|
|
$this->Task->params['no-location'] = true;
|
2015-07-13 02:08:50 +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');
|
|
|
|
|
|
|
|
$this->Task->execute();
|
2015-07-13 02:30:14 +00:00
|
|
|
$this->assertTrue(file_exists($this->path . DS . 'default.pot'));
|
2015-07-13 02:08:50 +00:00
|
|
|
|
|
|
|
$result = file_get_contents($this->path . DS . 'default.pot');
|
|
|
|
|
|
|
|
$pattern = '/\n\#: .*\n/';
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression($pattern, $result);
|
2015-07-13 02:08:50 +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/';
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression($pattern, $result);
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2010-10-29 04:40:04 +00:00
|
|
|
$pattern = '/\#: .*default\.ctp:26\n/';
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression($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"/';
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression($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');
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('#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',
|
2013-07-06 12:58:38 +00:00
|
|
|
array('_isExtractingApp', 'in', 'out', 'err', 'clear', '_stop'),
|
2011-07-07 06:27:55 +00:00
|
|
|
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');
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('#Pages#', $result);
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('translate.ctp:1', $result);
|
|
|
|
$this->assertStringContainsString('This is a translatable string', $result);
|
|
|
|
$this->assertStringContainsString('I can haz plugin model validation message', $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');
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('Model/PersisterOne.php:validation for field title', $result);
|
|
|
|
$this->assertStringContainsString('Model/PersisterOne.php:validation for field body', $result);
|
|
|
|
$this->assertStringContainsString('msgid "Post title is required"', $result);
|
|
|
|
$this->assertStringContainsString('msgid "You may enter up to %s chars (minimum is %s chars)"', $result);
|
|
|
|
$this->assertStringContainsString('msgid "Post body is required"', $result);
|
|
|
|
$this->assertStringContainsString('msgid "Post body is super required"', $result);
|
|
|
|
$this->assertStringContainsString('msgid "double \\"quoted\\" validation"', $result, 'Strings with quotes not handled correctly');
|
|
|
|
$this->assertStringContainsString("msgid \"single 'quoted' validation\"", $result, 'Strings with quotes not handled correctly');
|
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');
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('Plugin/TestPlugin/Model/TestPluginPost.php:validation for field title', $result);
|
|
|
|
$this->assertStringContainsString('Plugin/TestPlugin/Model/TestPluginPost.php:validation for field body', $result);
|
|
|
|
$this->assertStringContainsString('msgid "Post title is required"', $result);
|
|
|
|
$this->assertStringContainsString('msgid "Post body is required"', $result);
|
|
|
|
$this->assertStringContainsString('msgid "Post body is super required"', $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');
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('Model/TestPluginPost.php:validation for field title', $result);
|
|
|
|
$this->assertStringContainsString('Model/TestPluginPost.php:validation for field body', $result);
|
|
|
|
$this->assertStringContainsString('msgid "Post title is required"', $result);
|
|
|
|
$this->assertStringContainsString('msgid "Post body is required"', $result);
|
|
|
|
$this->assertStringContainsString('msgid "Post body is super required"', $result);
|
2022-12-30 09:44:36 +00:00
|
|
|
$this->assertStringNotContainsString('Plugin/TestPlugin/Model/TestPluginPost.php:validation for field title', $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/';
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression($pattern, $result);
|
2012-06-07 21:37:09 +00:00
|
|
|
|
|
|
|
$this->assertTrue(file_exists($this->path . DS . 'cake_dev.pot'));
|
|
|
|
$result = file_get_contents($this->path . DS . 'cake_dev.pot');
|
|
|
|
|
|
|
|
$pattern = '/#: Console\/Templates\//';
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression($pattern, $result);
|
2012-06-07 21:37:09 +00:00
|
|
|
|
|
|
|
$pattern = '/#: Test\//';
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression($pattern, $result);
|
2012-06-07 21:37:09 +00:00
|
|
|
}
|
2009-02-13 06:22:34 +00:00
|
|
|
}
|