CommandListShellTest.php 3.7 KB

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