CommandListShellTest.php 4.2 KB

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