CommandListShellTest.php 3.2 KB

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