LoadTaskTest.php 5.3 KB

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