UnloadTaskTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. * 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('Cake\Shell\Task\UnloadTask', ['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. * testUnload
  53. *
  54. * @return void
  55. */
  56. public function testUnload()
  57. {
  58. $bootstrap = new File($this->bootstrap, false);
  59. $this->_addPluginToBootstrap("TestPlugin");
  60. $this->_addPluginToBootstrap("TestPluginSecond");
  61. $expected = "Plugin::load('TestPlugin', ['autoload' => true, 'bootstrap' => false, 'routes' => false]);";
  62. $this->assertContains($expected, $bootstrap->read());
  63. $action = $this->Task->main('TestPlugin');
  64. $this->assertTrue($action);
  65. $expected = "Plugin::load('TestPlugin', ['autoload' => true, 'bootstrap' => false, 'routes' => false]);";
  66. $this->assertNotContains($expected, $bootstrap->read());
  67. $expected = "Plugin::load('TestPluginSecond', ['autoload' => true, 'bootstrap' => false, 'routes' => false]);";
  68. $this->assertContains($expected, $bootstrap->read());
  69. }
  70. /**
  71. * _addPluginToBootstrap
  72. *
  73. * Quick method to add a plugin to the bootstrap file.
  74. * This is useful for the tests
  75. *
  76. * @param string $name
  77. */
  78. protected function _addPluginToBootstrap($name)
  79. {
  80. $bootstrap = new File($this->bootstrap, false);
  81. $bootstrap->append("\nPlugin::load('$name', ['autoload' => true, 'bootstrap' => false, 'routes' => false]);");
  82. }
  83. }