LoadTaskTest.php 4.3 KB

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