5 * Test Case for plugin generation shell task
7 * CakePHP : Rapid Development Framework (http://cakephp.org)
8 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
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.
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
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');
31 * PluginTaskPlugin class
33 * @package Cake.Test.Case.Console.Command.Task
35 class PluginTaskTest extends CakeTestCase {
42 public function setUp() {
44 $this->out = $this->getMock('ConsoleOutput', array(), array(), '', false);
45 $this->in = $this->getMock('ConsoleInput', array(), array(), '', false);
47 $this->Task = $this->getMock('PluginTask',
48 array('in', 'err', 'createFile', '_stop', 'clear'),
49 array($this->out, $this->out, $this->in)
51 $this->Task->path = TMP . 'tests' . DS;
52 $this->Task->bootstrap = TMP . 'tests' . DS . 'bootstrap.php';
53 touch($this->Task->bootstrap);
55 $this->_paths = $paths = App::path('plugins');
56 foreach ($paths as $i => $p) {
58 array_splice($paths, $i, 1);
61 $this->_testPath = array_push($paths, TMP . 'tests' . DS) - 1;
62 App::build(array('plugins' => $paths));
70 public function tearDown() {
71 if (file_exists($this->Task->bootstrap)) {
72 unlink($this->Task->bootstrap);
82 public function testBakeFoldersAndFiles() {
83 $this->Task->expects($this->at(0))
85 ->will($this->returnValue($this->_testPath));
86 $this->Task->expects($this->at(1))
88 ->will($this->returnValue('y'));
90 $path = $this->Task->path . 'BakeTestPlugin';
92 $file = $path . DS . 'Controller' . DS . 'BakeTestPluginAppController.php';
93 $this->Task->expects($this->at(2))
94 ->method('createFile')
95 ->with($file, new PHPUnit_Framework_Constraint_IsAnything());
97 $file = $path . DS . 'Model' . DS . 'BakeTestPluginAppModel.php';
98 $this->Task->expects($this->at(3))
99 ->method('createFile')
100 ->with($file, new PHPUnit_Framework_Constraint_IsAnything());
102 $this->Task->bake('BakeTestPlugin');
104 $path = $this->Task->path . 'BakeTestPlugin';
105 $this->assertTrue(is_dir($path), 'No plugin dir %s');
107 $directories = array(
108 'Config' . DS . 'Schema',
109 'Console' . DS . 'Command' . DS . 'Task',
110 'Console' . DS . 'Templates',
111 'Controller' . DS . 'Component',
113 'Locale' . DS . 'eng' . DS . 'LC_MESSAGES',
114 'Model' . DS . 'Behavior',
115 'Model' . DS . 'Datasource',
116 'Test' . DS . 'Case' . DS . 'Controller' . DS . 'Component',
117 'Test' . DS . 'Case' . DS . 'Lib',
118 'Test' . DS . 'Case' . DS . 'Model' . DS . 'Behavior',
119 'Test' . DS . 'Case' . DS . 'Model' . DS . 'Datasource',
120 'Test' . DS . 'Case' . DS . 'View' . DS . 'Helper',
121 'Test' . DS . 'Fixture',
122 'View' . DS . 'Elements',
123 'View' . DS . 'Helper',
124 'View' . DS . 'Layouts',
125 'webroot' . DS . 'css',
126 'webroot' . DS . 'js',
127 'webroot' . DS . 'img',
129 foreach ($directories as $dir) {
130 $this->assertTrue(is_dir($path . DS . $dir), 'Missing directory for ' . $dir);
133 $Folder = new Folder($this->Task->path . 'BakeTestPlugin');
138 * test execute with no args, flowing into interactive,
142 public function testExecuteWithNoArgs() {
143 $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestPlugin'));
144 $this->Task->expects($this->at(1))->method('in')->will($this->returnValue($this->_testPath));
145 $this->Task->expects($this->at(2))->method('in')->will($this->returnValue('y'));
147 $path = $this->Task->path . 'TestPlugin';
148 $file = $path . DS . 'Controller' . DS . 'TestPluginAppController.php';
150 $this->Task->expects($this->at(3))->method('createFile')
151 ->with($file, new PHPUnit_Framework_Constraint_IsAnything());
153 $file = $path . DS . 'Model' . DS . 'TestPluginAppModel.php';
154 $this->Task->expects($this->at(4))->method('createFile')
155 ->with($file, new PHPUnit_Framework_Constraint_IsAnything());
157 $this->Task->args = array();
158 $this->Task->execute();
160 $Folder = new Folder($path);
169 public function testExecuteWithOneArg() {
170 $this->Task->expects($this->at(0))->method('in')
171 ->will($this->returnValue($this->_testPath));
172 $this->Task->expects($this->at(1))->method('in')
173 ->will($this->returnValue('y'));
175 $path = $this->Task->path . 'BakeTestPlugin';
176 $file = $path . DS . 'Controller' . DS . 'BakeTestPluginAppController.php';
177 $this->Task->expects($this->at(2))->method('createFile')
178 ->with($file, new PHPUnit_Framework_Constraint_IsAnything());
180 $path = $this->Task->path . 'BakeTestPlugin';
181 $file = $path . DS . 'Model' . DS . 'BakeTestPluginAppModel.php';
182 $this->Task->expects($this->at(3))->method('createFile')
183 ->with($file, new PHPUnit_Framework_Constraint_IsAnything());
185 $this->Task->args = array('BakeTestPlugin');
187 $this->Task->execute();
189 $Folder = new Folder($this->Task->path . 'BakeTestPlugin');
194 * Test that findPath ignores paths that don't exist.
198 public function testFindPathNonExistant() {
199 $paths = App::path('plugins');
200 $last = count($paths);
202 array_unshift($paths, '/fake/path');
203 $paths[] = '/fake/path2';
205 $this->Task = $this->getMock('PluginTask',
206 array('in', 'out', 'err', 'createFile', '_stop'),
207 array($this->out, $this->out, $this->in)
209 $this->Task->path = TMP . 'tests' . DS;
211 // Make sure the added path is filtered out.
212 $this->Task->expects($this->exactly($last))
215 $this->Task->expects($this->once())
217 ->will($this->returnValue($last));
219 $this->Task->findPath($paths);