Initial Commit
This commit is contained in:
35
tests/phpunit/Thelia/Tests/Command/BaseCommandTest.php
Normal file
35
tests/phpunit/Thelia/Tests/Command/BaseCommandTest.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Command;
|
||||
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
|
||||
/**
|
||||
* base class for testing command line command
|
||||
*
|
||||
* Class BaseCommandTest
|
||||
* @package Thelia\Tests\Command
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
abstract class BaseCommandTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @return KernelInterface
|
||||
*/
|
||||
public function getKernel()
|
||||
{
|
||||
$kernel = $this->getMock("Symfony\Component\HttpKernel\KernelInterface");
|
||||
|
||||
return $kernel;
|
||||
}
|
||||
}
|
||||
110
tests/phpunit/Thelia/Tests/Command/CacheClearTest.php
Normal file
110
tests/phpunit/Thelia/Tests/Command/CacheClearTest.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Command;
|
||||
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Thelia\Action\Cache;
|
||||
use Thelia\Core\Application;
|
||||
use Thelia\Command\CacheClear;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Thelia\Tests\ContainerAwareTestCase;
|
||||
|
||||
/**
|
||||
* test the cache:clear command
|
||||
*
|
||||
* Class CacheClearTest
|
||||
* @package Thelia\Tests\Command
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class CacheClearTest extends ContainerAwareTestCase
|
||||
{
|
||||
public $cache_dir;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->cache_dir = THELIA_CACHE_DIR . 'test_cache';
|
||||
|
||||
$fs = new Filesystem();
|
||||
|
||||
$fs->mkdir($this->cache_dir);
|
||||
$fs->mkdir(THELIA_WEB_DIR . "/assets");
|
||||
}
|
||||
|
||||
public function testCacheClear()
|
||||
{
|
||||
// Fails on windows - do not execute this test on windows
|
||||
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
|
||||
$application = new Application($this->getKernel());
|
||||
|
||||
$cacheClear = new CacheClear();
|
||||
$cacheClear->setContainer($this->getContainer());
|
||||
|
||||
$application->add($cacheClear);
|
||||
|
||||
$command = $application->find("cache:clear");
|
||||
$commandTester = new CommandTester($command);
|
||||
$commandTester->execute(array(
|
||||
"command" => $command->getName(),
|
||||
"--env" => "test"
|
||||
));
|
||||
|
||||
$fs = new Filesystem();
|
||||
|
||||
$this->assertFalse($fs->exists($this->cache_dir));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testCacheClearWithoutWritePermission()
|
||||
{
|
||||
// Fails on windows - mock this test on windows
|
||||
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
|
||||
$fs = new Filesystem();
|
||||
$fs->chmod($this->cache_dir, 0100);
|
||||
|
||||
$application = new Application($this->getKernel());
|
||||
|
||||
$cacheClear = new CacheClear();
|
||||
$cacheClear->setContainer($this->getContainer());
|
||||
|
||||
$application->add($cacheClear);
|
||||
|
||||
$command = $application->find("cache:clear");
|
||||
$commandTester = new CommandTester($command);
|
||||
$commandTester->execute(array(
|
||||
"command" => $command->getName(),
|
||||
"--env" => "test"
|
||||
));
|
||||
} else {
|
||||
throw new \RuntimeException("");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to build the container with the services that you need.
|
||||
* @param ContainerBuilder $container
|
||||
*/
|
||||
protected function buildContainer(ContainerBuilder $container)
|
||||
{
|
||||
$eventDispatcher = new EventDispatcher();
|
||||
$eventDispatcher->addSubscriber(new Cache());
|
||||
|
||||
$container->set("event_dispatcher", $eventDispatcher);
|
||||
|
||||
$container->setParameter("kernel.cache_dir", $this->cache_dir);
|
||||
}
|
||||
}
|
||||
281
tests/phpunit/Thelia/Tests/Command/ConfigCommandTest.php
Normal file
281
tests/phpunit/Thelia/Tests/Command/ConfigCommandTest.php
Normal file
@@ -0,0 +1,281 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Command;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Thelia\Command\ConfigCommand;
|
||||
use Thelia\Core\Application;
|
||||
use Thelia\Model\Config;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
|
||||
/**
|
||||
* Class ConfigCommandTest
|
||||
* @package Command
|
||||
* @author Julien Chanséaume <jchanseaume@openstudio.fr>
|
||||
*/
|
||||
class ConfigCommandTest extends BaseCommandTest
|
||||
{
|
||||
/** @var ConfigCommand */
|
||||
protected $command;
|
||||
|
||||
/** @var CommandTester */
|
||||
protected $commandTester;
|
||||
|
||||
const PREFIX_NAME = "config_command_test_";
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
self::clearTest();
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
self::clearTest();
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
if (null === $this->commandTester) {
|
||||
$application = new Application($this->getKernel());
|
||||
$configCommand = new ConfigCommand();
|
||||
|
||||
$application->add($configCommand);
|
||||
|
||||
$this->command = $application->find("thelia:config");
|
||||
$this->commandTester = new CommandTester($this->command);
|
||||
}
|
||||
}
|
||||
|
||||
public function testArguments()
|
||||
{
|
||||
$tester = $this->commandTester;
|
||||
|
||||
$commands = $this->getFakeCommands();
|
||||
|
||||
foreach ($commands as $command) {
|
||||
$arguments = array_merge(
|
||||
$command['args'],
|
||||
["command" => $this->command->getName()]
|
||||
);
|
||||
|
||||
$tester->execute($arguments);
|
||||
|
||||
$this->assertStringContains(
|
||||
$tester->getDisplay(),
|
||||
$command["out"],
|
||||
"Should display : " . $command["out"]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function testList()
|
||||
{
|
||||
$tester = $this->commandTester;
|
||||
|
||||
$tester->execute([
|
||||
"command" => $this->command->getName(),
|
||||
"COMMAND" => "list"
|
||||
]);
|
||||
|
||||
$out = $tester->getDisplay();
|
||||
|
||||
$vars = ConfigQuery::create()->find();
|
||||
|
||||
/** @var Config $var */
|
||||
foreach ($vars as $var) {
|
||||
$this->assertStringContains(
|
||||
$out,
|
||||
$var->getName(),
|
||||
"Should display : " . $var->getName()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetSetDelete()
|
||||
{
|
||||
$tester = $this->commandTester;
|
||||
|
||||
$varName = $this->getRandomVariableName();
|
||||
|
||||
// Get
|
||||
$tester->execute([
|
||||
"command" => $this->command->getName(),
|
||||
"COMMAND" => "get",
|
||||
"name" => $varName
|
||||
]);
|
||||
|
||||
$expected = sprintf("Unknown variable '%s'", $varName);
|
||||
|
||||
$this->assertStringContains(
|
||||
$tester->getDisplay(),
|
||||
$expected,
|
||||
"Should display : " . $expected
|
||||
);
|
||||
|
||||
// Set
|
||||
$tester->execute([
|
||||
"command" => $this->command->getName(),
|
||||
"COMMAND" => "set",
|
||||
"name" => $varName,
|
||||
"value" => "0"
|
||||
]);
|
||||
|
||||
$this->assertVariableEqual($varName, "0");
|
||||
|
||||
$tester->execute([
|
||||
"command" => $this->command->getName(),
|
||||
"COMMAND" => "set",
|
||||
"name" => $varName,
|
||||
"value" => "Thelia"
|
||||
]);
|
||||
|
||||
$this->assertVariableEqual($varName, "Thelia");
|
||||
|
||||
$tester->execute([
|
||||
"command" => $this->command->getName(),
|
||||
"COMMAND" => "set",
|
||||
"name" => $varName,
|
||||
"value" => "Thelia",
|
||||
"--secured" => true,
|
||||
"--visible" => true,
|
||||
]);
|
||||
|
||||
$this->assertVariableEqual($varName, "Thelia", 1, 0);
|
||||
|
||||
$tester->execute([
|
||||
"command" => $this->command->getName(),
|
||||
"COMMAND" => "set",
|
||||
"name" => $varName,
|
||||
"value" => "THELIA",
|
||||
"--visible" => true
|
||||
]);
|
||||
|
||||
$this->assertVariableEqual($varName, "THELIA", 0, 0);
|
||||
|
||||
// DELETE
|
||||
$tester->execute([
|
||||
"command" => $this->command->getName(),
|
||||
"COMMAND" => "delete",
|
||||
"name" => $varName
|
||||
]);
|
||||
|
||||
$this->assertNull(
|
||||
ConfigQuery::read($varName),
|
||||
sprintf("Variable '%s' should not exist", $varName)
|
||||
);
|
||||
}
|
||||
|
||||
public static function clearTest()
|
||||
{
|
||||
ConfigQuery::create()
|
||||
->filterByName(self::PREFIX_NAME . '%', Criteria::LIKE)
|
||||
->delete();
|
||||
}
|
||||
|
||||
protected function getRandomVariableName()
|
||||
{
|
||||
return sprintf(
|
||||
"%s%s",
|
||||
self::PREFIX_NAME,
|
||||
substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyz"), 0, 10)
|
||||
);
|
||||
}
|
||||
|
||||
protected function assertVariableEqual($name, $value, $secured = 0, $hidden = 1)
|
||||
{
|
||||
$var = ConfigQuery::create()->findOneByName($name);
|
||||
|
||||
$this->assertNotNull($var, sprintf("Variable '%s' should exist", $name));
|
||||
|
||||
$this->assertEquals(
|
||||
$var->getName(),
|
||||
$name,
|
||||
sprintf("Variable '%s' should have name '%s' :/", $var->getName(), $name)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$var->getValue(),
|
||||
$value,
|
||||
sprintf(
|
||||
"Variable '%s' should have value '%s' ('%s' found)",
|
||||
$name,
|
||||
$value,
|
||||
$var->getValue()
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$var->getSecured(),
|
||||
$secured,
|
||||
sprintf("Variable '%s' should be %s secured", $name, $secured === 1 ? '' : 'NOT')
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$var->getHidden(),
|
||||
$hidden,
|
||||
sprintf("Variable '%s' should be %s hidden", $name, $hidden === 1 ? '' : 'NOT')
|
||||
);
|
||||
}
|
||||
|
||||
protected function assertStringContains($data, $needle, $message = "")
|
||||
{
|
||||
$this->assertTrue((false !== strpos($data, $needle)), $message);
|
||||
}
|
||||
|
||||
protected function assertStringNotContains($data, $needle, $message = "")
|
||||
{
|
||||
$this->assertTrue((false === strpos($data, $needle)), $message);
|
||||
}
|
||||
|
||||
protected function getFakeCommands()
|
||||
{
|
||||
$commands = [
|
||||
[
|
||||
"args" => [
|
||||
'COMMAND' => 'hello',
|
||||
],
|
||||
'out' => "Unknown argument 'COMMAND'"
|
||||
],
|
||||
[
|
||||
"args" => [
|
||||
'COMMAND' => 'get',
|
||||
],
|
||||
'out' => "Need argument 'name'"
|
||||
],
|
||||
[
|
||||
"args" => [
|
||||
'COMMAND' => 'get',
|
||||
'name' => 'unknown_var_name',
|
||||
],
|
||||
'out' => "Unknown variable 'unknown_var_name'"
|
||||
],
|
||||
[
|
||||
"args" => [
|
||||
'COMMAND' => 'delete',
|
||||
'name' => 'unknown_var_name',
|
||||
],
|
||||
'out' => "Unknown variable 'unknown_var_name'"
|
||||
],
|
||||
[
|
||||
"args" => [
|
||||
'COMMAND' => 'set',
|
||||
'name' => 'unknown_var_name',
|
||||
],
|
||||
'out' => "Need argument 'name' and 'value'"
|
||||
]
|
||||
];
|
||||
|
||||
return $commands;
|
||||
}
|
||||
}
|
||||
106
tests/phpunit/Thelia/Tests/Command/ModuleActivateCommandTest.php
Normal file
106
tests/phpunit/Thelia/Tests/Command/ModuleActivateCommandTest.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Command;
|
||||
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Thelia\Action\Module;
|
||||
use Thelia\Command\ModuleActivateCommand;
|
||||
use Thelia\Core\Application;
|
||||
use Thelia\Model\ModuleQuery;
|
||||
use Thelia\Module\BaseModule;
|
||||
use Thelia\Tests\ContainerAwareTestCase;
|
||||
|
||||
/**
|
||||
* Class ModuleActivateCommandTest
|
||||
*
|
||||
* @package Thelia\Tests\Command
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*/
|
||||
class ModuleActivateCommandTest extends ContainerAwareTestCase
|
||||
{
|
||||
public function testModuleActivateCommand()
|
||||
{
|
||||
$module = ModuleQuery::create()->findOne();
|
||||
|
||||
if (null !== $module) {
|
||||
$prev_activation_status = $module->getActivate();
|
||||
|
||||
$application = new Application($this->getKernel());
|
||||
|
||||
$module->setActivate(BaseModule::IS_NOT_ACTIVATED);
|
||||
$module->save();
|
||||
|
||||
$moduleActivate = new ModuleActivateCommand();
|
||||
$moduleActivate->setContainer($this->getContainer());
|
||||
|
||||
$application->add($moduleActivate);
|
||||
|
||||
$command = $application->find("module:activate");
|
||||
$commandTester = new CommandTester($command);
|
||||
$commandTester->execute(array(
|
||||
"command" => $command->getName(),
|
||||
"module" => $module->getCode(),
|
||||
));
|
||||
|
||||
$activated = ModuleQuery::create()->findPk($module->getId())->getActivate();
|
||||
|
||||
// Restore activation status
|
||||
$module->setActivate($prev_activation_status)->save();
|
||||
|
||||
$this->assertEquals(BaseModule::IS_ACTIVATED, $activated);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
* @expectedExceptionMessage module Letshopethismoduledoesnotexists not found
|
||||
*/
|
||||
public function testModuleActivateCommandUnknownModule()
|
||||
{
|
||||
$testedModule = ModuleQuery::create()->findOneByCode('Letshopethismoduledoesnotexists');
|
||||
|
||||
if (null == $testedModule) {
|
||||
$application = new Application($this->getKernel());
|
||||
|
||||
$moduleActivate = new ModuleActivateCommand();
|
||||
$moduleActivate->setContainer($this->getContainer());
|
||||
|
||||
$application->add($moduleActivate);
|
||||
|
||||
$command = $application->find("module:activate");
|
||||
$commandTester = new CommandTester($command);
|
||||
$commandTester->execute(array(
|
||||
"command" => $command->getName(),
|
||||
"module" => "letshopethismoduledoesnotexists",
|
||||
));
|
||||
|
||||
$out = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to build the container with the services that you need.
|
||||
* @param ContainerBuilder $container
|
||||
*/
|
||||
protected function buildContainer(ContainerBuilder $container)
|
||||
{
|
||||
$eventDispatcher = new EventDispatcher();
|
||||
$eventDispatcher->addSubscriber(new Module($container, $eventDispatcher));
|
||||
|
||||
$container->set("event_dispatcher", $eventDispatcher);
|
||||
|
||||
$container->setParameter('kernel.cache_dir', THELIA_CACHE_DIR . 'dev');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Command;
|
||||
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Thelia\Action\Module;
|
||||
use Thelia\Command\ModuleDeactivateCommand;
|
||||
use Thelia\Core\Application;
|
||||
use Thelia\Model\ModuleQuery;
|
||||
use Thelia\Module\BaseModule;
|
||||
use Thelia\Tests\ContainerAwareTestCase;
|
||||
|
||||
/**
|
||||
* Class ModuleDeactivateCommandTest
|
||||
*
|
||||
* @package Thelia\Tests\Command
|
||||
* @author Nicolas Villa <nicolas@libre-shop.com>
|
||||
*/
|
||||
class ModuleDeactivateCommandTest extends ContainerAwareTestCase
|
||||
{
|
||||
public function testModuleDeactivateCommand()
|
||||
{
|
||||
$module = ModuleQuery::create()->findOne();
|
||||
|
||||
if (null !== $module) {
|
||||
$prev_activation_status = $module->getActivate();
|
||||
|
||||
$application = new Application($this->getKernel());
|
||||
|
||||
$module->setActivate(BaseModule::IS_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())->getActivate();
|
||||
|
||||
// Restore activation status
|
||||
$module->setActivate($prev_activation_status)->save();
|
||||
|
||||
$this->assertEquals(BaseModule::IS_NOT_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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContainerBuilder $container
|
||||
* Use this method to build the container with the services that you need.
|
||||
*/
|
||||
protected function buildContainer(ContainerBuilder $container)
|
||||
{
|
||||
$eventDispatcher = new EventDispatcher();
|
||||
$eventDispatcher->addSubscriber(new Module($container, $this->getMockEventDispatcher()));
|
||||
|
||||
$container->set("event_dispatcher", $eventDispatcher);
|
||||
|
||||
$container->setParameter('kernel.cache_dir', THELIA_CACHE_DIR . 'dev');
|
||||
}
|
||||
}
|
||||
131
tests/phpunit/Thelia/Tests/Command/ModuleGenerateCommandTest.php
Normal file
131
tests/phpunit/Thelia/Tests/Command/ModuleGenerateCommandTest.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Thelia\Core\Application;
|
||||
use Thelia\Command\ModuleGenerateCommand;
|
||||
|
||||
/**
|
||||
* test the module:generate command
|
||||
*
|
||||
* Class ModuleGenerateCommandTest
|
||||
* @package Thelia\Tests\Command
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class ModuleGenerateCommandTest extends BaseCommandTest
|
||||
{
|
||||
/** @var Command */
|
||||
protected $command;
|
||||
|
||||
/** @var CommandTester */
|
||||
protected $commandTester;
|
||||
|
||||
public static function clearTest()
|
||||
{
|
||||
$fs = new Filesystem();
|
||||
|
||||
if ($fs->exists(THELIA_MODULE_DIR . "Test")) {
|
||||
$fs->remove(THELIA_MODULE_DIR . "Test");
|
||||
}
|
||||
}
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
self::clearTest();
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
self::clearTest();
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$application = new Application($this->getKernel());
|
||||
|
||||
$moduleGenerator = new ModuleGenerateCommand();
|
||||
|
||||
$application->add($moduleGenerator);
|
||||
|
||||
$this->command = $application->find("module:generate");
|
||||
$this->commandTester = new CommandTester($this->command);
|
||||
}
|
||||
|
||||
public function testGenerateModule()
|
||||
{
|
||||
$tester = $this->commandTester;
|
||||
|
||||
$tester->execute(array(
|
||||
"command" => $this->command->getName(),
|
||||
"name" => "test"
|
||||
));
|
||||
|
||||
$fs = new Filesystem();
|
||||
|
||||
$this->assertTrue($fs->exists(THELIA_MODULE_DIR . "Test"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGenerateModule
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testGenerateDuplicateModule()
|
||||
{
|
||||
$tester = $this->commandTester;
|
||||
|
||||
$tester->execute(array(
|
||||
"command" => $this->command->getName(),
|
||||
"name" => "test"
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGenerateModule
|
||||
*/
|
||||
public function testGenerateDuplicateModuleWithForceOption()
|
||||
{
|
||||
$tester = $this->commandTester;
|
||||
|
||||
// remove the config.xml
|
||||
$fs = new Filesystem();
|
||||
$configFile = THELIA_MODULE_DIR . "Test" .
|
||||
DIRECTORY_SEPARATOR . "Config" .
|
||||
DIRECTORY_SEPARATOR . "config.xml"
|
||||
;
|
||||
$fs->remove($configFile);
|
||||
|
||||
$tester->execute(array(
|
||||
"command" => $this->command->getName(),
|
||||
"name" => "test",
|
||||
"--force" => ""
|
||||
));
|
||||
|
||||
$this->assertTrue($fs->exists($configFile));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testGenerateWithReservedKeyWord()
|
||||
{
|
||||
$tester = $this->commandTester;
|
||||
|
||||
$tester->execute(array(
|
||||
"command" => $this->command->getName(),
|
||||
"name" => "thelia"
|
||||
));
|
||||
}
|
||||
}
|
||||
104
tests/phpunit/Thelia/Tests/Command/ModuleRefreshCommandTest.php
Normal file
104
tests/phpunit/Thelia/Tests/Command/ModuleRefreshCommandTest.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Command;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpKernel\Kernel;
|
||||
use Thelia\Command\ModuleRefreshCommand;
|
||||
use Thelia\Core\Application;
|
||||
use Thelia\Model\ModuleQuery;
|
||||
use Thelia\Module\ModuleManagement;
|
||||
|
||||
/**
|
||||
* Class ModuleRefreshCommandTest
|
||||
* Test refresh modules list command
|
||||
*
|
||||
* @package Thelia\Tests\Command
|
||||
* @author Jérôme Billiras <jbilliras@openstudio.fr>
|
||||
*
|
||||
* Date: 2014-06-06
|
||||
* Time: 17:29
|
||||
*/
|
||||
class ModuleRefreshCommandTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Test ModuleRefreshCommand
|
||||
*/
|
||||
public function testModuleRefreshCommand()
|
||||
{
|
||||
$moduleManagement = new ModuleManagement;
|
||||
$moduleManagement->updateModules($this->getContainer());
|
||||
|
||||
$module = ModuleQuery::create()->filterByType(1)->orderByPosition(Criteria::DESC)->findOne();
|
||||
|
||||
if ($module !== null) {
|
||||
$module->delete();
|
||||
|
||||
$application = new Application($this->getKernel());
|
||||
|
||||
$moduleRefresh = new ModuleRefreshCommand;
|
||||
$moduleRefresh->setContainer($this->getContainer());
|
||||
|
||||
$application->add($moduleRefresh);
|
||||
|
||||
$command = $application->find('module:refresh');
|
||||
$commandTester = new CommandTester($command);
|
||||
$commandTester->execute([
|
||||
'command' => $command->getName()
|
||||
]);
|
||||
|
||||
$expected = $module;
|
||||
$actual = ModuleQuery::create()->filterByType(1)->orderByPosition(Criteria::DESC)->findOne();
|
||||
|
||||
$this->assertEquals($expected->getCode(), $actual->getCode(), 'Last standard module code must be same after deleting this one and calling module:refresh');
|
||||
$this->assertEquals($expected->getType(), $actual->getType(), 'Last standard module type must be same after deleting this one and calling module:refresh');
|
||||
$this->assertEquals($expected->getFullNamespace(), $actual->getFullNamespace(), 'Last standard module namespace must be same after deleting this one and calling module:refresh');
|
||||
|
||||
// Restore activation status
|
||||
$actual
|
||||
->setActivate($expected->getActivate())
|
||||
->save();
|
||||
} else {
|
||||
$this->markTestIncomplete(
|
||||
'This test cannot be complete without at least one standard module.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get HttpKernel mock
|
||||
*
|
||||
* @return Kernel Not really a Kernel but the mocked one
|
||||
*/
|
||||
public function getKernel()
|
||||
{
|
||||
$kernel = $this->getMock('Symfony\\Component\\HttpKernel\\KernelInterface');
|
||||
|
||||
return $kernel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get new ContainerBuilder
|
||||
*
|
||||
* @return ContainerBuilder
|
||||
*/
|
||||
public function getContainer()
|
||||
{
|
||||
$container = new ContainerBuilder;
|
||||
|
||||
return $container;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Command;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Thelia\Action\Sale;
|
||||
use Thelia\Command\SaleCheckActivationCommand;
|
||||
use Thelia\Core\Application;
|
||||
use Thelia\Model\SaleQuery;
|
||||
use Thelia\Tests\ContainerAwareTestCase;
|
||||
|
||||
/**
|
||||
* Class SaleCheckActivationCommandTest
|
||||
* @package Thelia\Tests\Command
|
||||
* @author manuel raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class SaleCheckActivationCommandTest extends ContainerAwareTestCase
|
||||
{
|
||||
protected static $deactivated;
|
||||
|
||||
protected static $activated;
|
||||
|
||||
/**
|
||||
* in this method two sales are created. The first must be activated and the second one must be deactivated
|
||||
*/
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
/** @var \Thelia\Model\Sale $sale */
|
||||
$sale = SaleQuery::create()
|
||||
->addAscendingOrderByColumn('RAND()')
|
||||
->findOne();
|
||||
|
||||
if (null === $sale) {
|
||||
throw new \RuntimeException('use fixtures before launching test, there is no sale in database');
|
||||
}
|
||||
|
||||
$startDate = new \DateTime("@".strtotime("today - 1 month"));
|
||||
$endDate = new \DateTime("@".strtotime("today + 1 month"));
|
||||
|
||||
$sale->setStartDate($startDate)
|
||||
->setEndDate($endDate)
|
||||
->setActive(false)
|
||||
->save();
|
||||
|
||||
self::$deactivated = $sale->getId();
|
||||
|
||||
/** @var \Thelia\Model\Sale $otherSale */
|
||||
$otherSale = SaleQuery::create()
|
||||
->filterById($sale->getId(), Criteria::NOT_IN)
|
||||
->addAscendingOrderByColumn('RAND()')
|
||||
->findOne();
|
||||
|
||||
$startDate = new \DateTime("@".strtotime("today - 1 month"));
|
||||
$endDate = new \DateTime("@".strtotime("today - 1 day"));
|
||||
|
||||
$otherSale
|
||||
->setStartDate($startDate)
|
||||
->setEndDate($endDate)
|
||||
->setActive(true)
|
||||
->save();
|
||||
|
||||
|
||||
self::$activated = $otherSale->getId();
|
||||
}
|
||||
|
||||
public function testCommand()
|
||||
{
|
||||
$application = new Application($this->getKernel());
|
||||
|
||||
$checkCommand = new SaleCheckActivationCommand();
|
||||
$checkCommand->setContainer($this->getContainer());
|
||||
|
||||
$application->add($checkCommand);
|
||||
|
||||
$command = $application->find("sale:check-activation");
|
||||
$commandTester = new CommandTester($command);
|
||||
$commandTester->execute([
|
||||
"command" => $command->getName(),
|
||||
"--env" => "test"
|
||||
]);
|
||||
|
||||
$deactivatedSale = SaleQuery::create()->findPk(self::$deactivated);
|
||||
|
||||
$this->assertTrue($deactivatedSale->getActive(), "the sale must be actived now");
|
||||
|
||||
$activatedSale = SaleQuery::create()->findPk(self::$activated);
|
||||
|
||||
$this->assertFalse($activatedSale->getActive(), "the sale must be deactived now");
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to build the container with the services that you need.
|
||||
* @param ContainerBuilder $container
|
||||
*/
|
||||
protected function buildContainer(ContainerBuilder $container)
|
||||
{
|
||||
$eventDispatcher = new EventDispatcher();
|
||||
$eventDispatcher->addSubscriber(new Sale($eventDispatcher));
|
||||
|
||||
$container->set("event_dispatcher", $eventDispatcher);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user