LoadTaskTest.php 5.4 KB

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