LoadTaskTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. ];
  62. $action = $this->Task->main('TestPlugin');
  63. $this->assertTrue($action);
  64. $expected = "Plugin::load('TestPlugin', ['autoload' => true, 'bootstrap' => false, 'routes' => false]);";
  65. $bootstrap = new File($this->bootstrap, false);
  66. $this->assertContains($expected, $bootstrap->read());
  67. }
  68. /**
  69. * testLoadWithBootstrap
  70. *
  71. * @return void
  72. */
  73. public function testLoadWithBootstrap()
  74. {
  75. $this->Task->params = [
  76. 'bootstrap' => true,
  77. 'routes' => false,
  78. ];
  79. $action = $this->Task->main('TestPlugin');
  80. $this->assertTrue($action);
  81. $expected = "Plugin::load('TestPlugin', ['autoload' => true, 'bootstrap' => true, 'routes' => false]);";
  82. $bootstrap = new File($this->bootstrap, false);
  83. $this->assertContains($expected, $bootstrap->read());
  84. }
  85. /**
  86. * testLoadWithRoutes
  87. *
  88. * @return void
  89. */
  90. public function testLoadWithRoutes()
  91. {
  92. $this->Task->params = [
  93. 'bootstrap' => false,
  94. 'routes' => true,
  95. ];
  96. $action = $this->Task->main('TestPlugin');
  97. $this->assertTrue($action);
  98. $expected = "Plugin::load('TestPlugin', ['autoload' => true, 'bootstrap' => false, 'routes' => true]);";
  99. $bootstrap = new File($this->bootstrap, false);
  100. $this->assertContains($expected, $bootstrap->read());
  101. }
  102. }