Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
13532 anikendra 1
<?php
2
/**
3
 * PluginTask Test file
4
 *
5
 * Test Case for plugin generation shell task
6
 *
7
 * CakePHP : 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 Project
16
 * @package       Cake.Test.Case.Console.Command.Task
17
 * @since         CakePHP v 1.3.0
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('PluginTask', 'Console/Command/Task');
26
App::uses('ModelTask', 'Console/Command/Task');
27
App::uses('Folder', 'Utility');
28
App::uses('File', 'Utility');
29
 
30
/**
31
 * PluginTaskPlugin class
32
 *
33
 * @package       Cake.Test.Case.Console.Command.Task
34
 */
35
class PluginTaskTest extends CakeTestCase {
36
 
37
/**
38
 * setUp method
39
 *
40
 * @return void
41
 */
42
	public function setUp() {
43
		parent::setUp();
44
		$this->out = $this->getMock('ConsoleOutput', array(), array(), '', false);
45
		$this->in = $this->getMock('ConsoleInput', array(), array(), '', false);
46
 
47
		$this->Task = $this->getMock('PluginTask',
48
			array('in', 'err', 'createFile', '_stop', 'clear'),
49
			array($this->out, $this->out, $this->in)
50
		);
51
		$this->Task->path = TMP . 'tests' . DS;
52
		$this->Task->bootstrap = TMP . 'tests' . DS . 'bootstrap.php';
53
		touch($this->Task->bootstrap);
54
 
55
		$this->_paths = $paths = App::path('plugins');
56
		foreach ($paths as $i => $p) {
57
			if (!is_dir($p)) {
58
				array_splice($paths, $i, 1);
59
			}
60
		}
61
		$this->_testPath = array_push($paths, TMP . 'tests' . DS);
62
		App::build(array('plugins' => $paths));
63
	}
64
 
65
/**
66
 * tearDown()
67
 *
68
 * @return void
69
 */
70
	public function tearDown() {
71
		if (file_exists($this->Task->bootstrap)) {
72
			unlink($this->Task->bootstrap);
73
		}
74
		parent::tearDown();
75
	}
76
 
77
/**
78
 * test bake()
79
 *
80
 * @return void
81
 */
82
	public function testBakeFoldersAndFiles() {
83
		$this->Task->expects($this->at(0))->method('in')->will($this->returnValue($this->_testPath));
84
		$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('y'));
85
 
86
		$path = $this->Task->path . 'BakeTestPlugin';
87
 
88
		$file = $path . DS . 'Controller' . DS . 'BakeTestPluginAppController.php';
89
		$this->Task->expects($this->at(2))->method('createFile')
90
			->with($file, new PHPUnit_Framework_Constraint_IsAnything());
91
 
92
		$file = $path . DS . 'Model' . DS . 'BakeTestPluginAppModel.php';
93
		$this->Task->expects($this->at(3))->method('createFile')
94
			->with($file, new PHPUnit_Framework_Constraint_IsAnything());
95
 
96
		$this->Task->bake('BakeTestPlugin');
97
 
98
		$path = $this->Task->path . 'BakeTestPlugin';
99
		$this->assertTrue(is_dir($path), 'No plugin dir %s');
100
 
101
		$directories = array(
102
			'Config' . DS . 'Schema',
103
			'Model' . DS . 'Behavior',
104
			'Model' . DS . 'Datasource',
105
			'Console' . DS . 'Command' . DS . 'Task',
106
			'Controller' . DS . 'Component',
107
			'Lib',
108
			'View' . DS . 'Helper',
109
			'Test' . DS . 'Case' . DS . 'Controller' . DS . 'Component',
110
			'Test' . DS . 'Case' . DS . 'View' . DS . 'Helper',
111
			'Test' . DS . 'Case' . DS . 'Model' . DS . 'Behavior',
112
			'Test' . DS . 'Fixture',
113
			'Vendor',
114
			'webroot'
115
		);
116
		foreach ($directories as $dir) {
117
			$this->assertTrue(is_dir($path . DS . $dir), 'Missing directory for ' . $dir);
118
		}
119
 
120
		$Folder = new Folder($this->Task->path . 'BakeTestPlugin');
121
		$Folder->delete();
122
	}
123
 
124
/**
125
 * test execute with no args, flowing into interactive,
126
 *
127
 * @return void
128
 */
129
	public function testExecuteWithNoArgs() {
130
		$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestPlugin'));
131
		$this->Task->expects($this->at(1))->method('in')->will($this->returnValue($this->_testPath));
132
		$this->Task->expects($this->at(2))->method('in')->will($this->returnValue('y'));
133
 
134
		$path = $this->Task->path . 'TestPlugin';
135
		$file = $path . DS . 'Controller' . DS . 'TestPluginAppController.php';
136
 
137
		$this->Task->expects($this->at(3))->method('createFile')
138
			->with($file, new PHPUnit_Framework_Constraint_IsAnything());
139
 
140
		$file = $path . DS . 'Model' . DS . 'TestPluginAppModel.php';
141
		$this->Task->expects($this->at(4))->method('createFile')
142
			->with($file, new PHPUnit_Framework_Constraint_IsAnything());
143
 
144
		$this->Task->args = array();
145
		$this->Task->execute();
146
 
147
		$Folder = new Folder($path);
148
		$Folder->delete();
149
	}
150
 
151
/**
152
 * Test Execute
153
 *
154
 * @return void
155
 */
156
	public function testExecuteWithOneArg() {
157
		$this->Task->expects($this->at(0))->method('in')
158
			->will($this->returnValue($this->_testPath));
159
		$this->Task->expects($this->at(1))->method('in')
160
			->will($this->returnValue('y'));
161
 
162
		$path = $this->Task->path . 'BakeTestPlugin';
163
		$file = $path . DS . 'Controller' . DS . 'BakeTestPluginAppController.php';
164
		$this->Task->expects($this->at(2))->method('createFile')
165
			->with($file, new PHPUnit_Framework_Constraint_IsAnything());
166
 
167
		$path = $this->Task->path . 'BakeTestPlugin';
168
		$file = $path . DS . 'Model' . DS . 'BakeTestPluginAppModel.php';
169
		$this->Task->expects($this->at(3))->method('createFile')
170
			->with($file, new PHPUnit_Framework_Constraint_IsAnything());
171
 
172
		$this->Task->args = array('BakeTestPlugin');
173
 
174
		$this->Task->execute();
175
 
176
		$Folder = new Folder($this->Task->path . 'BakeTestPlugin');
177
		$Folder->delete();
178
	}
179
 
180
/**
181
 * Test that findPath ignores paths that don't exist.
182
 *
183
 * @return void
184
 */
185
	public function testFindPathNonExistant() {
186
		$paths = App::path('plugins');
187
		$last = count($paths);
188
		$paths[] = '/fake/path';
189
 
190
		$this->Task = $this->getMock('PluginTask',
191
			array('in', 'out', 'err', 'createFile', '_stop'),
192
			array($this->out, $this->out, $this->in)
193
		);
194
		$this->Task->path = TMP . 'tests' . DS;
195
 
196
		// Make sure the added path is filtered out.
197
		$this->Task->expects($this->exactly($last))
198
			->method('out');
199
 
200
		$this->Task->expects($this->once())
201
			->method('in')
202
			->will($this->returnValue($last));
203
 
204
		$this->Task->findPath($paths);
205
	}
206
}