LoadTaskTest.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. /**
  3. * CakePHP : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://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. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP Project
  12. * @license http://www.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. */
  22. class LoadTaskTest extends TestCase
  23. {
  24. /**
  25. * setUp method
  26. *
  27. * @return void
  28. */
  29. public function setUp()
  30. {
  31. parent::setUp();
  32. $this->io = $this->getMockBuilder('Cake\Console\ConsoleIo')
  33. ->disableOriginalConstructor()
  34. ->getMock();
  35. $this->Task = $this->getMockBuilder('Cake\Shell\Task\LoadTask')
  36. ->setMethods(['in', 'out', 'err', '_stop'])
  37. ->setConstructorArgs([$this->io])
  38. ->getMock();
  39. $this->bootstrap = ROOT . DS . 'config' . DS . 'bootstrap.php';
  40. $bootstrap = new File($this->bootstrap, false);
  41. $this->originalBootstrapContent = $bootstrap->read();
  42. }
  43. /**
  44. * tearDown method
  45. *
  46. * @return void
  47. */
  48. public function tearDown()
  49. {
  50. parent::tearDown();
  51. unset($this->shell);
  52. Plugin::unload();
  53. $bootstrap = new File($this->bootstrap, false);
  54. $bootstrap->write($this->originalBootstrapContent);
  55. }
  56. /**
  57. * testLoad
  58. *
  59. * @return void
  60. */
  61. public function testLoad()
  62. {
  63. $this->Task->params = [
  64. 'bootstrap' => false,
  65. 'routes' => false,
  66. 'autoload' => true,
  67. ];
  68. $action = $this->Task->main('TestPlugin');
  69. $this->assertTrue($action);
  70. $expected = "Plugin::load('TestPlugin', ['autoload' => true]);";
  71. $bootstrap = new File($this->bootstrap, false);
  72. $this->assertContains($expected, $bootstrap->read());
  73. }
  74. /**
  75. * testLoadWithBootstrap
  76. *
  77. * @return void
  78. */
  79. public function testLoadWithBootstrap()
  80. {
  81. $this->Task->params = [
  82. 'bootstrap' => true,
  83. 'routes' => false,
  84. 'autoload' => true,
  85. ];
  86. $action = $this->Task->main('TestPlugin');
  87. $this->assertTrue($action);
  88. $expected = "Plugin::load('TestPlugin', ['autoload' => true, 'bootstrap' => true]);";
  89. $bootstrap = new File($this->bootstrap, false);
  90. $this->assertContains($expected, $bootstrap->read());
  91. }
  92. /**
  93. * testLoadWithRoutes
  94. *
  95. * @return void
  96. */
  97. public function testLoadWithRoutes()
  98. {
  99. $this->Task->params = [
  100. 'bootstrap' => false,
  101. 'routes' => true,
  102. 'autoload' => true,
  103. ];
  104. $action = $this->Task->main('TestPlugin');
  105. $this->assertTrue($action);
  106. $expected = "Plugin::load('TestPlugin', ['autoload' => true, 'routes' => true]);";
  107. $bootstrap = new File($this->bootstrap, false);
  108. $this->assertContains($expected, $bootstrap->read());
  109. }
  110. /**
  111. * test load no autoload
  112. *
  113. * @return void
  114. */
  115. public function testLoadNoAutoload()
  116. {
  117. $this->Task->params = [
  118. 'bootstrap' => false,
  119. 'routes' => true,
  120. 'autoload' => false,
  121. ];
  122. $action = $this->Task->main('TestPlugin');
  123. $this->assertTrue($action);
  124. $expected = "Plugin::load('TestPlugin', ['routes' => true]);";
  125. $bootstrap = new File($this->bootstrap, false);
  126. $this->assertContains($expected, $bootstrap->read());
  127. }
  128. /**
  129. * testLoad
  130. *
  131. * @return void
  132. */
  133. public function testLoadNothing()
  134. {
  135. $this->Task->params = [
  136. 'bootstrap' => false,
  137. 'routes' => false,
  138. 'autoload' => false,
  139. ];
  140. $action = $this->Task->main('TestPlugin');
  141. $this->assertTrue($action);
  142. $expected = "Plugin::load('TestPlugin');";
  143. $bootstrap = new File($this->bootstrap, false);
  144. $this->assertContains($expected, $bootstrap->read());
  145. }
  146. }