UnloadTaskTest.php 2.9 KB

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