LoadTaskTest.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. * @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. $bootstrap = new File($this->bootstrap, false);
  44. $this->originalBootstrapContent = $bootstrap->read();
  45. }
  46. /**
  47. * tearDown method
  48. *
  49. * @return void
  50. */
  51. public function tearDown()
  52. {
  53. parent::tearDown();
  54. unset($this->shell);
  55. Plugin::unload();
  56. $bootstrap = new File($this->bootstrap, false);
  57. $bootstrap->write($this->originalBootstrapContent);
  58. }
  59. /**
  60. * testLoad
  61. *
  62. * @return void
  63. */
  64. public function testLoad()
  65. {
  66. $this->Task->params = [
  67. 'bootstrap' => false,
  68. 'routes' => false,
  69. 'autoload' => true,
  70. 'cli' => false
  71. ];
  72. $action = $this->Task->main('TestPlugin');
  73. $this->assertTrue($action);
  74. $expected = "Plugin::load('TestPlugin', ['autoload' => true]);";
  75. $bootstrap = new File($this->bootstrap, false);
  76. $this->assertContains($expected, $bootstrap->read());
  77. }
  78. /**
  79. * testLoadWithBootstrap
  80. *
  81. * @return void
  82. */
  83. public function testLoadWithBootstrap()
  84. {
  85. $this->Task->params = [
  86. 'bootstrap' => true,
  87. 'routes' => false,
  88. 'autoload' => true,
  89. 'cli' => false
  90. ];
  91. $action = $this->Task->main('TestPlugin');
  92. $this->assertTrue($action);
  93. $expected = "Plugin::load('TestPlugin', ['autoload' => true, 'bootstrap' => true]);";
  94. $bootstrap = new File($this->bootstrap, false);
  95. $this->assertContains($expected, $bootstrap->read());
  96. }
  97. /**
  98. * testLoadWithRoutes
  99. *
  100. * @return void
  101. */
  102. public function testLoadWithRoutes()
  103. {
  104. $this->Task->params = [
  105. 'bootstrap' => false,
  106. 'routes' => true,
  107. 'autoload' => true,
  108. 'cli' => false
  109. ];
  110. $action = $this->Task->main('TestPlugin');
  111. $this->assertTrue($action);
  112. $expected = "Plugin::load('TestPlugin', ['autoload' => true, 'routes' => true]);";
  113. $bootstrap = new File($this->bootstrap, false);
  114. $this->assertContains($expected, $bootstrap->read());
  115. }
  116. /**
  117. * test load no autoload
  118. *
  119. * @return void
  120. */
  121. public function testLoadNoAutoload()
  122. {
  123. $this->Task->params = [
  124. 'bootstrap' => false,
  125. 'routes' => true,
  126. 'autoload' => false,
  127. 'cli' => false
  128. ];
  129. $action = $this->Task->main('TestPlugin');
  130. $this->assertTrue($action);
  131. $expected = "Plugin::load('TestPlugin', ['routes' => true]);";
  132. $bootstrap = new File($this->bootstrap, false);
  133. $this->assertContains($expected, $bootstrap->read());
  134. }
  135. /**
  136. * testLoad
  137. *
  138. * @return void
  139. */
  140. public function testLoadNothing()
  141. {
  142. $this->Task->params = [
  143. 'bootstrap' => false,
  144. 'routes' => false,
  145. 'autoload' => false,
  146. 'cli' => false
  147. ];
  148. $action = $this->Task->main('TestPlugin');
  149. $this->assertTrue($action);
  150. $expected = "Plugin::load('TestPlugin');";
  151. $bootstrap = new File($this->bootstrap, false);
  152. $this->assertContains($expected, $bootstrap->read());
  153. }
  154. }