CommandListShellTest.php 3.1 KB

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