/cake/tests/cases/console/libs/tasks/plugin.test.php

https://github.com/tsep/tsep1 · PHP · 263 lines · 146 code · 43 blank · 74 comment · 2 complexity · bcca7da2dcc53dff50c650e7125b0957 MD5 · raw file

  1. <?php
  2. /**
  3. * PluginTask Test file
  4. *
  5. * Test Case for plugin generation 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.3.0
  20. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  21. */
  22. App::import('Shell', 'Shell', false);
  23. if (!defined('DISABLE_AUTO_DISPATCH')) {
  24. define('DISABLE_AUTO_DISPATCH', true);
  25. }
  26. if (!class_exists('ShellDispatcher')) {
  27. ob_start();
  28. $argv = false;
  29. require CAKE . 'console' . DS . 'cake.php';
  30. ob_end_clean();
  31. }
  32. require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'plugin.php';
  33. require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'model.php';
  34. Mock::generatePartial(
  35. 'ShellDispatcher', 'TestPluginTaskMockShellDispatcher',
  36. array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
  37. );
  38. Mock::generatePartial(
  39. 'PluginTask', 'MockPluginTask',
  40. array('in', '_stop', 'err', 'out', 'createFile')
  41. );
  42. Mock::generate('ModelTask', 'PluginTestMockModelTask');
  43. /**
  44. * PluginTaskPlugin class
  45. *
  46. * @package cake
  47. * @subpackage cake.tests.cases.console.libs.tasks
  48. */
  49. class PluginTaskTest extends CakeTestCase {
  50. /**
  51. * startTest method
  52. *
  53. * @return void
  54. * @access public
  55. */
  56. function startTest() {
  57. $this->Dispatcher =& new TestPluginTaskMockShellDispatcher();
  58. $this->Dispatcher->shellPaths = App::path('shells');
  59. $this->Task =& new MockPluginTask($this->Dispatcher);
  60. $this->Task->Dispatch =& $this->Dispatcher;
  61. $this->Task->path = TMP . 'tests' . DS;
  62. }
  63. /**
  64. * startCase methods
  65. *
  66. * @return void
  67. * @access public
  68. */
  69. function startCase() {
  70. $this->_paths = $paths = App::path('plugins');
  71. $this->_testPath = array_push($paths, TMP . 'tests' . DS);
  72. App::build(array('plugins' => $paths));
  73. }
  74. /**
  75. * endCase
  76. *
  77. * @return void
  78. * @access public
  79. */
  80. function endCase() {
  81. App::build(array('plugins' => $this->_paths));
  82. }
  83. /**
  84. * endTest method
  85. *
  86. * @return void
  87. * @access public
  88. */
  89. function endTest() {
  90. ClassRegistry::flush();
  91. }
  92. /**
  93. * test bake()
  94. *
  95. * @return void
  96. * @access public
  97. */
  98. function testBakeFoldersAndFiles() {
  99. $this->Task->setReturnValueAt(0, 'in', $this->_testPath);
  100. $this->Task->setReturnValueAt(1, 'in', 'y');
  101. $this->Task->bake('BakeTestPlugin');
  102. $path = $this->Task->path . 'bake_test_plugin';
  103. $this->assertTrue(is_dir($path), 'No plugin dir %s');
  104. $this->assertTrue(is_dir($path . DS . 'config'), 'No config dir %s');
  105. $this->assertTrue(is_dir($path . DS . 'config' . DS . 'schema'), 'No schema dir %s');
  106. $this->assertTrue(file_exists($path . DS . 'config' . DS . 'schema' . DS . 'empty'), 'No empty file %s');
  107. $this->assertTrue(is_dir($path . DS . 'controllers'), 'No controllers dir %s');
  108. $this->assertTrue(is_dir($path . DS . 'controllers' . DS .'components'), 'No components dir %s');
  109. $this->assertTrue(file_exists($path . DS . 'controllers' . DS . 'components' . DS . 'empty'), 'No empty file %s');
  110. $this->assertTrue(is_dir($path . DS . 'models'), 'No models dir %s');
  111. $this->assertTrue(file_exists($path . DS . 'models' . DS . 'behaviors' . DS . 'empty'), 'No empty file %s');
  112. $this->assertTrue(is_dir($path . DS . 'models' . DS . 'datasources'), 'No datasources dir %s');
  113. $this->assertTrue(file_exists($path . DS . 'models' . DS . 'datasources' . DS . 'empty'), 'No empty file %s');
  114. $this->assertTrue(is_dir($path . DS . 'views'), 'No views dir %s');
  115. $this->assertTrue(is_dir($path . DS . 'views' . DS . 'helpers'), 'No helpers dir %s');
  116. $this->assertTrue(file_exists($path . DS . 'views' . DS . 'helpers' . DS . 'empty'), 'No empty file %s');
  117. $this->assertTrue(is_dir($path . DS . 'tests'), 'No tests dir %s');
  118. $this->assertTrue(is_dir($path . DS . 'tests' . DS . 'cases'), 'No cases dir %s');
  119. $this->assertTrue(
  120. is_dir($path . DS . 'tests' . DS . 'cases' . DS . 'components'), 'No components cases dir %s'
  121. );
  122. $this->assertTrue(
  123. file_exists($path . DS . 'tests' . DS . 'cases' . DS . 'components' . DS . 'empty'), 'No empty file %s'
  124. );
  125. $this->assertTrue(is_dir($path . DS . 'tests' . DS . 'cases' . DS . 'behaviors'), 'No behaviors cases dir %s');
  126. $this->assertTrue(
  127. file_exists($path . DS . 'tests' . DS . 'cases' . DS . 'behaviors' . DS . 'empty'), 'No empty file %s'
  128. );
  129. $this->assertTrue(is_dir($path . DS . 'tests' . DS . 'cases' . DS . 'helpers'), 'No helpers cases dir %s');
  130. $this->assertTrue(
  131. file_exists($path . DS . 'tests' . DS . 'cases' . DS . 'helpers' . DS . 'empty'), 'No empty file %s'
  132. );
  133. $this->assertTrue(is_dir($path . DS . 'tests' . DS . 'cases' . DS . 'models'), 'No models cases dir %s');
  134. $this->assertTrue(
  135. file_exists($path . DS . 'tests' . DS . 'cases' . DS . 'models' . DS . 'empty'), 'No empty file %s'
  136. );
  137. $this->assertTrue(
  138. is_dir($path . DS . 'tests' . DS . 'cases' . DS . 'controllers'),
  139. 'No controllers cases dir %s'
  140. );
  141. $this->assertTrue(
  142. file_exists($path . DS . 'tests' . DS . 'cases' . DS . 'controllers' . DS . 'empty'), 'No empty file %s'
  143. );
  144. $this->assertTrue(is_dir($path . DS . 'tests' . DS . 'groups'), 'No groups dir %s');
  145. $this->assertTrue(file_exists($path . DS . 'tests' . DS . 'groups' . DS . 'empty'), 'No empty file %s');
  146. $this->assertTrue(is_dir($path . DS . 'tests' . DS . 'fixtures'), 'No fixtures dir %s');
  147. $this->assertTrue(file_exists($path . DS . 'tests' . DS . 'fixtures' . DS . 'empty'), 'No empty file %s');
  148. $this->assertTrue(is_dir($path . DS . 'vendors'), 'No vendors dir %s');
  149. $this->assertTrue(is_dir($path . DS . 'vendors' . DS . 'shells'), 'No vendors shells dir %s');
  150. $this->assertTrue(is_dir($path . DS . 'vendors' . DS . 'shells' . DS . 'tasks'), 'No vendors shells tasks dir %s');
  151. $this->assertTrue(file_exists($path . DS . 'vendors' . DS . 'shells' . DS . 'tasks' . DS . 'empty'), 'No empty file %s');
  152. $this->assertTrue(is_dir($path . DS . 'libs'), 'No libs dir %s');
  153. $this->assertTrue(is_dir($path . DS . 'webroot'), 'No webroot dir %s');
  154. $file = $path . DS . 'bake_test_plugin_app_controller.php';
  155. $this->Task->expectAt(0, 'createFile', array($file, '*'), 'No AppController %s');
  156. $file = $path . DS . 'bake_test_plugin_app_model.php';
  157. $this->Task->expectAt(1, 'createFile', array($file, '*'), 'No AppModel %s');
  158. $Folder =& new Folder($this->Task->path . 'bake_test_plugin');
  159. $Folder->delete();
  160. }
  161. /**
  162. * test execute with no args, flowing into interactive,
  163. *
  164. * @return void
  165. * @access public
  166. */
  167. function testExecuteWithNoArgs() {
  168. $this->Task->setReturnValueAt(0, 'in', 'TestPlugin');
  169. $this->Task->setReturnValueAt(1, 'in', '3');
  170. $this->Task->setReturnValueAt(2, 'in', 'y');
  171. $this->Task->setReturnValueAt(3, 'in', 'n');
  172. $path = $this->Task->path . 'test_plugin';
  173. $file = $path . DS . 'test_plugin_app_controller.php';
  174. $this->Task->expectAt(0, 'createFile', array($file, '*'), 'No AppController %s');
  175. $file = $path . DS . 'test_plugin_app_model.php';
  176. $this->Task->expectAt(1, 'createFile', array($file, '*'), 'No AppModel %s');
  177. $this->Task->args = array();
  178. $this->Task->execute();
  179. $Folder =& new Folder($path);
  180. $Folder->delete();
  181. }
  182. /**
  183. * Test Execute
  184. *
  185. * @return void
  186. * @access public
  187. */
  188. function testExecuteWithOneArg() {
  189. $this->Task->setReturnValueAt(0, 'in', $this->_testPath);
  190. $this->Task->setReturnValueAt(1, 'in', 'y');
  191. $this->Task->Dispatch->args = array('BakeTestPlugin');
  192. $this->Task->args =& $this->Task->Dispatch->args;
  193. $path = $this->Task->path . 'bake_test_plugin';
  194. $file = $path . DS . 'bake_test_plugin_app_controller.php';
  195. $this->Task->expectAt(0, 'createFile', array($file, '*'), 'No AppController %s');
  196. $file = $path . DS . 'bake_test_plugin_app_model.php';
  197. $this->Task->expectAt(1, 'createFile', array($file, '*'), 'No AppModel %s');
  198. $this->Task->execute();
  199. $Folder =& new Folder($this->Task->path . 'bake_test_plugin');
  200. $Folder->delete();
  201. }
  202. /**
  203. * test execute chaining into MVC parts
  204. *
  205. * @return void
  206. * @access public
  207. */
  208. function testExecuteWithTwoArgs() {
  209. $this->Task->Model =& new PluginTestMockModelTask();
  210. $this->Task->setReturnValueAt(0, 'in', $this->_testPath);
  211. $this->Task->setReturnValueAt(1, 'in', 'y');
  212. $Folder =& new Folder($this->Task->path . 'bake_test_plugin', true);
  213. $this->Task->Dispatch->args = array('BakeTestPlugin', 'model');
  214. $this->Task->args =& $this->Task->Dispatch->args;
  215. $this->Task->Model->expectOnce('loadTasks');
  216. $this->Task->Model->expectOnce('execute');
  217. $this->Task->execute();
  218. $Folder->delete();
  219. }
  220. }