LoadTaskTest.php 4.2 KB

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