CommandTaskTest.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <?php
  2. /**
  3. * CakePHP : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP Project
  12. * @package Cake.Test.Case.Console.Command
  13. * @since CakePHP v 2.5
  14. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  15. */
  16. App::uses('CommandTask', 'Console/Command/Task');
  17. /**
  18. * CommandTaskTest class
  19. *
  20. * @package Cake.Test.Case.Console.Command.Task
  21. */
  22. class CommandTaskTest extends CakeTestCase {
  23. /**
  24. * setUp method
  25. *
  26. * @return void
  27. */
  28. public function setUp() {
  29. parent::setUp();
  30. App::build(array(
  31. 'Plugin' => array(
  32. CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS
  33. ),
  34. 'Console/Command' => array(
  35. CAKE . 'Test' . DS . 'test_app' . DS . 'Console' . DS . 'Command' . DS
  36. )
  37. ), App::RESET);
  38. CakePlugin::load(array('TestPlugin', 'TestPluginTwo'));
  39. $out = $this->getMock('ConsoleOutput', array(), array(), '', false);
  40. $in = $this->getMock('ConsoleInput', array(), array(), '', false);
  41. $this->CommandTask = $this->getMock(
  42. 'CommandTask',
  43. array('in', '_stop', 'clear'),
  44. array($out, $out, $in)
  45. );
  46. }
  47. /**
  48. * tearDown
  49. *
  50. * @return void
  51. */
  52. public function tearDown() {
  53. parent::tearDown();
  54. unset($this->CommandTask);
  55. CakePlugin::unload();
  56. }
  57. /**
  58. * Test the resulting list of shells
  59. *
  60. * @return void
  61. */
  62. public function testGetShellList() {
  63. $result = $this->CommandTask->getShellList();
  64. $expected = array(
  65. 'CORE' => array(
  66. 'acl',
  67. 'api',
  68. 'bake',
  69. 'command_list',
  70. 'completion',
  71. 'console',
  72. 'i18n',
  73. 'schema',
  74. 'server',
  75. 'test',
  76. 'testsuite',
  77. 'upgrade'
  78. ),
  79. 'TestPlugin' => array(
  80. 'example'
  81. ),
  82. 'TestPluginTwo' => array(
  83. 'example',
  84. 'welcome'
  85. ),
  86. 'app' => array(
  87. 'sample'
  88. ),
  89. );
  90. $this->assertEquals($expected, $result);
  91. }
  92. /**
  93. * Test the resulting list of commands
  94. *
  95. * @return void
  96. */
  97. public function testCommands() {
  98. $result = $this->CommandTask->commands();
  99. $expected = array(
  100. 'TestPlugin.example',
  101. 'TestPluginTwo.example',
  102. 'TestPluginTwo.welcome',
  103. 'acl',
  104. 'api',
  105. 'bake',
  106. 'command_list',
  107. 'completion',
  108. 'console',
  109. 'i18n',
  110. 'schema',
  111. 'server',
  112. 'test',
  113. 'testsuite',
  114. 'upgrade',
  115. 'sample'
  116. );
  117. $this->assertEquals($expected, $result);
  118. }
  119. /**
  120. * Test the resulting list of subcommands for the given command
  121. *
  122. * @return void
  123. */
  124. public function testSubCommands() {
  125. $result = $this->CommandTask->subCommands('acl');
  126. $expected = array(
  127. 'check',
  128. 'create',
  129. 'db_config',
  130. 'delete',
  131. 'deny',
  132. 'getPath',
  133. 'grant',
  134. 'inherit',
  135. 'initdb',
  136. 'nodeExists',
  137. 'parseIdentifier',
  138. 'setParent',
  139. 'view'
  140. );
  141. $this->assertEquals($expected, $result);
  142. }
  143. /**
  144. * Test that unknown commands return an empty array
  145. *
  146. * @return void
  147. */
  148. public function testSubCommandsUnknownCommand() {
  149. $result = $this->CommandTask->subCommands('yoghurt');
  150. $expected = array();
  151. $this->assertEquals($expected, $result);
  152. }
  153. /**
  154. * Test that getting a existing shell returns the shell instance
  155. *
  156. * @return void
  157. */
  158. public function testGetShell() {
  159. $result = $this->CommandTask->getShell('acl');
  160. $this->assertInstanceOf('AclShell', $result);
  161. }
  162. /**
  163. * Test that getting a non-existing shell returns false
  164. *
  165. * @return void
  166. */
  167. public function testGetShellNonExisting() {
  168. $result = $this->CommandTask->getShell('strawberry');
  169. $this->assertFalse($result);
  170. }
  171. /**
  172. * Test that getting a existing core shell with 'core.' prefix returns the correct shell instance
  173. *
  174. * @return void
  175. */
  176. public function testGetShellCore() {
  177. $result = $this->CommandTask->getShell('core.bake');
  178. $this->assertInstanceOf('BakeShell', $result);
  179. }
  180. /**
  181. * Test the options array for a known command
  182. *
  183. * @return void
  184. */
  185. public function testOptions() {
  186. $result = $this->CommandTask->options('bake');
  187. $expected = array(
  188. '--help',
  189. '-h',
  190. '--verbose',
  191. '-v',
  192. '--quiet',
  193. '-q',
  194. '--connection',
  195. '-c',
  196. '--theme',
  197. '-t'
  198. );
  199. $this->assertEquals($expected, $result);
  200. }
  201. /**
  202. * Test the options array for an unknown command
  203. *
  204. * @return void
  205. */
  206. public function testOptionsUnknownCommand() {
  207. $result = $this->CommandTask->options('pie');
  208. $expected = array(
  209. '--help',
  210. '-h',
  211. '--verbose',
  212. '-v',
  213. '--quiet',
  214. '-q'
  215. );
  216. $this->assertEquals($expected, $result);
  217. }
  218. }