PageRenderTime 48ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/Datawalke/Coordino
PHP | 301 lines | 168 code | 35 blank | 98 comment | 2 complexity | 4d678150a3598c2910320896c9608ba1 MD5 | raw file
  1. <?php
  2. /**
  3. * ProjectTask Test file
  4. *
  5. * Test Case for project generation shell task
  6. *
  7. * PHP versions 4 and 5
  8. *
  9. * CakePHP : Rapid Development Framework (http://cakephp.org)
  10. * Copyright 2005-2012, 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 2005-2012, 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 . 'project.php';
  33. Mock::generatePartial(
  34. 'ShellDispatcher', 'TestProjectTaskMockShellDispatcher',
  35. array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
  36. );
  37. Mock::generatePartial(
  38. 'ProjectTask', 'MockProjectTask',
  39. array('in', '_stop', 'err', 'out', 'createFile')
  40. );
  41. /**
  42. * ProjectTask Test class
  43. *
  44. * @package cake
  45. * @subpackage cake.tests.cases.console.libs.tasks
  46. */
  47. class ProjectTaskTest extends CakeTestCase {
  48. /**
  49. * startTest method
  50. *
  51. * @return void
  52. * @access public
  53. */
  54. function startTest() {
  55. $this->Dispatcher =& new TestProjectTaskMockShellDispatcher();
  56. $this->Dispatcher->shellPaths = App::path('shells');
  57. $this->Task =& new MockProjectTask($this->Dispatcher);
  58. $this->Task->Dispatch =& $this->Dispatcher;
  59. $this->Task->path = TMP . 'tests' . DS;
  60. }
  61. /**
  62. * endTest method
  63. *
  64. * @return void
  65. * @access public
  66. */
  67. function endTest() {
  68. ClassRegistry::flush();
  69. $Folder =& new Folder($this->Task->path . 'bake_test_app');
  70. $Folder->delete();
  71. }
  72. /**
  73. * creates a test project that is used for testing project task.
  74. *
  75. * @return void
  76. * @access protected
  77. */
  78. function _setupTestProject() {
  79. $skel = CAKE_CORE_INCLUDE_PATH . DS . CAKE . 'console' . DS . 'templates' . DS . 'skel';
  80. $this->Task->setReturnValueAt(0, 'in', 'y');
  81. $this->Task->setReturnValueAt(1, 'in', 'n');
  82. $this->Task->bake($this->Task->path . 'bake_test_app', $skel);
  83. }
  84. /**
  85. * test bake() method and directory creation.
  86. *
  87. * @return void
  88. * @access public
  89. */
  90. function testBake() {
  91. $this->_setupTestProject();
  92. $path = $this->Task->path . 'bake_test_app';
  93. $this->assertTrue(is_dir($path), 'No project dir %s');
  94. $this->assertTrue(is_dir($path . DS . 'controllers'), 'No controllers dir %s');
  95. $this->assertTrue(is_dir($path . DS . 'controllers' . DS .'components'), 'No components dir %s');
  96. $this->assertTrue(is_dir($path . DS . 'models'), 'No models dir %s');
  97. $this->assertTrue(is_dir($path . DS . 'views'), 'No views dir %s');
  98. $this->assertTrue(is_dir($path . DS . 'views' . DS . 'helpers'), 'No helpers dir %s');
  99. $this->assertTrue(is_dir($path . DS . 'tests'), 'No tests dir %s');
  100. $this->assertTrue(is_dir($path . DS . 'tests' . DS . 'cases'), 'No cases dir %s');
  101. $this->assertTrue(is_dir($path . DS . 'tests' . DS . 'groups'), 'No groups dir %s');
  102. $this->assertTrue(is_dir($path . DS . 'tests' . DS . 'fixtures'), 'No fixtures dir %s');
  103. }
  104. /**
  105. * test bake() method with -empty flag, directory creation and empty files.
  106. *
  107. * @return void
  108. * @access public
  109. */
  110. function testBakeEmptyFlag() {
  111. $this->Task->params['empty'] = true;
  112. $this->_setupTestProject();
  113. $path = $this->Task->path . 'bake_test_app';
  114. $this->assertTrue(is_dir($path), 'No project dir %s');
  115. $this->assertTrue(is_dir($path . DS . 'controllers'), 'No controllers dir %s');
  116. $this->assertTrue(is_dir($path . DS . 'controllers' . DS .'components'), 'No components dir %s');
  117. $this->assertTrue(is_dir($path . DS . 'models'), 'No models dir %s');
  118. $this->assertTrue(is_dir($path . DS . 'views'), 'No views dir %s');
  119. $this->assertTrue(is_dir($path . DS . 'views' . DS . 'helpers'), 'No helpers dir %s');
  120. $this->assertTrue(is_dir($path . DS . 'tests'), 'No tests dir %s');
  121. $this->assertTrue(is_dir($path . DS . 'tests' . DS . 'cases'), 'No cases dir %s');
  122. $this->assertTrue(is_dir($path . DS . 'tests' . DS . 'groups'), 'No groups dir %s');
  123. $this->assertTrue(is_dir($path . DS . 'tests' . DS . 'fixtures'), 'No fixtures dir %s');
  124. $this->assertTrue(is_file($path . DS . 'controllers' . DS .'components' . DS . 'empty'), 'No empty file in dir %s');
  125. $this->assertTrue(is_file($path . DS . 'locale' . DS . 'eng' . DS . 'LC_MESSAGES' . DS . 'empty'), 'No empty file in dir %s');
  126. $this->assertTrue(is_file($path . DS . 'models' . DS . 'behaviors' . DS . 'empty'), 'No empty file in dir %s');
  127. $this->assertTrue(is_file($path . DS . 'models' . DS . 'datasources' . DS . 'empty'), 'No empty file in dir %s');
  128. $this->assertTrue(is_file($path . DS . 'plugins' . DS . 'empty'), 'No empty file in dir %s');
  129. $this->assertTrue(is_file($path . DS . 'tests' . DS . 'cases' . DS . 'behaviors' . DS . 'empty'), 'No empty file in dir %s');
  130. $this->assertTrue(is_file($path . DS . 'tests' . DS . 'cases' . DS . 'components' . DS . 'empty'), 'No empty file in dir %s');
  131. $this->assertTrue(is_file($path . DS . 'tests' . DS . 'cases' . DS . 'controllers' . DS . 'empty'), 'No empty file in dir %s');
  132. $this->assertTrue(is_file($path . DS . 'tests' . DS . 'cases' . DS . 'datasources' . DS . 'empty'), 'No empty file in dir %s');
  133. $this->assertTrue(is_file($path . DS . 'tests' . DS . 'cases' . DS . 'helpers' . DS . 'empty'), 'No empty file in dir %s');
  134. $this->assertTrue(is_file($path . DS . 'tests' . DS . 'cases' . DS . 'models' . DS . 'empty'), 'No empty file in dir %s');
  135. $this->assertTrue(is_file($path . DS . 'tests' . DS . 'cases' . DS . 'shells' . DS . 'empty'), 'No empty file in dir %s');
  136. $this->assertTrue(is_file($path . DS . 'tests' . DS . 'fixtures' . DS . 'empty'), 'No empty file in dir %s');
  137. $this->assertTrue(is_file($path . DS . 'tests' . DS . 'groups' . DS . 'empty'), 'No empty file in dir %s');
  138. $this->assertTrue(is_file($path . DS . 'vendors' . DS . 'shells' . DS . 'tasks' . DS . 'empty'), 'No empty file in dir %s');
  139. $this->assertTrue(is_file($path . DS . 'views' . DS . 'errors' . DS . 'empty'), 'No empty file in dir %s');
  140. $this->assertTrue(is_file($path . DS . 'views' . DS . 'helpers' . DS . 'empty'), 'No empty file in dir %s');
  141. $this->assertTrue(is_file($path . DS . 'views' . DS . 'scaffolds' . DS . 'empty'), 'No empty file in dir %s');
  142. $this->assertTrue(is_file($path . DS . 'webroot' . DS . 'js' . DS . 'empty'), 'No empty file in dir %s');
  143. }
  144. /**
  145. * test generation of Security.salt
  146. *
  147. * @return void
  148. * @access public
  149. */
  150. function testSecuritySaltGeneration() {
  151. $this->_setupTestProject();
  152. $path = $this->Task->path . 'bake_test_app' . DS;
  153. $result = $this->Task->securitySalt($path);
  154. $this->assertTrue($result);
  155. $file =& new File($path . 'config' . DS . 'core.php');
  156. $contents = $file->read();
  157. $this->assertNoPattern('/DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi/', $contents, 'Default Salt left behind. %s');
  158. }
  159. /**
  160. * test generation of Security.cipherSeed
  161. *
  162. * @return void
  163. * @access public
  164. */
  165. function testSecurityCipherSeedGeneration() {
  166. $this->_setupTestProject();
  167. $path = $this->Task->path . 'bake_test_app' . DS;
  168. $result = $this->Task->securityCipherSeed($path);
  169. $this->assertTrue($result);
  170. $file =& new File($path . 'config' . DS . 'core.php');
  171. $contents = $file->read();
  172. $this->assertNoPattern('/76859309657453542496749683645/', $contents, 'Default CipherSeed left behind. %s');
  173. }
  174. /**
  175. * Test that index.php is generated correctly.
  176. *
  177. * @return void
  178. * @access public
  179. */
  180. function testIndexPhpGeneration() {
  181. $this->_setupTestProject();
  182. $path = $this->Task->path . 'bake_test_app' . DS;
  183. $this->Task->corePath($path);
  184. $file =& new File($path . 'webroot' . DS . 'index.php');
  185. $contents = $file->read();
  186. $this->assertNoPattern('/define\(\'CAKE_CORE_INCLUDE_PATH\', \'ROOT/', $contents);
  187. $file =& new File($path . 'webroot' . DS . 'test.php');
  188. $contents = $file->read();
  189. $this->assertNoPattern('/define\(\'CAKE_CORE_INCLUDE_PATH\', \'ROOT/', $contents);
  190. }
  191. /**
  192. * test getPrefix method, and that it returns Routing.prefix or writes to config file.
  193. *
  194. * @return void
  195. * @access public
  196. */
  197. function testGetPrefix() {
  198. Configure::write('Routing.prefixes', array('admin'));
  199. $result = $this->Task->getPrefix();
  200. $this->assertEqual($result, 'admin_');
  201. Configure::write('Routing.prefixes', null);
  202. $this->_setupTestProject();
  203. $this->Task->configPath = $this->Task->path . 'bake_test_app' . DS . 'config' . DS;
  204. $this->Task->setReturnValue('in', 'super_duper_admin');
  205. $result = $this->Task->getPrefix();
  206. $this->assertEqual($result, 'super_duper_admin_');
  207. $file =& new File($this->Task->configPath . 'core.php');
  208. $file->delete();
  209. }
  210. /**
  211. * test cakeAdmin() writing core.php
  212. *
  213. * @return void
  214. * @access public
  215. */
  216. function testCakeAdmin() {
  217. $file =& new File(CONFIGS . 'core.php');
  218. $contents = $file->read();;
  219. $file =& new File(TMP . 'tests' . DS . 'core.php');
  220. $file->write($contents);
  221. Configure::write('Routing.prefixes', null);
  222. $this->Task->configPath = TMP . 'tests' . DS;
  223. $result = $this->Task->cakeAdmin('my_prefix');
  224. $this->assertTrue($result);
  225. $this->assertEqual(Configure::read('Routing.prefixes'), array('my_prefix'));
  226. $file->delete();
  227. }
  228. /**
  229. * test getting the prefix with more than one prefix setup
  230. *
  231. * @return void
  232. * @access public
  233. */
  234. function testGetPrefixWithMultiplePrefixes() {
  235. Configure::write('Routing.prefixes', array('admin', 'ninja', 'shinobi'));
  236. $this->_setupTestProject();
  237. $this->Task->configPath = $this->Task->path . 'bake_test_app' . DS . 'config' . DS;
  238. $this->Task->setReturnValue('in', 2);
  239. $result = $this->Task->getPrefix();
  240. $this->assertEqual($result, 'ninja_');
  241. }
  242. /**
  243. * Test execute method with one param to destination folder.
  244. *
  245. * @return void
  246. * @access public
  247. */
  248. function testExecute() {
  249. $this->Task->params['skel'] = CAKE_CORE_INCLUDE_PATH . DS . CAKE . DS . 'console' . DS. 'templates' . DS . 'skel';
  250. $this->Task->params['working'] = TMP . 'tests' . DS;
  251. $path = $this->Task->path . 'bake_test_app';
  252. $this->Task->setReturnValue('in', 'y');
  253. $this->Task->setReturnValueAt(0, 'in', $path);
  254. $this->Task->execute();
  255. $this->assertTrue(is_dir($path), 'No project dir %s');
  256. $this->assertTrue(is_dir($path . DS . 'controllers'), 'No controllers dir %s');
  257. $this->assertTrue(is_dir($path . DS . 'controllers' . DS .'components'), 'No components dir %s');
  258. $this->assertTrue(is_dir($path . DS . 'models'), 'No models dir %s');
  259. $this->assertTrue(is_dir($path . DS . 'views'), 'No views dir %s');
  260. $this->assertTrue(is_dir($path . DS . 'views' . DS . 'helpers'), 'No helpers dir %s');
  261. $this->assertTrue(is_dir($path . DS . 'tests'), 'No tests dir %s');
  262. $this->assertTrue(is_dir($path . DS . 'tests' . DS . 'cases'), 'No cases dir %s');
  263. $this->assertTrue(is_dir($path . DS . 'tests' . DS . 'groups'), 'No groups dir %s');
  264. $this->assertTrue(is_dir($path . DS . 'tests' . DS . 'fixtures'), 'No fixtures dir %s');
  265. }
  266. }