CommandListShellTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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\Core\App;
  20. use Cake\Core\Plugin;
  21. use Cake\Shell\CommandListShell;
  22. use Cake\Shell\Task\CommandTask;
  23. use Cake\TestSuite\Stub\ConsoleOutput;
  24. use Cake\TestSuite\TestCase;
  25. /**
  26. * Class CommandListShellTest
  27. *
  28. */
  29. class CommandListShellTest extends TestCase
  30. {
  31. /**
  32. * setUp method
  33. *
  34. * @return void
  35. */
  36. public function setUp()
  37. {
  38. parent::setUp();
  39. Plugin::load(['TestPlugin', 'TestPluginTwo']);
  40. $this->out = new ConsoleOutput();
  41. $io = new ConsoleIo($this->out);
  42. $this->Shell = $this->getMock(
  43. 'Cake\Shell\CommandListShell',
  44. ['in', 'err', '_stop', 'clear'],
  45. [$io]
  46. );
  47. $this->Shell->Command = $this->getMock(
  48. 'Cake\Shell\Task\CommandTask',
  49. ['in', '_stop', 'err', 'clear'],
  50. [$io]
  51. );
  52. }
  53. /**
  54. * tearDown
  55. *
  56. * @return void
  57. */
  58. public function tearDown()
  59. {
  60. parent::tearDown();
  61. unset($this->Shell);
  62. Plugin::unload();
  63. }
  64. /**
  65. * test that main finds core shells.
  66. *
  67. * @return void
  68. */
  69. public function testMain()
  70. {
  71. $this->Shell->main();
  72. $output = $this->out->messages();
  73. $output = implode("\n", $output);
  74. $expected = "/\[.*TestPlugin.*\] example/";
  75. $this->assertRegExp($expected, $output);
  76. $expected = "/\[.*TestPluginTwo.*\] example, welcome/";
  77. $this->assertRegExp($expected, $output);
  78. $expected = "/\[.*CORE.*\] i18n, orm_cache, plugin, server/";
  79. $this->assertRegExp($expected, $output);
  80. $expected = "/\[.*app.*\] i18m, sample/";
  81. $this->assertRegExp($expected, $output);
  82. }
  83. /**
  84. * If there is an app shell with the same name as a core shell,
  85. * tests that the app shell is the one displayed and the core one is hidden.
  86. *
  87. * @return void
  88. */
  89. public function testMainAppPriority()
  90. {
  91. rename(APP . 'Shell' . DS . 'I18mShell.php', APP . 'Shell' . DS . 'I18nShell.php');
  92. $this->Shell->main();
  93. $output = $this->out->messages();
  94. $output = implode("\n", $output);
  95. $expected = "/\[.*CORE.*\] orm_cache, plugin, server/";
  96. $this->assertRegExp($expected, $output);
  97. $expected = "/\[.*app.*\] i18n, sample/";
  98. $this->assertRegExp($expected, $output);
  99. rename(APP . 'Shell' . DS . 'I18nShell.php', APP . 'Shell' . DS . 'I18mShell.php');
  100. }
  101. /**
  102. * test xml output.
  103. *
  104. * @return void
  105. */
  106. public function testMainXml()
  107. {
  108. $this->Shell->params['xml'] = true;
  109. $this->Shell->main();
  110. $output = $this->out->messages();
  111. $output = implode("\n", $output);
  112. $find = '<shell name="sample" call_as="sample" provider="app" help="sample -h"';
  113. $this->assertContains($find, $output);
  114. $find = '<shell name="orm_cache" call_as="orm_cache" provider="CORE" help="orm_cache -h"';
  115. $this->assertContains($find, $output);
  116. $find = '<shell name="welcome" call_as="TestPluginTwo.welcome" provider="TestPluginTwo" help="TestPluginTwo.welcome -h"';
  117. $this->assertContains($find, $output);
  118. }
  119. }