CommandListShellTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. * @since CakePHP v 2.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\Console\Command;
  16. use Cake\Console\Command\CommandListShell;
  17. use Cake\Console\Command\Task\CommandTask;
  18. use Cake\Console\ConsoleOutput;
  19. use Cake\Core\App;
  20. use Cake\Core\Plugin;
  21. use Cake\TestSuite\TestCase;
  22. /**
  23. * Class TestStringOutput
  24. *
  25. */
  26. class TestStringOutput extends ConsoleOutput {
  27. public $output = '';
  28. protected function _write($message) {
  29. $this->output .= $message;
  30. }
  31. }
  32. /**
  33. * Class CommandListShellTest
  34. *
  35. */
  36. class CommandListShellTest extends TestCase {
  37. /**
  38. * setUp method
  39. *
  40. * @return void
  41. */
  42. public function setUp() {
  43. parent::setUp();
  44. Plugin::load(array('TestPlugin', 'TestPluginTwo'));
  45. $out = new TestStringOutput();
  46. $in = $this->getMock('Cake\Console\ConsoleInput', array(), array(), '', false);
  47. $this->Shell = $this->getMock(
  48. 'Cake\Console\Command\CommandListShell',
  49. array('in', '_stop', 'clear'),
  50. array($out, $out, $in)
  51. );
  52. $this->Shell->Command = $this->getMock(
  53. 'Cake\Console\Command\Task\CommandTask',
  54. array('in', '_stop', 'clear'),
  55. array($out, $out, $in)
  56. );
  57. }
  58. /**
  59. * tearDown
  60. *
  61. * @return void
  62. */
  63. public function tearDown() {
  64. parent::tearDown();
  65. unset($this->Shell);
  66. Plugin::unload();
  67. }
  68. /**
  69. * test that main finds core shells.
  70. *
  71. * @return void
  72. */
  73. public function testMain() {
  74. $this->Shell->main();
  75. $output = $this->Shell->stdout->output;
  76. $expected = "/\[.*TestPlugin.*\] example/";
  77. $this->assertRegExp($expected, $output);
  78. $expected = "/\[.*TestPluginTwo.*\] example, welcome/";
  79. $this->assertRegExp($expected, $output);
  80. $expected = "/\[.*CORE.*\] acl, api, bake, command_list, completion, i18n, server, test, upgrade/";
  81. $this->assertRegExp($expected, $output);
  82. $expected = "/\[.*app.*\] sample/";
  83. $this->assertRegExp($expected, $output);
  84. }
  85. /**
  86. * test xml output.
  87. *
  88. * @return void
  89. */
  90. public function testMainXml() {
  91. $this->Shell->params['xml'] = true;
  92. $this->Shell->main();
  93. $output = $this->Shell->stdout->output;
  94. $find = '<shell name="sample" call_as="sample" provider="app" help="sample -h"/>';
  95. $this->assertContains($find, $output);
  96. $find = '<shell name="bake" call_as="bake" provider="CORE" help="bake -h"/>';
  97. $this->assertContains($find, $output);
  98. $find = '<shell name="welcome" call_as="TestPluginTwo.welcome" provider="TestPluginTwo" help="TestPluginTwo.welcome -h"/>';
  99. $this->assertContains($find, $output);
  100. }
  101. }