comparison cake/tests/cases/console/libs/tasks/extract.test.php @ 0:261e66bd5a0c

hg init
author Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
date Sun, 24 Jul 2011 21:08:31 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:261e66bd5a0c
1 <?php
2 /**
3 * ExtractTaskTest file
4 *
5 * Test Case for i18n extraction shell task
6 *
7 * PHP versions 4 and 5
8 *
9 * CakePHP : Rapid Development Framework (http://cakephp.org)
10 * Copyright 2006-2010, Cake Software Foundation, Inc.
11 *
12 * Licensed under The MIT License
13 * Redistributions of files must retain the above copyright notice.
14 *
15 * @copyright Copyright 2006-2010, Cake Software Foundation, Inc.
16 * @link http://cakephp.org CakePHP Project
17 * @package cake
18 * @subpackage cake.tests.cases.console.libs.tasks
19 * @since CakePHP v 1.2.0.7726
20 * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
21 */
22 App::import('Core', 'Folder');
23 App::import('Shell', 'Shell', false);
24
25 if (!defined('DISABLE_AUTO_DISPATCH')) {
26 define('DISABLE_AUTO_DISPATCH', true);
27 }
28
29 if (!class_exists('ShellDispatcher')) {
30 ob_start();
31 $argv = false;
32 require CAKE . 'console' . DS . 'cake.php';
33 ob_end_clean();
34 }
35
36 require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'extract.php';
37
38
39 Mock::generatePartial(
40 'ShellDispatcher', 'TestExtractTaskMockShellDispatcher',
41 array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
42 );
43
44 /**
45 * ExtractTaskTest class
46 *
47 * @package cake
48 * @subpackage cake.tests.cases.console.libs.tasks
49 */
50 class ExtractTaskTest extends CakeTestCase {
51
52 /**
53 * setUp method
54 *
55 * @return void
56 * @access public
57 */
58 function setUp() {
59 $this->Dispatcher =& new TestExtractTaskMockShellDispatcher();
60 $this->Task =& new ExtractTask($this->Dispatcher);
61 }
62
63 /**
64 * tearDown method
65 *
66 * @return void
67 * @access public
68 */
69 function tearDown() {
70 ClassRegistry::flush();
71 }
72
73 /**
74 * testExecute method
75 *
76 * @return void
77 * @access public
78 */
79 function testExecute() {
80 $path = TMP . 'tests' . DS . 'extract_task_test';
81 new Folder($path . DS . 'locale', true);
82
83 $this->Task->interactive = false;
84
85 $this->Task->params['paths'] = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'pages';
86 $this->Task->params['output'] = $path . DS;
87 $this->Task->Dispatch->expectNever('stderr');
88 $this->Task->Dispatch->expectNever('_stop');
89 $this->Task->execute();
90 $this->assertTrue(file_exists($path . DS . 'default.pot'));
91 $result = file_get_contents($path . DS . 'default.pot');
92
93 $pattern = '/"Content-Type\: text\/plain; charset\=utf-8/';
94 $this->assertPattern($pattern, $result);
95 $pattern = '/"Content-Transfer-Encoding\: 8bit/';
96 $this->assertPattern($pattern, $result);
97 $pattern = '/"Plural-Forms\: nplurals\=INTEGER; plural\=EXPRESSION;/';
98 $this->assertPattern($pattern, $result);
99
100 // home.ctp
101 $pattern = '/msgid "Your tmp directory is writable."\nmsgstr ""\n/';
102 $this->assertPattern($pattern, $result);
103 $pattern = '/msgid "Your tmp directory is NOT writable."\nmsgstr ""\n/';
104 $this->assertPattern($pattern, $result);
105 $pattern = '/msgid "The %s is being used for caching. To change the config edit ';
106 $pattern .= 'APP\/config\/core.php "\nmsgstr ""\n/';
107 $this->assertPattern($pattern, $result);
108 $pattern = '/msgid "Your cache is NOT working. Please check ';
109 $pattern .= 'the settings in APP\/config\/core.php"\nmsgstr ""\n/';
110 $this->assertPattern($pattern, $result);
111 $pattern = '/msgid "Your database configuration file is present."\nmsgstr ""\n/';
112 $this->assertPattern($pattern, $result);
113 $pattern = '/msgid "Your database configuration file is NOT present."\nmsgstr ""\n/';
114 $this->assertPattern($pattern, $result);
115 $pattern = '/msgid "Rename config\/database.php.default to ';
116 $pattern .= 'config\/database.php"\nmsgstr ""\n/';
117 $this->assertPattern($pattern, $result);
118 $pattern = '/msgid "Cake is able to connect to the database."\nmsgstr ""\n/';
119 $this->assertPattern($pattern, $result);
120 $pattern = '/msgid "Cake is NOT able to connect to the database."\nmsgstr ""\n/';
121 $this->assertPattern($pattern, $result);
122 $pattern = '/msgid "Editing this Page"\nmsgstr ""\n/';
123 $this->assertPattern($pattern, $result);
124 $pattern = '/msgid "To change the content of this page, edit: %s.*To change its layout, ';
125 $pattern .= 'edit: %s.*You can also add some CSS styles for your pages at: %s"\nmsgstr ""/s';
126 $this->assertPattern($pattern, $result);
127
128 // extract.ctp
129 $pattern = '/\#: (\\\\|\/)extract\.ctp:6\n';
130 $pattern .= 'msgid "You have %d new message."\nmsgid_plural "You have %d new messages."/';
131 $this->assertPattern($pattern, $result);
132
133 $pattern = '/\#: (\\\\|\/)extract\.ctp:7\n';
134 $pattern .= 'msgid "You deleted %d message."\nmsgid_plural "You deleted %d messages."/';
135 $this->assertPattern($pattern, $result);
136
137 $pattern = '/\#: (\\\\|\/)extract\.ctp:14\n';
138 $pattern .= '\#: (\\\\|\/)home\.ctp:74\n';
139 $pattern .= 'msgid "Editing this Page"\nmsgstr ""/';
140 $this->assertPattern($pattern, $result);
141
142 // extract.ctp - reading the domain.pot
143 $result = file_get_contents($path . DS . 'domain.pot');
144
145 $pattern = '/msgid "You have %d new message."\nmsgid_plural "You have %d new messages."/';
146 $this->assertNoPattern($pattern, $result);
147 $pattern = '/msgid "You deleted %d message."\nmsgid_plural "You deleted %d messages."/';
148 $this->assertNoPattern($pattern, $result);
149
150 $pattern = '/msgid "You have %d new message \(domain\)."\nmsgid_plural "You have %d new messages \(domain\)."/';
151 $this->assertPattern($pattern, $result);
152 $pattern = '/msgid "You deleted %d message \(domain\)."\nmsgid_plural "You deleted %d messages \(domain\)."/';
153 $this->assertPattern($pattern, $result);
154
155 $Folder = new Folder($path);
156 $Folder->delete();
157 }
158 function getTests() {
159 return array('start', 'startCase', 'testExtractMultiplePaths', 'endCase', 'end');
160 }
161
162 /**
163 * test extract can read more than one path.
164 *
165 * @return void
166 */
167 function testExtractMultiplePaths() {
168 $path = TMP . 'tests' . DS . 'extract_task_test';
169 new Folder($path . DS . 'locale', true);
170
171 $this->Task->interactive = false;
172
173 $this->Task->params['paths'] =
174 TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'pages,' .
175 TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'posts';
176
177 $this->Task->params['output'] = $path . DS;
178 $this->Task->Dispatch->expectNever('stderr');
179 $this->Task->Dispatch->expectNever('_stop');
180 $this->Task->execute();
181
182 $result = file_get_contents($path . DS . 'default.pot');
183
184 $pattern = '/msgid "Add User"/';
185 $this->assertPattern($pattern, $result);
186 }
187 }