LoadTaskTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. * @since 1.2.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\Shell\Task;
  16. use Cake\Core\Plugin;
  17. use Cake\TestSuite\TestCase;
  18. use Cake\Filesystem\File;
  19. /**
  20. * LoadTaskTest class
  21. *
  22. */
  23. class LoadTaskTest extends TestCase
  24. {
  25. /**
  26. * setUp method
  27. *
  28. * @return void
  29. */
  30. public function setUp()
  31. {
  32. parent::setUp();
  33. $this->io = $this->getMock('Cake\Console\ConsoleIo', [], [], '', false);
  34. $this->Task = $this->getMock(
  35. 'Cake\Shell\Task\LoadTask', ['in', 'out', 'err', '_stop'], [$this->io]
  36. );
  37. $this->bootstrap = ROOT . DS . 'config' . DS . 'bootstrap.php';
  38. $bootstrap = new File($this->bootstrap, false);
  39. $this->original_bootstrap_content = $bootstrap->read();
  40. }
  41. /**
  42. * tearDown method
  43. *
  44. * @return void
  45. */
  46. public function tearDown()
  47. {
  48. parent::tearDown();
  49. unset($this->shell);
  50. Plugin::unload();
  51. $bootstrap = new File($this->bootstrap, false);
  52. $bootstrap->write($this->original_bootstrap_content);
  53. }
  54. /**
  55. * testLoad
  56. *
  57. * @return void
  58. */
  59. public function testLoad()
  60. {
  61. $this->Task->params = [
  62. 'bootstrap' => false,
  63. 'routes' => false,
  64. ];
  65. $action = $this->Task->main('TestPlugin');
  66. $this->assertTrue($action);
  67. $expected = "Plugin::load('TestPlugin', ['autoload' => true, 'bootstrap' => false, 'routes' => false]);";
  68. $bootstrap = new File($this->bootstrap, false);
  69. $this->assertContains($expected, $bootstrap->read());
  70. }
  71. /**
  72. * testLoadWithBootstrap
  73. *
  74. * @return void
  75. */
  76. public function testLoadWithBootstrap()
  77. {
  78. $this->Task->params = [
  79. 'bootstrap' => true,
  80. 'routes' => false,
  81. ];
  82. $action = $this->Task->main('TestPlugin');
  83. $this->assertTrue($action);
  84. $expected = "Plugin::load('TestPlugin', ['autoload' => true, 'bootstrap' => true, 'routes' => false]);";
  85. $bootstrap = new File($this->bootstrap, false);
  86. $this->assertContains($expected, $bootstrap->read());
  87. }
  88. /**
  89. * testLoadWithRoutes
  90. *
  91. * @return void
  92. */
  93. public function testLoadWithRoutes()
  94. {
  95. $this->Task->params = [
  96. 'bootstrap' => false,
  97. 'routes' => true,
  98. ];
  99. $action = $this->Task->main('TestPlugin');
  100. $this->assertTrue($action);
  101. $expected = "Plugin::load('TestPlugin', ['autoload' => true, 'bootstrap' => false, 'routes' => true]);";
  102. $bootstrap = new File($this->bootstrap, false);
  103. $this->assertContains($expected, $bootstrap->read());
  104. }
  105. /**
  106. * testLoadNoName
  107. *
  108. * @return void
  109. */
  110. public function testLoadNoName()
  111. {
  112. $this->Task->params = [
  113. 'bootstrap' => false,
  114. 'routes' => true,
  115. ];
  116. $action = $this->Task->main();
  117. $this->assertFalse($action);
  118. $expected = "Plugin::load(";
  119. $bootstrap = new File($this->bootstrap, false);
  120. $this->assertNotContains($expected, $bootstrap->read());
  121. }
  122. }