LoadTaskTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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(
  34. 'Cake\Shell\Task\LoadTask', ['in', 'out', 'err', '_stop'], [$this->io]
  35. );
  36. $this->bootstrap = ROOT . DS . 'config' . DS . 'bootstrap.php';
  37. $bootstrap = new File($this->bootstrap, false);
  38. $this->original_bootstrap_content = $bootstrap->read();
  39. }
  40. /**
  41. * tearDown method
  42. *
  43. * @return void
  44. */
  45. public function tearDown()
  46. {
  47. parent::tearDown();
  48. unset($this->shell);
  49. Plugin::unload();
  50. $bootstrap = new File($this->bootstrap, false);
  51. $bootstrap->write($this->original_bootstrap_content);
  52. }
  53. /**
  54. * testLoad
  55. *
  56. * @return void
  57. */
  58. public function testLoad()
  59. {
  60. $this->Task->params = [
  61. 'bootstrap' => false,
  62. 'routes' => false,
  63. ];
  64. $action = $this->Task->main('TestPlugin');
  65. $this->assertTrue($action);
  66. $expected = "Plugin::load('TestPlugin', ['autoload' => true, 'bootstrap' => false, 'routes' => false]);";
  67. $bootstrap = new File($this->bootstrap, false);
  68. $this->assertContains($expected, $bootstrap->read());
  69. }
  70. /**
  71. * testLoadWithBootstrap
  72. *
  73. * @return void
  74. */
  75. public function testLoadWithBootstrap()
  76. {
  77. $this->Task->params = [
  78. 'bootstrap' => true,
  79. 'routes' => false,
  80. ];
  81. $action = $this->Task->main('TestPlugin');
  82. $this->assertTrue($action);
  83. $expected = "Plugin::load('TestPlugin', ['autoload' => true, 'bootstrap' => true, 'routes' => false]);";
  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. ];
  98. $action = $this->Task->main('TestPlugin');
  99. $this->assertTrue($action);
  100. $expected = "Plugin::load('TestPlugin', ['autoload' => true, 'bootstrap' => false, 'routes' => true]);";
  101. $bootstrap = new File($this->bootstrap, false);
  102. $this->assertContains($expected, $bootstrap->read());
  103. }
  104. /**
  105. * testLoadNoName
  106. *
  107. * @return void
  108. */
  109. public function testLoadNoName()
  110. {
  111. $this->Task->params = [
  112. 'bootstrap' => false,
  113. 'routes' => true,
  114. ];
  115. $action = $this->Task->main();
  116. $this->assertFalse($action);
  117. $expected = "Plugin::load(";
  118. $bootstrap = new File($this->bootstrap, false);
  119. $this->assertNotContains($expected, $bootstrap->read());
  120. }
  121. }