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)
|
2010-01-14 04:47:14 +00:00
|
|
|
* Copyright 2006-2010, 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.
|
|
|
|
*
|
2010-01-14 04:47:14 +00:00
|
|
|
* @copyright Copyright 2006-2010, Cake Software Foundation, Inc.
|
2009-11-06 06:00:11 +00:00
|
|
|
* @link http://cakephp.org CakePHP Project
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.console.libs.tasks
|
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
|
|
|
*/
|
2009-07-26 01:27:02 +00:00
|
|
|
App::import('Core', 'Folder');
|
|
|
|
App::import('Shell', 'Shell', false);
|
2010-10-17 19:43:20 +00:00
|
|
|
App::import('Shell', 'tasks/Extract', false);
|
2009-02-13 06:22:34 +00:00
|
|
|
|
2010-10-03 05:53:42 +00:00
|
|
|
require_once CAKE . 'console' . DS . 'shell_dispatcher.php';
|
2010-01-17 00:41:52 +00:00
|
|
|
|
2009-03-13 16:06:18 +00:00
|
|
|
/**
|
|
|
|
* ExtractTaskTest class
|
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.console.libs.tasks
|
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() {
|
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();
|
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
|
|
|
|
2009-09-15 03:43:59 +00:00
|
|
|
$this->Task->params['paths'] = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'pages';
|
2010-10-29 04:40:04 +00:00
|
|
|
$this->Task->params['output'] = $this->path . DS;
|
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
|
|
|
|
2009-03-13 16:06:18 +00:00
|
|
|
$pattern = '/"Content-Type\: text\/plain; charset\=utf-8/';
|
|
|
|
$this->assertPattern($pattern, $result);
|
|
|
|
$pattern = '/"Content-Transfer-Encoding\: 8bit/';
|
|
|
|
$this->assertPattern($pattern, $result);
|
|
|
|
$pattern = '/"Plural-Forms\: nplurals\=INTEGER; plural\=EXPRESSION;/';
|
|
|
|
$this->assertPattern($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/';
|
|
|
|
$this->assertPattern($pattern, $result);
|
|
|
|
$pattern = '/msgid "Your tmp directory is NOT writable."\nmsgstr ""\n/';
|
|
|
|
$this->assertPattern($pattern, $result);
|
|
|
|
$pattern = '/msgid "The %s is being used for caching. To change the config edit ';
|
|
|
|
$pattern .= 'APP\/config\/core.php "\nmsgstr ""\n/';
|
|
|
|
$this->assertPattern($pattern, $result);
|
|
|
|
$pattern = '/msgid "Your cache is NOT working. Please check ';
|
|
|
|
$pattern .= 'the settings in APP\/config\/core.php"\nmsgstr ""\n/';
|
|
|
|
$this->assertPattern($pattern, $result);
|
|
|
|
$pattern = '/msgid "Your database configuration file is present."\nmsgstr ""\n/';
|
|
|
|
$this->assertPattern($pattern, $result);
|
|
|
|
$pattern = '/msgid "Your database configuration file is NOT present."\nmsgstr ""\n/';
|
|
|
|
$this->assertPattern($pattern, $result);
|
|
|
|
$pattern = '/msgid "Rename config\/database.php.default to ';
|
|
|
|
$pattern .= 'config\/database.php"\nmsgstr ""\n/';
|
|
|
|
$this->assertPattern($pattern, $result);
|
|
|
|
$pattern = '/msgid "Cake is able to connect to the database."\nmsgstr ""\n/';
|
|
|
|
$this->assertPattern($pattern, $result);
|
|
|
|
$pattern = '/msgid "Cake is NOT able to connect to the database."\nmsgstr ""\n/';
|
|
|
|
$this->assertPattern($pattern, $result);
|
|
|
|
$pattern = '/msgid "Editing this Page"\nmsgstr ""\n/';
|
|
|
|
$this->assertPattern($pattern, $result);
|
|
|
|
$pattern = '/msgid "To change the content of this page, edit: %s.*To change its layout, ';
|
|
|
|
$pattern .= 'edit: %s.*You can also add some CSS styles for your pages at: %s"\nmsgstr ""/s';
|
|
|
|
$this->assertPattern($pattern, $result);
|
2009-02-13 06:22:34 +00:00
|
|
|
|
2009-08-06 21:14:25 +00:00
|
|
|
// extract.ctp
|
2010-02-12 13:52:58 +00:00
|
|
|
$pattern = '/\#: (\\\\|\/)extract\.ctp:6\n';
|
|
|
|
$pattern .= 'msgid "You have %d new message."\nmsgid_plural "You have %d new messages."/';
|
2009-08-06 21:14:25 +00:00
|
|
|
$this->assertPattern($pattern, $result);
|
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."/';
|
|
|
|
$this->assertPattern($pattern, $result);
|
|
|
|
|
|
|
|
$pattern = '/\#: (\\\\|\/)extract\.ctp:14\n';
|
2010-06-21 03:23:56 +00:00
|
|
|
$pattern .= '\#: (\\\\|\/)home\.ctp:66\n';
|
2010-02-12 13:52:58 +00:00
|
|
|
$pattern .= 'msgid "Editing this Page"\nmsgstr ""/';
|
2009-08-06 21:14:25 +00:00
|
|
|
$this->assertPattern($pattern, $result);
|
|
|
|
|
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."/';
|
|
|
|
$this->assertNoPattern($pattern, $result);
|
|
|
|
$pattern = '/msgid "You deleted %d message."\nmsgid_plural "You deleted %d messages."/';
|
|
|
|
$this->assertNoPattern($pattern, $result);
|
|
|
|
|
|
|
|
$pattern = '/msgid "You have %d new message \(domain\)."\nmsgid_plural "You have %d new messages \(domain\)."/';
|
|
|
|
$this->assertPattern($pattern, $result);
|
|
|
|
$pattern = '/msgid "You deleted %d message \(domain\)."\nmsgid_plural "You deleted %d messages \(domain\)."/';
|
|
|
|
$this->assertPattern($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
|
|
|
|
*/
|
|
|
|
function testExtractWithExclude() {
|
|
|
|
$this->Task->interactive = false;
|
|
|
|
|
|
|
|
$this->Task->params['paths'] = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views';
|
|
|
|
$this->Task->params['output'] = $this->path . DS;
|
|
|
|
$this->Task->params['exclude'] = 'pages,layouts';
|
|
|
|
|
|
|
|
$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);
|
|
|
|
|
|
|
|
$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
|
|
|
|
*/
|
|
|
|
function testExtractMultiplePaths() {
|
|
|
|
$this->Task->interactive = false;
|
|
|
|
|
|
|
|
$this->Task->params['paths'] =
|
|
|
|
TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'pages,' .
|
|
|
|
TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'posts';
|
|
|
|
|
2010-10-29 04:40:04 +00:00
|
|
|
$this->Task->params['output'] = $this->path . DS;
|
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"/';
|
|
|
|
$this->assertPattern($pattern, $result);
|
|
|
|
}
|
2009-02-13 06:22:34 +00:00
|
|
|
}
|