CommandListShellTest.php 4.1 KB

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