UnloadTaskTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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\TestSuite\TestCase;
  17. use Cake\Filesystem\File;
  18. /**
  19. * UnloadTaskTest class
  20. *
  21. */
  22. class UnloadTaskTest 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\UnloadTask', ['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. * testUnload
  55. *
  56. * @return void
  57. */
  58. public function testUnload()
  59. {
  60. $bootstrap = new File($this->bootstrap, false);
  61. $this->_addPluginToBootstrap("TestPlugin");
  62. $expected = "Plugin::load('TestPlugin', ['autoload' => true, 'bootstrap' => false, 'routes' => false]);";
  63. $this->assertContains($expected, $bootstrap->read());
  64. $action = $this->Task->main('TestPlugin');
  65. $this->assertTrue($action);
  66. $expected = "Plugin::load('TestPlugin', ['autoload' => true, 'bootstrap' => false, 'routes' => false]);";
  67. $this->assertNotContains($expected, $bootstrap->read());
  68. }
  69. /**
  70. * testUnloadNoName
  71. *
  72. * @return void
  73. */
  74. public function testUnloadNoName()
  75. {
  76. $bootstrap = new File($this->bootstrap, false);
  77. $action = $this->Task->main();
  78. $this->assertFalse($action);
  79. }
  80. /**
  81. * _addPluginToBootstrap
  82. *
  83. * Quick method to add a plugin to the bootstrap file.
  84. * This is useful for the tests
  85. *
  86. * @param string $name
  87. */
  88. protected function _addPluginToBootstrap($name)
  89. {
  90. $bootstrap = new File($this->bootstrap, false);
  91. $bootstrap->append("Plugin::load('" . $name . "', ['autoload' => true, 'bootstrap' => false, 'routes' => false]);\n");
  92. }
  93. }