Mercurial > hg > Members > shoshi > webvirt
comparison cake/tests/cases/console/libs/tasks/template.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 * TemplateTask file | |
4 * | |
5 * Test Case for TemplateTask generation shell task | |
6 * | |
7 * | |
8 * PHP versions 4 and 5 | |
9 * | |
10 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | |
11 * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) | |
12 * | |
13 * Licensed under The MIT License | |
14 * Redistributions of files must retain the above copyright notice. | |
15 * | |
16 * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) | |
17 * @link http://cakephp.org CakePHP(tm) Project | |
18 * @package cake | |
19 * @subpackage cake.tests.cases.console.libs.tasks | |
20 * @since CakePHP(tm) v 1.3 | |
21 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) | |
22 */ | |
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 . 'template.php'; | |
37 | |
38 Mock::generatePartial( | |
39 'ShellDispatcher', 'TestTemplateTaskMockShellDispatcher', | |
40 array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment') | |
41 ); | |
42 | |
43 Mock::generatePartial( | |
44 'TemplateTask', 'MockTemplateTask', | |
45 array('in', 'out', 'err', 'createFile', '_stop') | |
46 ); | |
47 | |
48 /** | |
49 * TemplateTaskTest class | |
50 * | |
51 * @package cake | |
52 * @subpackage cake.tests.cases.console.libs.tasks | |
53 */ | |
54 class TemplateTaskTest extends CakeTestCase { | |
55 | |
56 /** | |
57 * startTest method | |
58 * | |
59 * @return void | |
60 * @access public | |
61 */ | |
62 function startTest() { | |
63 $this->Dispatcher =& new TestTemplateTaskMockShellDispatcher(); | |
64 $this->Task =& new MockTemplateTask($this->Dispatcher); | |
65 $this->Task->Dispatch =& $this->Dispatcher; | |
66 $this->Task->Dispatch->shellPaths = App::path('shells'); | |
67 } | |
68 | |
69 /** | |
70 * endTest method | |
71 * | |
72 * @return void | |
73 * @access public | |
74 */ | |
75 function endTest() { | |
76 unset($this->Task, $this->Dispatcher); | |
77 ClassRegistry::flush(); | |
78 } | |
79 | |
80 /** | |
81 * test that set sets variables | |
82 * | |
83 * @return void | |
84 * @access public | |
85 */ | |
86 function testSet() { | |
87 $this->Task->set('one', 'two'); | |
88 $this->assertTrue(isset($this->Task->templateVars['one'])); | |
89 $this->assertEqual($this->Task->templateVars['one'], 'two'); | |
90 | |
91 $this->Task->set(array('one' => 'three', 'four' => 'five')); | |
92 $this->assertTrue(isset($this->Task->templateVars['one'])); | |
93 $this->assertEqual($this->Task->templateVars['one'], 'three'); | |
94 $this->assertTrue(isset($this->Task->templateVars['four'])); | |
95 $this->assertEqual($this->Task->templateVars['four'], 'five'); | |
96 | |
97 $this->Task->templateVars = array(); | |
98 $this->Task->set(array(3 => 'three', 4 => 'four')); | |
99 $this->Task->set(array(1 => 'one', 2 => 'two')); | |
100 $expected = array(3 => 'three', 4 => 'four', 1 => 'one', 2 => 'two'); | |
101 $this->assertEqual($this->Task->templateVars, $expected); | |
102 } | |
103 | |
104 /** | |
105 * test finding themes installed in | |
106 * | |
107 * @return void | |
108 * @access public | |
109 */ | |
110 function testFindingInstalledThemesForBake() { | |
111 $consoleLibs = CAKE_CORE_INCLUDE_PATH . DS . CAKE . 'console' . DS; | |
112 $this->Task->Dispatch->shellPaths = array($consoleLibs); | |
113 $this->Task->initialize(); | |
114 $this->assertEqual($this->Task->templatePaths, array('default' => $consoleLibs . 'templates' . DS . 'default' . DS)); | |
115 } | |
116 | |
117 /** | |
118 * test getting the correct theme name. Ensure that with only one theme, or a theme param | |
119 * that the user is not bugged. If there are more, find and return the correct theme name | |
120 * | |
121 * @return void | |
122 * @access public | |
123 */ | |
124 function testGetThemePath() { | |
125 $defaultTheme = CAKE_CORE_INCLUDE_PATH . DS . dirname(CONSOLE_LIBS) . 'templates' . DS . 'default' .DS; | |
126 $this->Task->templatePaths = array('default' => $defaultTheme); | |
127 $this->Task->expectCallCount('in', 1); | |
128 | |
129 $result = $this->Task->getThemePath(); | |
130 $this->assertEqual($result, $defaultTheme); | |
131 | |
132 $this->Task->templatePaths = array('default' => $defaultTheme, 'other' => '/some/path'); | |
133 $this->Task->params['theme'] = 'other'; | |
134 $result = $this->Task->getThemePath(); | |
135 $this->assertEqual($result, '/some/path'); | |
136 | |
137 $this->Task->params = array(); | |
138 $this->Task->setReturnValueAt(0, 'in', '1'); | |
139 $result = $this->Task->getThemePath(); | |
140 $this->assertEqual($result, $defaultTheme); | |
141 $this->assertEqual($this->Dispatcher->params['theme'], 'default'); | |
142 } | |
143 | |
144 /** | |
145 * test generate | |
146 * | |
147 * @return void | |
148 * @access public | |
149 */ | |
150 function testGenerate() { | |
151 App::build(array( | |
152 'shells' => array( | |
153 TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors' . DS . 'shells' . DS | |
154 ) | |
155 )); | |
156 $this->Task->initialize(); | |
157 $this->Task->setReturnValue('in', 1); | |
158 $result = $this->Task->generate('classes', 'test_object', array('test' => 'foo')); | |
159 $expected = "I got rendered\nfoo"; | |
160 $this->assertEqual($result, $expected); | |
161 } | |
162 | |
163 /** | |
164 * test generate with a missing template in the chosen theme. | |
165 * ensure fallback to default works. | |
166 * | |
167 * @return void | |
168 * @access public | |
169 */ | |
170 function testGenerateWithTemplateFallbacks() { | |
171 App::build(array( | |
172 'shells' => array( | |
173 TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors' . DS . 'shells' . DS, | |
174 CAKE_CORE_INCLUDE_PATH . DS . 'console' . DS | |
175 ) | |
176 )); | |
177 $this->Task->initialize(); | |
178 $this->Task->params['theme'] = 'test'; | |
179 $this->Task->set(array( | |
180 'model' => 'Article', | |
181 'table' => 'articles', | |
182 'import' => false, | |
183 'records' => false, | |
184 'schema' => '' | |
185 )); | |
186 $result = $this->Task->generate('classes', 'fixture'); | |
187 $this->assertPattern('/ArticleFixture extends CakeTestFixture/', $result); | |
188 } | |
189 } |