Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
13532 anikendra 1
<?php
2
/**
3
 * TemplateTask file
4
 *
5
 * Test Case for TemplateTask generation shell task
6
 *
7
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
8
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
9
 *
10
 * Licensed under The MIT License
11
 * For full copyright and license information, please see the LICENSE.txt
12
 * Redistributions of files must retain the above copyright notice.
13
 *
14
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
15
 * @link          http://cakephp.org CakePHP(tm) Project
16
 * @package       Cake.Test.Case.Console.Command.Task
17
 * @since         CakePHP(tm) v 1.3
18
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
19
 */
20
 
21
App::uses('ShellDispatcher', 'Console');
22
App::uses('ConsoleOutput', 'Console');
23
App::uses('ConsoleInput', 'Console');
24
App::uses('Shell', 'Console');
25
App::uses('TemplateTask', 'Console/Command/Task');
26
 
27
/**
28
 * TemplateTaskTest class
29
 *
30
 * @package       Cake.Test.Case.Console.Command.Task
31
 */
32
class TemplateTaskTest extends CakeTestCase {
33
 
34
/**
35
 * setUp method
36
 *
37
 * @return void
38
 */
39
	public function setUp() {
40
		parent::setUp();
41
		$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
42
		$in = $this->getMock('ConsoleInput', array(), array(), '', false);
43
 
44
		$this->Task = $this->getMock('TemplateTask',
45
			array('in', 'err', 'createFile', '_stop', 'clear'),
46
			array($out, $out, $in)
47
		);
48
	}
49
 
50
/**
51
 * tearDown method
52
 *
53
 * @return void
54
 */
55
	public function tearDown() {
56
		parent::tearDown();
57
		unset($this->Task);
58
	}
59
 
60
/**
61
 * test that set sets variables
62
 *
63
 * @return void
64
 */
65
	public function testSet() {
66
		$this->Task->set('one', 'two');
67
		$this->assertTrue(isset($this->Task->templateVars['one']));
68
		$this->assertEquals('two', $this->Task->templateVars['one']);
69
 
70
		$this->Task->set(array('one' => 'three', 'four' => 'five'));
71
		$this->assertTrue(isset($this->Task->templateVars['one']));
72
		$this->assertEquals('three', $this->Task->templateVars['one']);
73
		$this->assertTrue(isset($this->Task->templateVars['four']));
74
		$this->assertEquals('five', $this->Task->templateVars['four']);
75
 
76
		$this->Task->templateVars = array();
77
		$this->Task->set(array(3 => 'three', 4 => 'four'));
78
		$this->Task->set(array(1 => 'one', 2 => 'two'));
79
		$expected = array(3 => 'three', 4 => 'four', 1 => 'one', 2 => 'two');
80
		$this->assertEquals($expected, $this->Task->templateVars);
81
	}
82
 
83
/**
84
 * test finding themes installed in
85
 *
86
 * @return void
87
 */
88
	public function testFindingInstalledThemesForBake() {
89
		$consoleLibs = CAKE . 'Console' . DS;
90
		$this->Task->initialize();
91
		$this->assertEquals($this->Task->templatePaths['default'], $consoleLibs . 'Templates' . DS . 'default' . DS);
92
	}
93
 
94
/**
95
 * test getting the correct theme name. Ensure that with only one theme, or a theme param
96
 * that the user is not bugged. If there are more, find and return the correct theme name
97
 *
98
 * @return void
99
 */
100
	public function testGetThemePath() {
101
		$defaultTheme = CAKE . 'Console' . DS . 'Templates' . DS . 'default' . DS;
102
		$this->Task->templatePaths = array('default' => $defaultTheme);
103
 
104
		$this->Task->expects($this->exactly(1))->method('in')->will($this->returnValue('1'));
105
 
106
		$result = $this->Task->getThemePath();
107
		$this->assertEquals($defaultTheme, $result);
108
 
109
		$this->Task->templatePaths = array('other' => '/some/path', 'default' => $defaultTheme);
110
		$this->Task->params['theme'] = 'other';
111
		$result = $this->Task->getThemePath();
112
		$this->assertEquals('/some/path', $result);
113
 
114
		$this->Task->params = array();
115
		$result = $this->Task->getThemePath();
116
		$this->assertEquals('/some/path', $result);
117
		$this->assertEquals('other', $this->Task->params['theme']);
118
	}
119
 
120
/**
121
 * test generate
122
 *
123
 * @return void
124
 */
125
	public function testGenerate() {
126
		App::build(array(
127
			'Console' => array(
128
				CAKE . 'Test' . DS . 'test_app' . DS . 'Console' . DS
129
			)
130
		));
131
		$this->Task->initialize();
132
		$this->Task->expects($this->any())->method('in')->will($this->returnValue(1));
133
 
134
		$result = $this->Task->generate('classes', 'test_object', array('test' => 'foo'));
135
		$expected = "I got rendered\nfoo";
136
		$this->assertTextEquals($expected, $result);
137
	}
138
 
139
/**
140
 * test generate with a missing template in the chosen theme.
141
 * ensure fallback to default works.
142
 *
143
 * @return void
144
 */
145
	public function testGenerateWithTemplateFallbacks() {
146
		App::build(array(
147
			'Console' => array(
148
				CAKE . 'Test' . DS . 'test_app' . DS . 'Console' . DS,
149
				CAKE_CORE_INCLUDE_PATH . DS . 'console' . DS
150
			)
151
		));
152
		$this->Task->initialize();
153
		$this->Task->params['theme'] = 'test';
154
		$this->Task->set(array(
155
			'model' => 'Article',
156
			'table' => 'articles',
157
			'import' => false,
158
			'records' => false,
159
			'schema' => ''
160
		));
161
		$result = $this->Task->generate('classes', 'fixture');
162
		$this->assertRegExp('/ArticleFixture extends CakeTestFixture/', $result);
163
	}
164
}