CommandListShellTest.php 3.8 KB

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