Skip to content

Commit

Permalink
Fixed Unload Task for Plugin Shell. Plugins with breaked lines can no…
Browse files Browse the repository at this point in the history
…w be unloaded.
  • Loading branch information
bobmulder committed Mar 11, 2015
1 parent 9b7cf6d commit 6534182
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Shell/Task/UnloadTask.php
Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion tests/TestCase/Shell/Task/UnloadTaskTest.php
Expand Up @@ -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());

Expand All @@ -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());
}

/**
Expand All @@ -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]);");
}
}

0 comments on commit 6534182

Please sign in to comment.