CommandListShellTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. /**
  3. * CommandListShellTest file
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP : Rapid Development Framework (http://cakephp.org)
  8. * Copyright 2005-2011, Cake Software Foundation, Inc.
  9. *
  10. * Licensed under The MIT License
  11. * Redistributions of files must retain the above copyright notice.
  12. *
  13. * @copyright Copyright 2005-2011, Cake Software Foundation, Inc.
  14. * @link http://cakephp.org CakePHP Project
  15. * @package Cake.Test.Case.Console.Command
  16. * @since CakePHP v 2.0
  17. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  18. */
  19. App::uses('CommandListShell', 'Console/Command');
  20. App::uses('ConsoleOutput', 'Console');
  21. App::uses('ConsoleInput', 'Console');
  22. App::uses('Shell', 'Console');
  23. class TestStringOutput extends ConsoleOutput {
  24. public $output = '';
  25. protected function _write($message) {
  26. $this->output .= $message;
  27. }
  28. }
  29. class CommandListShellTest extends CakeTestCase {
  30. /**
  31. * setUp method
  32. *
  33. * @return void
  34. */
  35. public function setUp() {
  36. parent::setUp();
  37. App::build(array(
  38. 'Plugin' => array(
  39. CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS
  40. ),
  41. 'Console/Command' => array(
  42. CAKE . 'Test' . DS . 'test_app' . DS . 'Console' . DS . 'Command' . DS
  43. )
  44. ), App::RESET);
  45. CakePlugin::load(array('TestPlugin', 'TestPluginTwo'));
  46. $out = new TestStringOutput();
  47. $in = $this->getMock('ConsoleInput', array(), array(), '', false);
  48. $this->Shell = $this->getMock(
  49. 'CommandListShell',
  50. array('in', '_stop', 'clear'),
  51. array($out, $out, $in)
  52. );
  53. }
  54. /**
  55. * tearDown
  56. *
  57. * @return void
  58. */
  59. public function tearDown() {
  60. parent::tearDown();
  61. unset($this->Shell);
  62. CakePlugin::unload();
  63. }
  64. /**
  65. * test that main finds core shells.
  66. *
  67. * @return void
  68. */
  69. public function testMain() {
  70. $this->Shell->main();
  71. $output = $this->Shell->stdout->output;
  72. $expected = "/example \[.*TestPlugin, TestPluginTwo.*\]/";
  73. $this->assertRegExp($expected, $output);
  74. $expected = "/welcome \[.*TestPluginTwo.*\]/";
  75. $this->assertRegExp($expected, $output);
  76. $expected = "/acl \[.*CORE.*\]/";
  77. $this->assertRegExp($expected, $output);
  78. $expected = "/api \[.*CORE.*\]/";
  79. $this->assertRegExp($expected, $output);
  80. $expected = "/bake \[.*CORE.*\]/";
  81. $this->assertRegExp($expected, $output);
  82. $expected = "/console \[.*CORE.*\]/";
  83. $this->assertRegExp($expected, $output);
  84. $expected = "/i18n \[.*CORE.*\]/";
  85. $this->assertRegExp($expected, $output);
  86. $expected = "/schema \[.*CORE.*\]/";
  87. $this->assertRegExp($expected, $output);
  88. $expected = "/testsuite \[.*CORE.*\]/";
  89. $this->assertRegExp($expected, $output);
  90. $expected = "/sample \[.*app.*\]/";
  91. $this->assertRegExp($expected, $output);
  92. }
  93. /**
  94. * Test the sort param
  95. *
  96. * @return void
  97. */
  98. public function testSortPlugin() {
  99. $this->Shell->params['sort'] = true;
  100. $this->Shell->main();
  101. $output = $this->Shell->stdout->output;
  102. $expected = "/\[.*App.*\]\\v*[ ]+sample/";
  103. $this->assertRegExp($expected, $output);
  104. $expected = "/\[.*TestPluginTwo.*\]\\v*[ ]+example, welcome/";
  105. $this->assertRegExp($expected, $output);
  106. $expected = "/\[.*TestPlugin.*\]\\v*[ ]+example/";
  107. $this->assertRegExp($expected, $output);
  108. $expected = "/\[.*Core.*\]\\v*[ ]+acl, api, bake, command_list, console, i18n, schema, test, testsuite/";
  109. $this->assertRegExp($expected, $output);
  110. }
  111. /**
  112. * test xml output.
  113. *
  114. * @return void
  115. */
  116. public function testMainXml() {
  117. $this->Shell->params['xml'] = true;
  118. $this->Shell->main();
  119. $output = $this->Shell->stdout->output;
  120. $find = '<shell name="sample" call_as="sample" provider="app" help="sample -h"/>';
  121. $this->assertContains($find, $output);
  122. $find = '<shell name="bake" call_as="bake" provider="CORE" help="bake -h"/>';
  123. $this->assertContains($find, $output);
  124. $find = '<shell name="welcome" call_as="TestPluginTwo.welcome" provider="TestPluginTwo" help="TestPluginTwo.welcome -h"/>';
  125. $this->assertContains($find, $output);
  126. }
  127. }