CommandListShellTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * CommandListShellTest file
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP : Rapid Development Framework (http://cakephp.org)
  8. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * For full copyright and license information, please see the LICENSE.txt
  12. * Redistributions of files must retain the above copyright notice.
  13. *
  14. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  15. * @link http://cakephp.org CakePHP Project
  16. * @package Cake.Test.Case.Console.Command
  17. * @since CakePHP v 2.0
  18. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  19. */
  20. App::uses('CommandListShell', 'Console/Command');
  21. App::uses('ConsoleOutput', 'Console');
  22. App::uses('ConsoleInput', 'Console');
  23. App::uses('Shell', 'Console');
  24. class TestStringOutput extends ConsoleOutput {
  25. public $output = '';
  26. protected function _write($message) {
  27. $this->output .= $message;
  28. }
  29. }
  30. class CommandListShellTest extends CakeTestCase {
  31. /**
  32. * setUp method
  33. *
  34. * @return void
  35. */
  36. public function setUp() {
  37. parent::setUp();
  38. App::build(array(
  39. 'Plugin' => array(
  40. CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS
  41. ),
  42. 'Console/Command' => array(
  43. CAKE . 'Test' . DS . 'test_app' . DS . 'Console' . DS . 'Command' . DS
  44. )
  45. ), App::RESET);
  46. CakePlugin::load(array('TestPlugin', 'TestPluginTwo'));
  47. $out = new TestStringOutput();
  48. $in = $this->getMock('ConsoleInput', array(), array(), '', false);
  49. $this->Shell = $this->getMock(
  50. 'CommandListShell',
  51. array('in', '_stop', 'clear'),
  52. array($out, $out, $in)
  53. );
  54. }
  55. /**
  56. * tearDown
  57. *
  58. * @return void
  59. */
  60. public function tearDown() {
  61. parent::tearDown();
  62. unset($this->Shell);
  63. CakePlugin::unload();
  64. }
  65. /**
  66. * test that main finds core shells.
  67. *
  68. * @return void
  69. */
  70. public function testMain() {
  71. $this->Shell->main();
  72. $output = $this->Shell->stdout->output;
  73. $expected = "/\[.*TestPlugin.*\] example/";
  74. $this->assertRegExp($expected, $output);
  75. $expected = "/\[.*TestPluginTwo.*\] example, welcome/";
  76. $this->assertRegExp($expected, $output);
  77. $expected = "/\[.*CORE.*\] acl, api, bake, command_list, console, i18n, schema, server, test, testsuite, upgrade/";
  78. $this->assertRegExp($expected, $output);
  79. $expected = "/\[.*app.*\] sample/";
  80. $this->assertRegExp($expected, $output);
  81. }
  82. /**
  83. * test xml output.
  84. *
  85. * @return void
  86. */
  87. public function testMainXml() {
  88. $this->Shell->params['xml'] = true;
  89. $this->Shell->main();
  90. $output = $this->Shell->stdout->output;
  91. $find = '<shell name="sample" call_as="sample" provider="app" help="sample -h"/>';
  92. $this->assertContains($find, $output);
  93. $find = '<shell name="bake" call_as="bake" provider="CORE" help="bake -h"/>';
  94. $this->assertContains($find, $output);
  95. $find = '<shell name="welcome" call_as="TestPluginTwo.welcome" provider="TestPluginTwo" help="TestPluginTwo.welcome -h"/>';
  96. $this->assertContains($find, $output);
  97. }
  98. }