LoadTaskTest.php 5.3 KB

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