CommandListShellTest.php 4.2 KB

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