Fix #1663 : Remove plugin configuration on uninstall

This commit is contained in:
Romain Neutron
2014-02-03 14:00:33 +01:00
parent 142c221be2
commit 0085b15304
2 changed files with 74 additions and 4 deletions

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\Command\Plugin; namespace Alchemy\Phrasea\Command\Plugin;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
@@ -23,7 +24,8 @@ class RemovePlugin extends AbstractPluginCommand
$this $this
->setDescription('Removes a plugin given its name') ->setDescription('Removes a plugin given its name')
->addArgument('name', InputArgument::REQUIRED, 'The name of the plugin'); ->addArgument('name', InputArgument::REQUIRED, 'The name of the plugin')
->addOption('keep-config', 'k', InputOption::VALUE_NONE, 'Use this flag to keep configuration');
} }
protected function doExecute(InputInterface $input, OutputInterface $output) protected function doExecute(InputInterface $input, OutputInterface $output)
@@ -42,6 +44,12 @@ class RemovePlugin extends AbstractPluginCommand
$this->updateConfigFiles($input, $output); $this->updateConfigFiles($input, $output);
if (!$input->getOption('keep-config')) {
$conf = $this->container['phraseanet.configuration']->getConfig();
unset($conf['plugins'][$name]);
$this->container['phraseanet.configuration']->setConfig($conf);
}
return 0; return 0;
} }
} }

View File

@@ -12,9 +12,16 @@ class RemovePluginTest extends PluginCommandTestCase
$input = $this->getMock('Symfony\Component\Console\Input\InputInterface'); $input = $this->getMock('Symfony\Component\Console\Input\InputInterface');
$input->expects($this->once()) $input->expects($this->once())
->method('getArgument') ->method('getArgument')
->with($this->equalTo('name')) ->with($this->equalTo('name'))
->will($this->returnValue($name)); ->will($this->returnValue($name));
$input->expects($this->any())
->method('getOption')
->will($this->returnCallback(function ($option) {
if ($option === 'keep-config') {
return false;
}
}));
$output = $this->getMock('Symfony\Component\Console\Output\OutputInterface'); $output = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
@@ -33,5 +40,60 @@ class RemovePluginTest extends PluginCommandTestCase
$result = $command->execute($input, $output); $result = $command->execute($input, $output);
$this->assertSame(0, $result); $this->assertSame(0, $result);
$conf = self::$DI['cli']['phraseanet.configuration']->getConfig();
$this->assertArrayNotHasKey('test-plugin', $conf['plugins']);
}
public function testExecuteWithoutRemoveConfig()
{
$name = 'test-plugin';
$input = $this->getMock('Symfony\Component\Console\Input\InputInterface');
$input->expects($this->once())
->method('getArgument')
->with($this->equalTo('name'))
->will($this->returnValue($name));
$input->expects($this->any())
->method('getOption')
->will($this->returnCallback(function ($option) {
if ($option === 'keep-config') {
return true;
}
}));
$output = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
$command = new RemovePlugin();
$command->setContainer(self::$DI['cli']);
$data = $this->addPluginData();
self::$DI['cli']['filesystem'] = $this->createFilesystemMock();
self::$DI['cli']['filesystem']->expects($this->at(0))
->method('remove')
->with(self::$DI['cli']['root.path'].'/www/plugins/'.$name);
self::$DI['cli']['filesystem']->expects($this->at(1))
->method('remove')
->with(self::$DI['cli']['plugins.directory'].'/'.$name);
$result = $command->execute($input, $output);
$this->assertSame(0, $result);
$conf = self::$DI['cli']['phraseanet.configuration']->getConfig();
$this->assertSame($data, $conf['plugins']['test-plugin']);
}
private function addPluginData()
{
$data = array('key' => 'value');
$conf = self::$DI['cli']['phraseanet.configuration']->getConfig();
$conf['plugins']['test-plugin'] = $data;
self::$DI['cli']['phraseanet.configuration']->setConfig($conf);
return $data;
} }
} }