PageRenderTime 70ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/cake/tests/cases/console/cake.test.php

https://bitbucket.org/d1rk/cakephp-including-capistrano
PHP | 482 lines | 321 code | 40 blank | 121 comment | 4 complexity | 7c8ec2d554b63dee543d36edeae8a2f6 MD5 | raw file
  1. <?php
  2. /* SVN FILE: $Id: cake.test.php 8123 2009-03-21 23:55:39Z davidpersson $ */
  3. /**
  4. * ShellDispatcherTest file
  5. *
  6. * Long description for file
  7. *
  8. * PHP versions 4 and 5
  9. *
  10. * CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
  11. * Copyright 2005-2007, Cake Software Foundation, Inc.
  12. *
  13. * Licensed under The Open Group Test Suite License
  14. * Redistributions of files must retain the above copyright notice.
  15. *
  16. * @filesource
  17. * @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
  18. * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
  19. * @package cake
  20. * @subpackage cake.tests.cases.console
  21. * @since CakePHP(tm) v 1.2.0.5432
  22. * @version $Revision: 8123 $
  23. * @modifiedby $LastChangedBy: davidpersson $
  24. * @lastmodified $Date: 2009-03-22 00:55:39 +0100 (So, 22. Mär 2009) $
  25. * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
  26. */
  27. if (!defined('DISABLE_AUTO_DISPATCH')) {
  28. define('DISABLE_AUTO_DISPATCH', true);
  29. }
  30. if (!class_exists('ShellDispatcher')) {
  31. ob_start();
  32. $argv = false;
  33. require CAKE . 'console' . DS . 'cake.php';
  34. ob_end_clean();
  35. }
  36. /**
  37. * TestShellDispatcher class
  38. *
  39. * @package cake
  40. * @subpackage cake.tests.cases.console
  41. */
  42. class TestShellDispatcher extends ShellDispatcher {
  43. /**
  44. * params property
  45. *
  46. * @var array
  47. * @access public
  48. */
  49. var $params = array();
  50. /**
  51. * stdout property
  52. *
  53. * @var string
  54. * @access public
  55. */
  56. var $stdout = '';
  57. /**
  58. * stderr property
  59. *
  60. * @var string
  61. * @access public
  62. */
  63. var $stderr = '';
  64. /**
  65. * stopped property
  66. *
  67. * @var string
  68. * @access public
  69. */
  70. var $stopped = null;
  71. /**
  72. * _initEnvironment method
  73. *
  74. * @access protected
  75. * @return void
  76. */
  77. function _initEnvironment() {
  78. }
  79. /**
  80. * stderr method
  81. *
  82. * @access public
  83. * @return void
  84. */
  85. function stderr($string) {
  86. $this->stderr .= rtrim($string, ' ');
  87. }
  88. /**
  89. * stdout method
  90. *
  91. * @access public
  92. * @return void
  93. */
  94. function stdout($string, $newline = true) {
  95. if ($newline) {
  96. $this->stdout .= rtrim($string, ' ') . "\n";
  97. } else {
  98. $this->stdout .= rtrim($string, ' ');
  99. }
  100. }
  101. /**
  102. * _stop method
  103. *
  104. * @access protected
  105. * @return void
  106. */
  107. function _stop($status = 0) {
  108. $this->stopped = 'Stopped with status: ' . $status;
  109. }
  110. }
  111. /**
  112. * ShellDispatcherTest
  113. *
  114. * @package cake
  115. * @subpackage cake.tests.cases.libs
  116. */
  117. class ShellDispatcherTest extends UnitTestCase {
  118. /**
  119. * setUp method
  120. *
  121. * @access public
  122. * @return void
  123. */
  124. function setUp() {
  125. $this->_pluginPaths = Configure::read('pluginPaths');
  126. $this->_shellPaths = Configure::read('shellPaths');
  127. Configure::write('pluginPaths', array(
  128. TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS
  129. ));
  130. Configure::write('shellPaths', array(
  131. CORE_PATH ? CONSOLE_LIBS : ROOT . DS . CONSOLE_LIBS,
  132. TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors' . DS . 'shells' . DS
  133. ));
  134. }
  135. /**
  136. * tearDown method
  137. *
  138. * @access public
  139. * @return void
  140. */
  141. function tearDown() {
  142. Configure::write('pluginPaths', $this->_pluginPaths);
  143. Configure::write('shellPaths', $this->_shellPaths);
  144. }
  145. /**
  146. * testParseParams method
  147. *
  148. * @access public
  149. * @return void
  150. */
  151. function testParseParams() {
  152. $Dispatcher =& new TestShellDispatcher();
  153. $params = array(
  154. '/cake/1.2.x.x/cake/console/cake.php',
  155. 'bake',
  156. '-app',
  157. 'new',
  158. '-working',
  159. '/var/www/htdocs'
  160. );
  161. $expected = array(
  162. 'app' => 'new',
  163. 'webroot' => 'webroot',
  164. 'working' => '/var/www/htdocs/new',
  165. 'root' => '/var/www/htdocs'
  166. );
  167. $Dispatcher->parseParams($params);
  168. $this->assertEqual($expected, $Dispatcher->params);
  169. $params = array('cake.php');
  170. $expected = array(
  171. 'app' => 'app',
  172. 'webroot' => 'webroot',
  173. 'working' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH . DS . 'app'),
  174. 'root' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH),
  175. );
  176. $Dispatcher->params = $Dispatcher->args = array();
  177. $Dispatcher->parseParams($params);
  178. $this->assertEqual($expected, $Dispatcher->params);
  179. $params = array(
  180. 'cake.php',
  181. '-app',
  182. 'new',
  183. );
  184. $expected = array(
  185. 'app' => 'new',
  186. 'webroot' => 'webroot',
  187. 'working' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH . DS . 'new'),
  188. 'root' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH)
  189. );
  190. $Dispatcher->params = $Dispatcher->args = array();
  191. $Dispatcher->parseParams($params);
  192. $this->assertEqual($expected, $Dispatcher->params);
  193. $params = array(
  194. './cake.php',
  195. 'bake',
  196. '-app',
  197. 'new',
  198. '-working',
  199. '/cake/1.2.x.x/cake/console'
  200. );
  201. $expected = array(
  202. 'app' => 'new',
  203. 'webroot' => 'webroot',
  204. 'working' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH . DS . 'new'),
  205. 'root' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH)
  206. );
  207. $Dispatcher->params = $Dispatcher->args = array();
  208. $Dispatcher->parseParams($params);
  209. $this->assertEqual($expected, $Dispatcher->params);
  210. $params = array(
  211. './console/cake.php',
  212. 'bake',
  213. '-app',
  214. 'new',
  215. '-working',
  216. '/cake/1.2.x.x/cake'
  217. );
  218. $expected = array(
  219. 'app' => 'new',
  220. 'webroot' => 'webroot',
  221. 'working' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH . DS . 'new'),
  222. 'root' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH)
  223. );
  224. $Dispatcher->params = $Dispatcher->args = array();
  225. $Dispatcher->parseParams($params);
  226. $this->assertEqual($expected, $Dispatcher->params);
  227. $params = array(
  228. './console/cake.php',
  229. 'bake',
  230. '-app',
  231. 'new',
  232. '-dry',
  233. '-working',
  234. '/cake/1.2.x.x/cake'
  235. );
  236. $expected = array(
  237. 'app' => 'new',
  238. 'webroot' => 'webroot',
  239. 'working' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH . DS . 'new'),
  240. 'root' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH),
  241. 'dry' => 1
  242. );
  243. $Dispatcher->params = $Dispatcher->args = array();
  244. $Dispatcher->parseParams($params);
  245. $this->assertEqual($expected, $Dispatcher->params);
  246. $params = array(
  247. './console/cake.php',
  248. '-working',
  249. '/cake/1.2.x.x/cake',
  250. 'schema',
  251. 'run',
  252. 'create',
  253. '-dry',
  254. '-f',
  255. '-name',
  256. 'DbAcl'
  257. );
  258. $expected = array(
  259. 'app' => 'app',
  260. 'webroot' => 'webroot',
  261. 'working' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH . DS . 'app'),
  262. 'root' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH),
  263. 'dry' => 1,
  264. 'f' => 1,
  265. 'name' => 'DbAcl'
  266. );
  267. $Dispatcher->params = $Dispatcher->args = array();
  268. $Dispatcher->parseParams($params);
  269. $this->assertEqual($expected, $Dispatcher->params);
  270. $expected = array('./console/cake.php', 'schema', 'run', 'create');
  271. $this->assertEqual($expected, $Dispatcher->args);
  272. $params = array(
  273. '/cake/1.2.x.x/cake/console/cake.php',
  274. '-working',
  275. '/cake/1.2.x.x/app',
  276. 'schema',
  277. 'run',
  278. 'create',
  279. '-dry',
  280. '-name',
  281. 'DbAcl'
  282. );
  283. $expected = array(
  284. 'app' => 'app',
  285. 'webroot' => 'webroot',
  286. 'working' => '/cake/1.2.x.x/app',
  287. 'root' => '/cake/1.2.x.x',
  288. 'dry' => 1,
  289. 'name' => 'DbAcl'
  290. );
  291. $Dispatcher->params = $Dispatcher->args = array();
  292. $Dispatcher->parseParams($params);
  293. $this->assertEqual($expected, $Dispatcher->params);
  294. $expected = array('/cake/1.2.x.x/cake/console/cake.php', 'schema', 'run', 'create');
  295. $this->assertEqual($expected, $Dispatcher->args);
  296. $params = array(
  297. 'cake.php',
  298. '-working',
  299. 'C:/wamp/www/cake/app',
  300. 'bake',
  301. '-app',
  302. 'C:/wamp/www/apps/cake/app',
  303. );
  304. $expected = array(
  305. 'app' => 'app',
  306. 'webroot' => 'webroot',
  307. 'working' => 'C:\wamp\www\apps\cake\app',
  308. 'root' => 'C:\wamp\www\apps\cake'
  309. );
  310. $Dispatcher->params = $Dispatcher->args = array();
  311. $Dispatcher->parseParams($params);
  312. $this->assertEqual($expected, $Dispatcher->params);
  313. $params = array(
  314. 'cake.php',
  315. '-working',
  316. 'C:\wamp\www\cake\app',
  317. 'bake',
  318. '-app',
  319. 'C:\wamp\www\apps\cake\app',
  320. );
  321. $expected = array(
  322. 'app' => 'app',
  323. 'webroot' => 'webroot',
  324. 'working' => 'C:\wamp\www\apps\cake\app',
  325. 'root' => 'C:\wamp\www\apps\cake'
  326. );
  327. $Dispatcher->params = $Dispatcher->args = array();
  328. $Dispatcher->parseParams($params);
  329. $this->assertEqual($expected, $Dispatcher->params);
  330. $params = array(
  331. 'cake.php',
  332. '-working',
  333. 'C:\wamp\www\apps',
  334. 'bake',
  335. '-app',
  336. 'cake\app',
  337. '-url',
  338. 'http://example.com/some/url/with/a/path'
  339. );
  340. $expected = array(
  341. 'app' => 'app',
  342. 'webroot' => 'webroot',
  343. 'working' => 'C:\wamp\www\apps\cake\app',
  344. 'root' => 'C:\wamp\www\apps\cake',
  345. 'url' => 'http://example.com/some/url/with/a/path'
  346. );
  347. $Dispatcher->params = $Dispatcher->args = array();
  348. $Dispatcher->parseParams($params);
  349. $this->assertEqual($expected, $Dispatcher->params);
  350. $params = array(
  351. '/home/amelo/dev/cake-common/cake/console/cake.php',
  352. '-root',
  353. '/home/amelo/dev/lsbu-vacancy',
  354. '-working',
  355. '/home/amelo/dev/lsbu-vacancy',
  356. '-app',
  357. 'app',
  358. );
  359. $expected = array(
  360. 'app' => 'app',
  361. 'webroot' => 'webroot',
  362. 'working' => '/home/amelo/dev/lsbu-vacancy/app',
  363. 'root' => '/home/amelo/dev/lsbu-vacancy',
  364. );
  365. $Dispatcher->params = $Dispatcher->args = array();
  366. $Dispatcher->parseParams($params);
  367. $this->assertEqual($expected, $Dispatcher->params);
  368. }
  369. /**
  370. * testBuildPaths method
  371. *
  372. * @access public
  373. * @return void
  374. */
  375. function testBuildPaths() {
  376. $Dispatcher =& new TestShellDispatcher();
  377. $result = $Dispatcher->shellPaths;
  378. $expected = array(
  379. TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS . 'vendors' . DS . 'shells' . DS,
  380. TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin_two' . DS . 'vendors' . DS . 'shells' . DS,
  381. APP . 'vendors' . DS . 'shells' . DS,
  382. VENDORS . 'shells' . DS,
  383. CORE_PATH ? CONSOLE_LIBS : ROOT . DS . CONSOLE_LIBS,
  384. TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors' . DS . 'shells' . DS,
  385. );
  386. $this->assertIdentical(array_diff($result, $expected), array());
  387. $this->assertIdentical(array_diff($expected, $result), array());
  388. }
  389. /**
  390. * testDispatch method
  391. *
  392. * @access public
  393. * @return void
  394. */
  395. function testDispatch() {
  396. $Dispatcher =& new TestShellDispatcher(array('sample'));
  397. $this->assertPattern('/This is the main method called from SampleShell/', $Dispatcher->stdout);
  398. $Dispatcher =& new TestShellDispatcher(array('test_plugin_two.example'));
  399. $this->assertPattern('/This is the main method called from TestPluginTwo.ExampleShell/', $Dispatcher->stdout);
  400. $Dispatcher =& new TestShellDispatcher(array('test_plugin_two.welcome', 'say_hello'));
  401. $this->assertPattern('/This is the say_hello method called from TestPluginTwo.WelcomeShell/', $Dispatcher->stdout);
  402. }
  403. /**
  404. * testHelpCommand method
  405. *
  406. * @access public
  407. * @return void
  408. */
  409. function testHelpCommand() {
  410. $Dispatcher =& new TestShellDispatcher();
  411. $expected = "/ CORE(\\\|\/)tests(\\\|\/)test_app(\\\|\/)plugins(\\\|\/)test_plugin(\\\|\/)vendors(\\\|\/)shells:";
  412. $expected .= "\n\t example";
  413. $expected .= "\n/";
  414. $this->assertPattern($expected, $Dispatcher->stdout);
  415. $expected = "/ CORE(\\\|\/)tests(\\\|\/)test_app(\\\|\/)plugins(\\\|\/)test_plugin_two(\\\|\/)vendors(\\\|\/)shells:";
  416. $expected .= "\n\t example";
  417. $expected .= "\n\t welcome";
  418. $expected .= "\n/";
  419. $this->assertPattern($expected, $Dispatcher->stdout);
  420. $expected = "/ APP(\\\|\/)vendors(\\\|\/)shells:";
  421. $expected .= "\n/";
  422. $this->assertPattern($expected, $Dispatcher->stdout);
  423. $expected = "/ ROOT(\\\|\/)vendors(\\\|\/)shells:";
  424. $expected .= "\n/";
  425. $this->assertPattern($expected, $Dispatcher->stdout);
  426. $expected = "/ CORE(\\\|\/)console(\\\|\/)libs:";
  427. $expected .= "\n\t acl";
  428. $expected .= "\n\t api";
  429. $expected .= "\n\t bake";
  430. $expected .= "\n\t console";
  431. $expected .= "\n\t i18n";
  432. $expected .= "\n\t schema";
  433. $expected .= "\n\t testsuite";
  434. $expected .= "\n/";
  435. $this->assertPattern($expected, $Dispatcher->stdout);
  436. $expected = "/ CORE(\\\|\/)tests(\\\|\/)test_app(\\\|\/)vendors(\\\|\/)shells:";
  437. $expected .= "\n\t sample";
  438. $expected .= "\n/";
  439. $this->assertPattern($expected, $Dispatcher->stdout);
  440. }
  441. }
  442. ?>