From 6534182f725a53752003fd096ca238e03827de65 Mon Sep 17 00:00:00 2001 From: Bob Date: Wed, 11 Mar 2015 15:57:46 +0100 Subject: [PATCH] Fixed Unload Task for Plugin Shell. Plugins with breaked lines can now be unloaded. --- src/Shell/Task/UnloadTask.php | 4 ++-- tests/TestCase/Shell/Task/UnloadTaskTest.php | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Shell/Task/UnloadTask.php b/src/Shell/Task/UnloadTask.php index e1f86a93122..1803b0d5462 100644 --- a/src/Shell/Task/UnloadTask.php +++ b/src/Shell/Task/UnloadTask.php @@ -64,13 +64,13 @@ public function main($plugin = null) */ protected function _modifyBootstrap($plugin) { - $bool = "(false|true)"; - $finder = "/Plugin::load\('$plugin', \['autoload' => $bool, 'bootstrap' => $bool, 'routes' => $bool]\);\n/"; + $finder = "/\nPlugin::load\('$plugin'(.|.\n|)+\);\n/"; $bootstrap = new File($this->bootstrap, false); $contents = $bootstrap->read(); if (!preg_match("@\n\s*Plugin::loadAll@", $contents)) { + $contents = preg_replace($finder, "", $contents); $bootstrap->write($contents); diff --git a/tests/TestCase/Shell/Task/UnloadTaskTest.php b/tests/TestCase/Shell/Task/UnloadTaskTest.php index 4e913a5b3a9..1f14f13bcab 100644 --- a/tests/TestCase/Shell/Task/UnloadTaskTest.php +++ b/tests/TestCase/Shell/Task/UnloadTaskTest.php @@ -73,6 +73,8 @@ public function testUnload() $this->_addPluginToBootstrap("TestPlugin"); + $this->_addPluginToBootstrap("TestPluginSecond"); + $expected = "Plugin::load('TestPlugin', ['autoload' => true, 'bootstrap' => false, 'routes' => false]);"; $this->assertContains($expected, $bootstrap->read()); @@ -81,6 +83,8 @@ public function testUnload() $this->assertTrue($action); $expected = "Plugin::load('TestPlugin', ['autoload' => true, 'bootstrap' => false, 'routes' => false]);"; $this->assertNotContains($expected, $bootstrap->read()); + $expected = "Plugin::load('TestPluginSecond', ['autoload' => true, 'bootstrap' => false, 'routes' => false]);"; + $this->assertContains($expected, $bootstrap->read()); } /** @@ -94,6 +98,6 @@ public function testUnload() protected function _addPluginToBootstrap($name) { $bootstrap = new File($this->bootstrap, false); - $bootstrap->append("Plugin::load('" . $name . "', ['autoload' => true, 'bootstrap' => false, 'routes' => false]);\n"); + $bootstrap->append("\nPlugin::load('" . $name . "', ['autoload' => true, 'bootstrap' => false, 'routes' => false]);"); } }