LoadTaskTest.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <?php
  2. /**
  3. * CakePHP : Rapid Development Framework (https://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (https://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. (https://cakefoundation.org)
  11. * @link https://cakephp.org CakePHP Project
  12. * @license https://opensource.org/licenses/mit-license.php MIT License
  13. */
  14. namespace Cake\Test\TestCase\Shell\Task;
  15. use Cake\Console\Shell;
  16. use Cake\Filesystem\File;
  17. use Cake\TestSuite\ConsoleIntegrationTestCase;
  18. /**
  19. * LoadTaskTest class.
  20. */
  21. class LoadTaskTest extends ConsoleIntegrationTestCase
  22. {
  23. /**
  24. * setUp method
  25. *
  26. * @return void
  27. */
  28. public function setUp()
  29. {
  30. parent::setUp();
  31. $this->app = APP . DS . 'Application.php';
  32. $this->bootstrap = ROOT . DS . 'config' . DS . 'bootstrap.php';
  33. $this->bootstrapCli = ROOT . DS . 'config' . DS . 'bootstrap_cli.php';
  34. copy($this->bootstrap, $this->bootstrapCli);
  35. $bootstrap = new File($this->bootstrap, false);
  36. $this->originalBootstrapContent = $bootstrap->read();
  37. $app = new File($this->app, false);
  38. $this->originalAppContent = $app->read();
  39. }
  40. /**
  41. * tearDown method
  42. *
  43. * @return void
  44. */
  45. public function tearDown()
  46. {
  47. parent::tearDown();
  48. $bootstrap = new File($this->bootstrap, false);
  49. $bootstrap->write($this->originalBootstrapContent);
  50. unlink($this->bootstrapCli);
  51. $app = new File($this->app, false);
  52. $app->write($this->originalAppContent);
  53. }
  54. /**
  55. * testLoad
  56. *
  57. * @return void
  58. */
  59. public function testLoad()
  60. {
  61. $this->exec('plugin load --no_app --autoload TestPlugin');
  62. $this->assertExitCode(Shell::CODE_SUCCESS);
  63. $contents = file_get_contents($this->bootstrap);
  64. $this->assertContains(
  65. "Plugin::load('TestPlugin', ['autoload' => true]);",
  66. $contents
  67. );
  68. }
  69. /**
  70. * testLoadWithBootstrap
  71. *
  72. * @return void
  73. */
  74. public function testLoadWithBootstrap()
  75. {
  76. $this->exec('plugin load --no_app --bootstrap --autoload TestPlugin');
  77. $this->assertExitCode(Shell::CODE_SUCCESS);
  78. $contents = file_get_contents($this->bootstrap);
  79. $this->assertContains(
  80. "Plugin::load('TestPlugin', ['autoload' => true, 'bootstrap' => true]);",
  81. $contents
  82. );
  83. }
  84. /**
  85. * Tests that loading with bootstrap_cli works.
  86. *
  87. * @return void
  88. */
  89. public function testLoadBootstrapCli()
  90. {
  91. $this->exec('plugin load --no_app --cli TestPlugin');
  92. $this->assertExitCode(Shell::CODE_SUCCESS);
  93. $contents = file_get_contents($this->bootstrapCli);
  94. $this->assertContains(
  95. "Plugin::load('TestPlugin');",
  96. $contents
  97. );
  98. }
  99. /**
  100. * testLoadWithRoutes
  101. *
  102. * @return void
  103. */
  104. public function testLoadWithRoutes()
  105. {
  106. $this->exec('plugin load --no_app --routes --autoload TestPlugin');
  107. $this->assertExitCode(Shell::CODE_SUCCESS);
  108. $contents = file_get_contents($this->bootstrap);
  109. $this->assertContains(
  110. "Plugin::load('TestPlugin', ['autoload' => true, 'routes' => true]);",
  111. $contents
  112. );
  113. }
  114. /**
  115. * test load no autoload
  116. *
  117. * @return void
  118. */
  119. public function testLoadNoAutoload()
  120. {
  121. $this->exec('plugin load --no_app --routes TestPlugin');
  122. $this->assertExitCode(Shell::CODE_SUCCESS);
  123. $contents = file_get_contents($this->bootstrap);
  124. $this->assertContains("Plugin::load('TestPlugin', ['routes' => true]);", $contents);
  125. }
  126. /**
  127. * testLoad
  128. *
  129. * @return void
  130. */
  131. public function testLoadNothing()
  132. {
  133. $this->exec('plugin load --no_app TestPlugin');
  134. $this->assertExitCode(Shell::CODE_SUCCESS);
  135. $contents = file_get_contents($this->bootstrap);
  136. $this->assertContains("Plugin::load('TestPlugin');", $contents);
  137. }
  138. /**
  139. * Test loading the app
  140. *
  141. * @return void
  142. */
  143. public function testLoadApp()
  144. {
  145. $this->exec('plugin load TestPlugin');
  146. $this->assertExitCode(Shell::CODE_SUCCESS);
  147. $contents = file_get_contents($this->app);
  148. $this->assertContains("\$this->addPlugin('TestPlugin');", $contents);
  149. }
  150. /**
  151. * Test loading the app
  152. *
  153. * @return void
  154. */
  155. public function testLoadAppBootstrap()
  156. {
  157. $this->exec('plugin load --bootstrap TestPlugin');
  158. $this->assertExitCode(Shell::CODE_SUCCESS);
  159. $contents = file_get_contents($this->app);
  160. $this->assertContains("\$this->addPlugin('TestPlugin', ['bootstrap' => true]);", $contents);
  161. }
  162. /**
  163. * Test loading the app
  164. *
  165. * @return void
  166. */
  167. public function testLoadAppRoutes()
  168. {
  169. $this->exec('plugin load --routes TestPlugin');
  170. $this->assertExitCode(Shell::CODE_SUCCESS);
  171. $contents = file_get_contents($this->app);
  172. $this->assertContains("\$this->addPlugin('TestPlugin', ['routes' => true]);", $contents);
  173. }
  174. }