PageRenderTime 25ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://skygames.googlecode.com/
PHP | 481 lines | 320 code | 39 blank | 122 comment | 5 complexity | 88a74d9009c15e38c3a6d6314d484ffe MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, CC-BY-SA-3.0
  1. <?php
  2. /* SVN FILE: $Id: cake.test.php 7871 2008-11-13 00:33:53Z renan.saddam $ */
  3. /**
  4. * Short description for 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.tests
  20. * @subpackage cake.tests.cases.console
  21. * @since CakePHP(tm) v 1.2.0.5432
  22. * @version $Revision: 7871 $
  23. * @modifiedby $LastChangedBy: renan.saddam $
  24. * @lastmodified $Date: 2008-11-12 18:33:53 -0600 (Wed, 12 Nov 2008) $
  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. /**
  81. * stderr method
  82. *
  83. * @access public
  84. * @return void
  85. */
  86. function stderr($string) {
  87. $this->stderr .= rtrim($string, ' ');
  88. }
  89. /**
  90. * stdout method
  91. *
  92. * @access public
  93. * @return void
  94. */
  95. function stdout($string, $newline = true) {
  96. if ($newline) {
  97. $this->stdout .= rtrim($string, ' ') . "\n";
  98. } else {
  99. $this->stdout .= rtrim($string, ' ');
  100. }
  101. }
  102. /**
  103. * _stop method
  104. *
  105. * @access protected
  106. * @return void
  107. */
  108. function _stop($status = 0) {
  109. $this->stopped = 'Stopped with status: ' . $status;
  110. }
  111. }
  112. /**
  113. * Short description for class.
  114. *
  115. * @package cake.tests
  116. * @subpackage cake.tests.cases.libs
  117. */
  118. class ShellDispatcherTest extends UnitTestCase {
  119. /**
  120. * setUp method
  121. *
  122. * @access public
  123. * @return void
  124. */
  125. function setUp() {
  126. if (!isset($this->pluginPaths)) {
  127. $this->pluginPaths = Configure::read('pluginPaths');
  128. $this->shellPaths = Configure::read('shellPaths');
  129. }
  130. Configure::write('pluginPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS));
  131. Configure::write('shellPaths', array(
  132. ROOT . DS . CONSOLE_LIBS,
  133. TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors' . DS . 'shells' . DS
  134. ));
  135. }
  136. /**
  137. * tearDown method
  138. *
  139. * @access public
  140. * @return void
  141. */
  142. function tearDown() {
  143. Configure::write('pluginPaths', $this->pluginPaths);
  144. Configure::write('shellPaths', $this->shellPaths);
  145. }
  146. /**
  147. * testParseParams method
  148. *
  149. * @access public
  150. * @return void
  151. */
  152. function testParseParams() {
  153. $Dispatcher =& new TestShellDispatcher();
  154. $params = array(
  155. '/cake/1.2.x.x/cake/console/cake.php',
  156. 'bake',
  157. '-app',
  158. 'new',
  159. '-working',
  160. '/var/www/htdocs'
  161. );
  162. $expected = array(
  163. 'app' => 'new',
  164. 'webroot' => 'webroot',
  165. 'working' => '/var/www/htdocs/new',
  166. 'root' => '/var/www/htdocs'
  167. );
  168. $Dispatcher->parseParams($params);
  169. $this->assertEqual($expected, $Dispatcher->params);
  170. $params = array('cake.php');
  171. $expected = array(
  172. 'app' => 'app',
  173. 'webroot' => 'webroot',
  174. 'working' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH . DS . 'app'),
  175. 'root' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH),
  176. );
  177. $Dispatcher->params = $Dispatcher->args = array();
  178. $Dispatcher->parseParams($params);
  179. $this->assertEqual($expected, $Dispatcher->params);
  180. $params = array(
  181. 'cake.php',
  182. '-app',
  183. 'new',
  184. );
  185. $expected = array(
  186. 'app' => 'new',
  187. 'webroot' => 'webroot',
  188. 'working' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH . DS . 'new'),
  189. 'root' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH)
  190. );
  191. $Dispatcher->params = $Dispatcher->args = array();
  192. $Dispatcher->parseParams($params);
  193. $this->assertEqual($expected, $Dispatcher->params);
  194. $params = array(
  195. './cake.php',
  196. 'bake',
  197. '-app',
  198. 'new',
  199. '-working',
  200. '/cake/1.2.x.x/cake/console'
  201. );
  202. $expected = array(
  203. 'app' => 'new',
  204. 'webroot' => 'webroot',
  205. 'working' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH . DS . 'new'),
  206. 'root' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH)
  207. );
  208. $Dispatcher->params = $Dispatcher->args = array();
  209. $Dispatcher->parseParams($params);
  210. $this->assertEqual($expected, $Dispatcher->params);
  211. $params = array(
  212. './console/cake.php',
  213. 'bake',
  214. '-app',
  215. 'new',
  216. '-working',
  217. '/cake/1.2.x.x/cake'
  218. );
  219. $expected = array(
  220. 'app' => 'new',
  221. 'webroot' => 'webroot',
  222. 'working' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH . DS . 'new'),
  223. 'root' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH)
  224. );
  225. $Dispatcher->params = $Dispatcher->args = array();
  226. $Dispatcher->parseParams($params);
  227. $this->assertEqual($expected, $Dispatcher->params);
  228. $params = array(
  229. './console/cake.php',
  230. 'bake',
  231. '-app',
  232. 'new',
  233. '-dry',
  234. '-working',
  235. '/cake/1.2.x.x/cake'
  236. );
  237. $expected = array(
  238. 'app' => 'new',
  239. 'webroot' => 'webroot',
  240. 'working' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH . DS . 'new'),
  241. 'root' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH),
  242. 'dry' => 1
  243. );
  244. $Dispatcher->params = $Dispatcher->args = array();
  245. $Dispatcher->parseParams($params);
  246. $this->assertEqual($expected, $Dispatcher->params);
  247. $params = array(
  248. './console/cake.php',
  249. '-working',
  250. '/cake/1.2.x.x/cake',
  251. 'schema',
  252. 'run',
  253. 'create',
  254. '-dry',
  255. '-f',
  256. '-name',
  257. 'DbAcl'
  258. );
  259. $expected = array(
  260. 'app' => 'app',
  261. 'webroot' => 'webroot',
  262. 'working' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH . DS . 'app'),
  263. 'root' => str_replace('\\', '/', CAKE_CORE_INCLUDE_PATH),
  264. 'dry' => 1,
  265. 'f' => 1,
  266. 'name' => 'DbAcl'
  267. );
  268. $Dispatcher->params = $Dispatcher->args = array();
  269. $Dispatcher->parseParams($params);
  270. $this->assertEqual($expected, $Dispatcher->params);
  271. $expected = array('./console/cake.php', 'schema', 'run', 'create');
  272. $this->assertEqual($expected, $Dispatcher->args);
  273. $params = array(
  274. '/cake/1.2.x.x/cake/console/cake.php',
  275. '-working',
  276. '/cake/1.2.x.x/app',
  277. 'schema',
  278. 'run',
  279. 'create',
  280. '-dry',
  281. '-name',
  282. 'DbAcl'
  283. );
  284. $expected = array(
  285. 'app' => 'app',
  286. 'webroot' => 'webroot',
  287. 'working' => '/cake/1.2.x.x/app',
  288. 'root' => '/cake/1.2.x.x',
  289. 'dry' => 1,
  290. 'name' => 'DbAcl'
  291. );
  292. $Dispatcher->params = $Dispatcher->args = array();
  293. $Dispatcher->parseParams($params);
  294. $this->assertEqual($expected, $Dispatcher->params);
  295. $expected = array('/cake/1.2.x.x/cake/console/cake.php', 'schema', 'run', 'create');
  296. $this->assertEqual($expected, $Dispatcher->args);
  297. $params = array(
  298. 'cake.php',
  299. '-working',
  300. 'C:/wamp/www/cake/app',
  301. 'bake',
  302. '-app',
  303. 'C:/wamp/www/apps/cake/app',
  304. );
  305. $expected = array(
  306. 'app' => 'app',
  307. 'webroot' => 'webroot',
  308. 'working' => 'C:\wamp\www\apps\cake\app',
  309. 'root' => 'C:\wamp\www\apps\cake'
  310. );
  311. $Dispatcher->params = $Dispatcher->args = array();
  312. $Dispatcher->parseParams($params);
  313. $this->assertEqual($expected, $Dispatcher->params);
  314. $params = array(
  315. 'cake.php',
  316. '-working',
  317. 'C:\wamp\www\cake\app',
  318. 'bake',
  319. '-app',
  320. 'C:\wamp\www\apps\cake\app',
  321. );
  322. $expected = array(
  323. 'app' => 'app',
  324. 'webroot' => 'webroot',
  325. 'working' => 'C:\wamp\www\apps\cake\app',
  326. 'root' => 'C:\wamp\www\apps\cake'
  327. );
  328. $Dispatcher->params = $Dispatcher->args = array();
  329. $Dispatcher->parseParams($params);
  330. $this->assertEqual($expected, $Dispatcher->params);
  331. $params = array(
  332. 'cake.php',
  333. '-working',
  334. 'C:\wamp\www\apps',
  335. 'bake',
  336. '-app',
  337. 'cake\app',
  338. '-url',
  339. 'http://example.com/some/url/with/a/path'
  340. );
  341. $expected = array(
  342. 'app' => 'app',
  343. 'webroot' => 'webroot',
  344. 'working' => 'C:\wamp\www\apps\cake\app',
  345. 'root' => 'C:\wamp\www\apps\cake',
  346. 'url' => 'http://example.com/some/url/with/a/path'
  347. );
  348. $Dispatcher->params = $Dispatcher->args = array();
  349. $Dispatcher->parseParams($params);
  350. $this->assertEqual($expected, $Dispatcher->params);
  351. $params = array(
  352. '/home/amelo/dev/cake-common/cake/console/cake.php',
  353. '-root',
  354. '/home/amelo/dev/lsbu-vacancy',
  355. '-working',
  356. '/home/amelo/dev/lsbu-vacancy',
  357. '-app',
  358. 'app',
  359. );
  360. $expected = array(
  361. 'app' => 'app',
  362. 'webroot' => 'webroot',
  363. 'working' => '/home/amelo/dev/lsbu-vacancy/app',
  364. 'root' => '/home/amelo/dev/lsbu-vacancy',
  365. );
  366. $Dispatcher->params = $Dispatcher->args = array();
  367. $Dispatcher->parseParams($params);
  368. $this->assertEqual($expected, $Dispatcher->params);
  369. }
  370. /**
  371. * testBuildPaths method
  372. *
  373. * @access public
  374. * @return void
  375. */
  376. function testBuildPaths() {
  377. $Dispatcher =& new TestShellDispatcher();
  378. $this->assertEqual($Dispatcher->shellPaths, 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. ROOT . DS . CONSOLE_LIBS,
  384. TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors' . DS . 'shells' . DS,
  385. ));
  386. }
  387. /**
  388. * testDispatch method
  389. *
  390. * @access public
  391. * @return void
  392. */
  393. function testDispatch() {
  394. $Dispatcher =& new TestShellDispatcher(array('sample'));
  395. $this->assertPattern('/This is the main method called from SampleShell/', $Dispatcher->stdout);
  396. $Dispatcher =& new TestShellDispatcher(array('test_plugin_two.example'));
  397. $this->assertPattern('/This is the main method called from TestPluginTwo.ExampleShell/', $Dispatcher->stdout);
  398. $Dispatcher =& new TestShellDispatcher(array('test_plugin_two.welcome', 'say_hello'));
  399. $this->assertPattern('/This is the say_hello method called from TestPluginTwo.WelcomeShell/', $Dispatcher->stdout);
  400. }
  401. /**
  402. * testHelpCommand method
  403. *
  404. * @access public
  405. * @return void
  406. */
  407. function testHelpCommand() {
  408. $Dispatcher =& new TestShellDispatcher();
  409. $expected = "/ ROOT(\\\|\/)cake(\\\|\/)tests(\\\|\/)test_app(\\\|\/)plugins(\\\|\/)test_plugin(\\\|\/)vendors(\\\|\/)shells:";
  410. $expected .= "\n\t example";
  411. $expected .= "\n/";
  412. $this->assertPattern($expected, $Dispatcher->stdout);
  413. $expected = "/ ROOT(\\\|\/)cake(\\\|\/)tests(\\\|\/)test_app(\\\|\/)plugins(\\\|\/)test_plugin_two(\\\|\/)vendors(\\\|\/)shells:";
  414. $expected .= "\n\t example";
  415. $expected .= "\n\t welcome";
  416. $expected .= "\n/";
  417. $this->assertPattern($expected, $Dispatcher->stdout);
  418. $expected = "/ ROOT(\\\|\/)app(\\\|\/)vendors(\\\|\/)shells:";
  419. $expected .= "\n\t - none";
  420. $expected .= "\n/";
  421. $this->assertPattern($expected, $Dispatcher->stdout);
  422. $expected = "/ ROOT(\\\|\/)vendors(\\\|\/)shells:";
  423. $expected .= "\n\t - none";
  424. $expected .= "\n/";
  425. $this->assertPattern($expected, $Dispatcher->stdout);
  426. $expected = "/ ROOT(\\\|\/)cake(\\\|\/)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 = "/ ROOT(\\\|\/)cake(\\\|\/)tests(\\\|\/)test_app(\\\|\/)vendors(\\\|\/)shells:";
  437. $expected .= "\n\t sample";
  438. $expected .= "\n/";
  439. $this->assertPattern($expected, $Dispatcher->stdout);
  440. }
  441. }
  442. ?>