From 05073d09cb0126f6859a2d10325c2744ed90d489 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 6 Mar 2014 00:31:27 +0100 Subject: [PATCH 1/5] Add Deactivate Module Command Line --- .../Command/ModuleDeactivateCommand.php | 84 +++++++++++++ .../Command/ModuleDeactivateCommandTest.php | 113 ++++++++++++++++++ 2 files changed, 197 insertions(+) create mode 100755 core/lib/Thelia/Command/ModuleDeactivateCommand.php create mode 100755 core/lib/Thelia/Tests/Command/ModuleDeactivateCommandTest.php diff --git a/core/lib/Thelia/Command/ModuleDeactivateCommand.php b/core/lib/Thelia/Command/ModuleDeactivateCommand.php new file mode 100755 index 000000000..18d38778c --- /dev/null +++ b/core/lib/Thelia/Command/ModuleDeactivateCommand.php @@ -0,0 +1,84 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Command; + +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +use Thelia\Model\ModuleQuery; + +/** + * DeActivates a module + * + * Class ModuleDeactivateCommand + * @package Thelia\Command + * @author Nicolas Villa + * + */ +class ModuleDeactivateCommand extends BaseModuleGenerate +{ + protected function configure() + { + $this + ->setName("module:deactivate") + ->setDescription("Deactivate a module") + ->addArgument( + "module" , + InputArgument::REQUIRED, + "module to deactivate" + ) + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $moduleCode = $this->formatModuleName($input->getArgument("module")); + + $module = ModuleQuery::create()->findOneByCode($moduleCode); + + if (null === $module) { + throw new \RuntimeException(sprintf("module %s not found", $moduleCode)); + } + + try { + $moduleReflection = new \ReflectionClass($module->getFullNamespace()); + + $moduleInstance = $moduleReflection->newInstance(); + + $moduleInstance->deActivate(); + } catch (\Exception $e) { + throw new \RuntimeException(sprintf("Deactivation fail with Exception : [%d] %s", $e->getCode(), $e->getMessage())); + } + + //impossible to change output class in CommandTester... + if (method_exists($output, "renderBlock")) { + $output->renderBlock(array( + '', + sprintf("Deactivation succeed for module %s", $moduleCode), + '' + ), "bg=green;fg=black"); + } + } +} diff --git a/core/lib/Thelia/Tests/Command/ModuleDeactivateCommandTest.php b/core/lib/Thelia/Tests/Command/ModuleDeactivateCommandTest.php new file mode 100755 index 000000000..309a29ff8 --- /dev/null +++ b/core/lib/Thelia/Tests/Command/ModuleDeactivateCommandTest.php @@ -0,0 +1,113 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Tests\Command; + +use Symfony\Component\Console\Tester\CommandTester; +use Thelia\Command\ModuleDeactivateCommand; +use Thelia\Core\Application; +use Thelia\Model\ModuleQuery; +use Thelia\Module\BaseModule; + +/** + * Class ModuleDeactivateCommandTest + * + * @package Thelia\Tests\Command + * @author Nicolas Villa + */ +class ModuleDeactivateCommandTest extends \PHPUnit_Framework_TestCase +{ + public function testModuleDeactivateCommand() + { + $module = ModuleQuery::create()->findOne(); + + if (null !== $module) { + + $prev_activation_status = $module->getDeactivate(); + + $application = new Application($this->getKernel()); + + $module->setDeactivate(BaseModule::IS_NOT_ACTIVATED); + $module->save(); + + $moduleDeactivate = new ModuleDeactivateCommand(); + $moduleDeactivate->setContainer($this->getContainer()); + + $application->add($moduleDeactivate); + + $command = $application->find("module:deactivate"); + $commandTester = new CommandTester($command); + $commandTester->execute(array( + "command" => $command->getName(), + "module" => $module->getCode(), + )); + + $deactivated = ModuleQuery::create()->findPk($module->getId())->getDeactivate(); + + // Restore activation status + $module->setDeactivate($prev_activation_status)->save(); + + $this->assertEquals(BaseModule::IS_ACTIVATED, $deactivated); + } + } + + /** + * @expectedException \RuntimeException + * @expectedExceptionMessage module Letshopethismoduledoesnotexists not found + */ + public function testModuleDeactivateCommandUnknownModule() + { + $testedModule = ModuleQuery::create()->findOneByCode('Letshopethismoduledoesnotexists'); + + if (null == $testedModule) { + $application = new Application($this->getKernel()); + + $moduleDeactivate = new ModuleDeactivateCommand(); + $moduleDeactivate->setContainer($this->getContainer()); + + $application->add($moduleDeactivate); + + $command = $application->find("module:deactivate"); + $commandTester = new CommandTester($command); + $commandTester->execute(array( + "command" => $command->getName(), + "module" => "letshopethismoduledoesnotexists", + )); + + $out = true; + } + } + + public function getKernel() + { + $kernel = $this->getMock("Symfony\Component\HttpKernel\KernelInterface"); + + return $kernel; + } + + public function getContainer() + { + $container = new \Symfony\Component\DependencyInjection\ContainerBuilder(); + + return $container; + } +} From 36a49f812d224b6bbc1406dc560ed513a9171118 Mon Sep 17 00:00:00 2001 From: Boyquotes Date: Thu, 6 Mar 2014 00:34:12 +0100 Subject: [PATCH 2/5] Add Deactivate Module Command Line --- .../Command/ModuleDeactivateCommand.php | 84 +++++++++++++ .../Command/ModuleDeactivateCommandTest.php | 113 ++++++++++++++++++ 2 files changed, 197 insertions(+) create mode 100755 core/lib/Thelia/Command/ModuleDeactivateCommand.php create mode 100755 core/lib/Thelia/Tests/Command/ModuleDeactivateCommandTest.php diff --git a/core/lib/Thelia/Command/ModuleDeactivateCommand.php b/core/lib/Thelia/Command/ModuleDeactivateCommand.php new file mode 100755 index 000000000..18d38778c --- /dev/null +++ b/core/lib/Thelia/Command/ModuleDeactivateCommand.php @@ -0,0 +1,84 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Command; + +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +use Thelia\Model\ModuleQuery; + +/** + * DeActivates a module + * + * Class ModuleDeactivateCommand + * @package Thelia\Command + * @author Nicolas Villa + * + */ +class ModuleDeactivateCommand extends BaseModuleGenerate +{ + protected function configure() + { + $this + ->setName("module:deactivate") + ->setDescription("Deactivate a module") + ->addArgument( + "module" , + InputArgument::REQUIRED, + "module to deactivate" + ) + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $moduleCode = $this->formatModuleName($input->getArgument("module")); + + $module = ModuleQuery::create()->findOneByCode($moduleCode); + + if (null === $module) { + throw new \RuntimeException(sprintf("module %s not found", $moduleCode)); + } + + try { + $moduleReflection = new \ReflectionClass($module->getFullNamespace()); + + $moduleInstance = $moduleReflection->newInstance(); + + $moduleInstance->deActivate(); + } catch (\Exception $e) { + throw new \RuntimeException(sprintf("Deactivation fail with Exception : [%d] %s", $e->getCode(), $e->getMessage())); + } + + //impossible to change output class in CommandTester... + if (method_exists($output, "renderBlock")) { + $output->renderBlock(array( + '', + sprintf("Deactivation succeed for module %s", $moduleCode), + '' + ), "bg=green;fg=black"); + } + } +} diff --git a/core/lib/Thelia/Tests/Command/ModuleDeactivateCommandTest.php b/core/lib/Thelia/Tests/Command/ModuleDeactivateCommandTest.php new file mode 100755 index 000000000..309a29ff8 --- /dev/null +++ b/core/lib/Thelia/Tests/Command/ModuleDeactivateCommandTest.php @@ -0,0 +1,113 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Tests\Command; + +use Symfony\Component\Console\Tester\CommandTester; +use Thelia\Command\ModuleDeactivateCommand; +use Thelia\Core\Application; +use Thelia\Model\ModuleQuery; +use Thelia\Module\BaseModule; + +/** + * Class ModuleDeactivateCommandTest + * + * @package Thelia\Tests\Command + * @author Nicolas Villa + */ +class ModuleDeactivateCommandTest extends \PHPUnit_Framework_TestCase +{ + public function testModuleDeactivateCommand() + { + $module = ModuleQuery::create()->findOne(); + + if (null !== $module) { + + $prev_activation_status = $module->getDeactivate(); + + $application = new Application($this->getKernel()); + + $module->setDeactivate(BaseModule::IS_NOT_ACTIVATED); + $module->save(); + + $moduleDeactivate = new ModuleDeactivateCommand(); + $moduleDeactivate->setContainer($this->getContainer()); + + $application->add($moduleDeactivate); + + $command = $application->find("module:deactivate"); + $commandTester = new CommandTester($command); + $commandTester->execute(array( + "command" => $command->getName(), + "module" => $module->getCode(), + )); + + $deactivated = ModuleQuery::create()->findPk($module->getId())->getDeactivate(); + + // Restore activation status + $module->setDeactivate($prev_activation_status)->save(); + + $this->assertEquals(BaseModule::IS_ACTIVATED, $deactivated); + } + } + + /** + * @expectedException \RuntimeException + * @expectedExceptionMessage module Letshopethismoduledoesnotexists not found + */ + public function testModuleDeactivateCommandUnknownModule() + { + $testedModule = ModuleQuery::create()->findOneByCode('Letshopethismoduledoesnotexists'); + + if (null == $testedModule) { + $application = new Application($this->getKernel()); + + $moduleDeactivate = new ModuleDeactivateCommand(); + $moduleDeactivate->setContainer($this->getContainer()); + + $application->add($moduleDeactivate); + + $command = $application->find("module:deactivate"); + $commandTester = new CommandTester($command); + $commandTester->execute(array( + "command" => $command->getName(), + "module" => "letshopethismoduledoesnotexists", + )); + + $out = true; + } + } + + public function getKernel() + { + $kernel = $this->getMock("Symfony\Component\HttpKernel\KernelInterface"); + + return $kernel; + } + + public function getContainer() + { + $container = new \Symfony\Component\DependencyInjection\ContainerBuilder(); + + return $container; + } +} From 34937fe3ecc002d4a1a4c4c4fcf00717e94c1597 Mon Sep 17 00:00:00 2001 From: Boyquotes Date: Fri, 21 Mar 2014 09:28:31 +0100 Subject: [PATCH 3/5] reference deactivate command line --- core/lib/Thelia/Config/Resources/command.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/core/lib/Thelia/Config/Resources/command.xml b/core/lib/Thelia/Config/Resources/command.xml index e9b90d8b9..283fe2321 100644 --- a/core/lib/Thelia/Config/Resources/command.xml +++ b/core/lib/Thelia/Config/Resources/command.xml @@ -12,6 +12,7 @@ + From adf56fd142eaae8b1f7baba00f0646e80b77e0b5 Mon Sep 17 00:00:00 2001 From: Boyquotes Date: Sat, 22 Mar 2014 10:17:00 +0100 Subject: [PATCH 4/5] Typo in class/file name --- core/lib/Thelia/Command/ModuleDeactivateCommand.php | 2 +- core/lib/Thelia/Config/Resources/command.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/lib/Thelia/Command/ModuleDeactivateCommand.php b/core/lib/Thelia/Command/ModuleDeactivateCommand.php index 18d38778c..cebc75681 100755 --- a/core/lib/Thelia/Command/ModuleDeactivateCommand.php +++ b/core/lib/Thelia/Command/ModuleDeactivateCommand.php @@ -30,7 +30,7 @@ use Symfony\Component\Console\Output\OutputInterface; use Thelia\Model\ModuleQuery; /** - * DeActivates a module + * Deactivates a module * * Class ModuleDeactivateCommand * @package Thelia\Command diff --git a/core/lib/Thelia/Config/Resources/command.xml b/core/lib/Thelia/Config/Resources/command.xml index 283fe2321..8b61f40e7 100644 --- a/core/lib/Thelia/Config/Resources/command.xml +++ b/core/lib/Thelia/Config/Resources/command.xml @@ -12,7 +12,7 @@ - + From ee2e2356dc86688f804f1f9a68cff8e4658f8338 Mon Sep 17 00:00:00 2001 From: Boyquotes Date: Mon, 24 Mar 2014 10:14:23 +0100 Subject: [PATCH 5/5] Fix the travis error: Error when Test the Deactivation --- .../Tests/Command/ModuleDeactivateCommandTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/lib/Thelia/Tests/Command/ModuleDeactivateCommandTest.php b/core/lib/Thelia/Tests/Command/ModuleDeactivateCommandTest.php index 309a29ff8..e227a9e5c 100755 --- a/core/lib/Thelia/Tests/Command/ModuleDeactivateCommandTest.php +++ b/core/lib/Thelia/Tests/Command/ModuleDeactivateCommandTest.php @@ -42,11 +42,11 @@ class ModuleDeactivateCommandTest extends \PHPUnit_Framework_TestCase if (null !== $module) { - $prev_activation_status = $module->getDeactivate(); + $prev_activation_status = $module->getActivate(); $application = new Application($this->getKernel()); - $module->setDeactivate(BaseModule::IS_NOT_ACTIVATED); + $module->setActivate(BaseModule::IS_ACTIVATED); $module->save(); $moduleDeactivate = new ModuleDeactivateCommand(); @@ -61,12 +61,12 @@ class ModuleDeactivateCommandTest extends \PHPUnit_Framework_TestCase "module" => $module->getCode(), )); - $deactivated = ModuleQuery::create()->findPk($module->getId())->getDeactivate(); + $deactivated = ModuleQuery::create()->findPk($module->getId())->getActivate(); // Restore activation status - $module->setDeactivate($prev_activation_status)->save(); + $module->setActivate($prev_activation_status)->save(); - $this->assertEquals(BaseModule::IS_ACTIVATED, $deactivated); + $this->assertEquals(BaseModule::IS_NOT_ACTIVATED, $deactivated); } }