Initial Commit
This commit is contained in:
33
tests/phpunit/Thelia/Tests/Model/CurrencyTest.php
Normal file
33
tests/phpunit/Thelia/Tests/Model/CurrencyTest.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?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\Model;
|
||||
|
||||
use Thelia\Model\Currency;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
|
||||
/**
|
||||
* Class CurrencyTest
|
||||
* @package Thelia\Tests\Model
|
||||
* @author Gilles Bourgeat <gilles@thelia.net>
|
||||
*/
|
||||
class CurrencyTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testGetDefaultCurrency()
|
||||
{
|
||||
$expectedCurrency = CurrencyQuery::create()->findOneByByDefault(true);
|
||||
$actualCurrency = Currency::getDefaultCurrency();
|
||||
|
||||
$this->assertEquals($expectedCurrency->getId(), $actualCurrency->getId());
|
||||
|
||||
}
|
||||
}
|
||||
338
tests/phpunit/Thelia/Tests/Model/MessageTest.php
Normal file
338
tests/phpunit/Thelia/Tests/Model/MessageTest.php
Normal file
@@ -0,0 +1,338 @@
|
||||
<?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\Model;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
use Thelia\Core\Form\TheliaFormFactory;
|
||||
use Thelia\Core\Form\TheliaFormValidator;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Core\HttpFoundation\Session\Session;
|
||||
use Thelia\Core\Template\ParserContext;
|
||||
use Thelia\Core\Template\TheliaTemplateHelper;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Model\Message as ModelMessage;
|
||||
use TheliaSmarty\Template\SmartyParser;
|
||||
|
||||
/**
|
||||
* Class CustomerTest
|
||||
* @package Thelia\Tests\Model
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*/
|
||||
class MessageTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** @var ContainerBuilder */
|
||||
protected $container;
|
||||
|
||||
/** @var SmartyParser */
|
||||
protected $parser;
|
||||
|
||||
/** @var TheliaTemplateHelper */
|
||||
protected $templateHelper;
|
||||
|
||||
private $backup_mail_template = 'undefined';
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->backup_mail_template = ConfigQuery::read('active-mail-template', 'default');
|
||||
|
||||
ConfigQuery::write('active-mail-template', 'test');
|
||||
|
||||
$this->templateHelper = new TheliaTemplateHelper();
|
||||
|
||||
@mkdir($this->templateHelper->getActiveMailTemplate()->getAbsolutePath(), 0777, true);
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
$request = new Request();
|
||||
$requestStack = new RequestStack();
|
||||
$requestStack->push($request);
|
||||
|
||||
$dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface");
|
||||
|
||||
$request->setSession($session);
|
||||
|
||||
$parserContext = new ParserContext(
|
||||
$requestStack,
|
||||
new TheliaFormFactory($requestStack, $container, []),
|
||||
new TheliaFormValidator(new Translator($container), 'dev')
|
||||
);
|
||||
|
||||
$container->set("event_dispatcher", $dispatcher);
|
||||
$container->set('request', $request);
|
||||
|
||||
$this->parser = new SmartyParser($requestStack, $dispatcher, $parserContext, $this->templateHelper, 'dev', true);
|
||||
$this->parser->setTemplateDefinition($this->templateHelper->getActiveMailTemplate());
|
||||
|
||||
$container->set('thelia.parser', $this->parser);
|
||||
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create message with HTML and TEXT body from message HTMl and TEXT fields
|
||||
*/
|
||||
public function testMessageWithTextAndHtmlBody()
|
||||
{
|
||||
$message = new ModelMessage();
|
||||
|
||||
$message->setLocale('fr_FR');
|
||||
|
||||
$message->setSubject("The subject");
|
||||
$message->setHtmlMessage("The HTML content");
|
||||
$message->setTextMessage("The TEXT content");
|
||||
|
||||
$instance = \Swift_Message::newInstance();
|
||||
|
||||
$message->buildMessage($this->parser, $instance);
|
||||
|
||||
$this->assertEquals("The subject", $instance->getSubject());
|
||||
$this->assertEquals("The HTML content", $instance->getBody());
|
||||
$this->assertEquals("The TEXT content", $instance->getChildren()[0]->getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create message with TEXT body only from message HTMl and TEXT fields
|
||||
*/
|
||||
public function testMessageWithTextOnlyBody()
|
||||
{
|
||||
$message = new ModelMessage();
|
||||
|
||||
$message->setLocale('fr_FR');
|
||||
|
||||
$message->setSubject("The subject");
|
||||
$message->setTextMessage("The TEXT content");
|
||||
|
||||
$instance = \Swift_Message::newInstance();
|
||||
|
||||
$message->buildMessage($this->parser, $instance);
|
||||
|
||||
$this->assertEquals("The subject", $instance->getSubject());
|
||||
$this->assertEquals("The TEXT content", $instance->getBody());
|
||||
$this->assertEquals(0, count($instance->getChildren()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create message with HTML and TEXT body from message HTMl and TEXT fields
|
||||
* using a text and a html layout
|
||||
*/
|
||||
public function testMessageWithTextAndHtmlBodyAndTextAndHtmlLayout()
|
||||
{
|
||||
$message = new ModelMessage();
|
||||
|
||||
$message->setLocale('fr_FR');
|
||||
|
||||
$message->setSubject("The subject");
|
||||
$message->setTextMessage("The TEXT content");
|
||||
$message->setHtmlMessage("The HTML content");
|
||||
|
||||
$message->setHtmlLayoutFileName('layout.html.tpl');
|
||||
$message->setTextLayoutFileName('layout.text.tpl');
|
||||
|
||||
$path = $this->templateHelper->getActiveMailTemplate()->getAbsolutePath();
|
||||
|
||||
file_put_contents($path.DS.'layout.html.tpl', 'HTML Layout: {$message_body nofilter}');
|
||||
file_put_contents($path.DS.'layout.text.tpl', 'TEXT Layout: {$message_body nofilter}');
|
||||
|
||||
$instance = \Swift_Message::newInstance();
|
||||
|
||||
$message->buildMessage($this->parser, $instance);
|
||||
|
||||
$this->assertEquals("The subject", $instance->getSubject());
|
||||
$this->assertEquals("HTML Layout: The HTML content", $instance->getBody());
|
||||
$this->assertEquals("TEXT Layout: The TEXT content", $instance->getChildren()[0]->getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create message with TEXT only body from message HTMl and TEXT fields
|
||||
* using a text only layout
|
||||
*/
|
||||
public function testMessageWithTextOnlyBodyAndTextOnlyLayout()
|
||||
{
|
||||
$message = new ModelMessage();
|
||||
|
||||
$message->setLocale('fr_FR');
|
||||
|
||||
$message->setSubject("The subject");
|
||||
$message->setTextMessage("The <TEXT> & content");
|
||||
|
||||
$message->setTextLayoutFileName('layout3.text.tpl');
|
||||
|
||||
$path = $this->templateHelper->getActiveMailTemplate()->getAbsolutePath();
|
||||
|
||||
file_put_contents($path.DS.'layout3.text.tpl', 'TEXT Layout 3: {$message_body nofilter} :-) <>');
|
||||
|
||||
$instance = \Swift_Message::newInstance();
|
||||
|
||||
$message->buildMessage($this->parser, $instance);
|
||||
|
||||
$this->assertEquals("The subject", $instance->getSubject());
|
||||
$this->assertEquals("TEXT Layout 3: The <TEXT> & content :-) <>", $instance->getBody());
|
||||
$this->assertEquals(0, count($instance->getChildren()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create message with TEXT and HTML body from message HTMl and TEXT fields
|
||||
* using a text only layout
|
||||
*/
|
||||
public function testMessageWithTextAndHtmlBodyAndTextOnlyLayout()
|
||||
{
|
||||
$message = new ModelMessage();
|
||||
|
||||
$message->setLocale('fr_FR');
|
||||
|
||||
$message->setSubject("The subject");
|
||||
$message->setTextMessage("The <TEXT> & content");
|
||||
$message->setHtmlMessage("The <HTML> & content");
|
||||
|
||||
$message->setTextLayoutFileName('layout3.text.tpl');
|
||||
|
||||
$path = $this->templateHelper->getActiveMailTemplate()->getAbsolutePath();
|
||||
|
||||
file_put_contents($path.DS.'layout3.text.tpl', 'TEXT Layout 3: {$message_body nofilter} :-) <>');
|
||||
|
||||
$instance = \Swift_Message::newInstance();
|
||||
|
||||
$message->buildMessage($this->parser, $instance);
|
||||
|
||||
$this->assertEquals("The subject", $instance->getSubject());
|
||||
$this->assertEquals("The <HTML> & content", $instance->getBody());
|
||||
$this->assertEquals("TEXT Layout 3: The <TEXT> & content :-) <>", $instance->getChildren()[0]->getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create message with HTML and TEXT body from template HTMl and TEXT fields
|
||||
* using a text and a html layout
|
||||
*/
|
||||
public function testMessageWithTextAndHtmlBodyAndTextAndHtmlLayoutAndTextAndHtmlTemplate()
|
||||
{
|
||||
$message = new ModelMessage();
|
||||
|
||||
$message->setLocale('fr_FR');
|
||||
|
||||
$message->setSubject("The subject");
|
||||
$message->setTextMessage("The TEXT content");
|
||||
$message->setHtmlMessage("The HTML content");
|
||||
|
||||
$message->setTextTemplateFileName('template4-text.txt');
|
||||
$message->setHtmlTemplateFileName('template4-html.html');
|
||||
|
||||
$message->setHtmlLayoutFileName('layout4.html.tpl');
|
||||
$message->setTextLayoutFileName('layout4.text.tpl');
|
||||
|
||||
$path = $this->templateHelper->getActiveMailTemplate()->getAbsolutePath();
|
||||
|
||||
$this->parser->assign('myvar', 'my-value');
|
||||
|
||||
file_put_contents($path.DS.'layout4.html.tpl', 'HTML Layout 4: {$message_body nofilter}');
|
||||
file_put_contents($path.DS.'layout4.text.tpl', 'TEXT Layout 4: {$message_body nofilter}');
|
||||
|
||||
file_put_contents($path.DS.'template4-html.html', 'HTML <template> & content v={$myvar}');
|
||||
file_put_contents($path.DS.'template4-text.txt', 'TEXT <template> & content v={$myvar}');
|
||||
|
||||
$instance = \Swift_Message::newInstance();
|
||||
|
||||
$message->buildMessage($this->parser, $instance);
|
||||
|
||||
$this->assertEquals("The subject", $instance->getSubject());
|
||||
$this->assertEquals("HTML Layout 4: HTML <template> & content v=my-value", $instance->getBody());
|
||||
$this->assertEquals("TEXT Layout 4: TEXT <template> & content v=my-value", $instance->getChildren()[0]->getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create message with HTML and TEXT body from template HTMl and TEXT fields
|
||||
* using a text and a html layout
|
||||
*/
|
||||
public function testMessageWithTextAndHtmlBodyAndTextAndHtmlLayoutAndTextAndHtmlTemplateWichExtendsLayout()
|
||||
{
|
||||
$message = new ModelMessage();
|
||||
|
||||
$message->setLocale('fr_FR');
|
||||
|
||||
$message->setSubject("The subject");
|
||||
$message->setTextMessage("The TEXT content");
|
||||
$message->setHtmlMessage("The HTML content");
|
||||
|
||||
$message->setTextTemplateFileName('template5-text.txt');
|
||||
$message->setHtmlTemplateFileName('template5-html.html');
|
||||
|
||||
//$message->setHtmlLayoutFileName('layout5.html.tpl');
|
||||
//$message->setTextLayoutFileName('layout5.text.tpl');
|
||||
|
||||
$path = $this->templateHelper->getActiveMailTemplate()->getAbsolutePath();
|
||||
|
||||
$this->parser->assign('myvar', 'my-value');
|
||||
|
||||
file_put_contents($path.DS.'layout5.html.tpl', 'HTML Layout 5: {block name="message-body"}{$message_body nofilter}{/block}');
|
||||
file_put_contents($path.DS.'layout5.text.tpl', 'TEXT Layout 5: {block name="message-body"}{$message_body nofilter}{/block}');
|
||||
|
||||
file_put_contents($path.DS.'template5-html.html', '{extends file="layout5.html.tpl"}{block name="message-body"}HTML <template> & content v={$myvar}{/block}');
|
||||
file_put_contents($path.DS.'template5-text.txt', '{extends file="layout5.text.tpl"}{block name="message-body"}TEXT <template> & content v={$myvar}{/block}');
|
||||
|
||||
$instance = \Swift_Message::newInstance();
|
||||
|
||||
$message->buildMessage($this->parser, $instance);
|
||||
|
||||
$this->assertEquals("The subject", $instance->getSubject());
|
||||
$this->assertEquals("HTML Layout 5: HTML <template> & content v=my-value", $instance->getBody());
|
||||
$this->assertEquals("TEXT Layout 5: TEXT <template> & content v=my-value", $instance->getChildren()[0]->getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create message with HTML and TEXT body from template HTMl and TEXT fields
|
||||
* using a text and a html layout
|
||||
*/
|
||||
public function testMessageWithTextAndHtmlBodyAndTextAndHtmlExtendableLayout()
|
||||
{
|
||||
$message = new ModelMessage();
|
||||
|
||||
$message->setLocale('fr_FR');
|
||||
|
||||
$message->setSubject("The subject");
|
||||
$message->setTextMessage('TEXT <template> & content v={$myvar}');
|
||||
$message->setHtmlMessage('HTML <template> & content v={$myvar}');
|
||||
|
||||
$message->setHtmlLayoutFileName('layout6.html.tpl');
|
||||
$message->setTextLayoutFileName('layout6.text.tpl');
|
||||
|
||||
$path = $this->templateHelper->getActiveMailTemplate()->getAbsolutePath();
|
||||
|
||||
$this->parser->assign('myvar', 'my-value');
|
||||
|
||||
file_put_contents($path.DS.'layout6.html.tpl', 'HTML Layout 6: {block name="message-body"}{$message_body nofilter}{/block}');
|
||||
file_put_contents($path.DS.'layout6.text.tpl', 'TEXT Layout 6: {block name="message-body"}{$message_body nofilter}{/block}');
|
||||
|
||||
$instance = \Swift_Message::newInstance();
|
||||
|
||||
$message->buildMessage($this->parser, $instance);
|
||||
|
||||
$this->assertEquals("The subject", $instance->getSubject());
|
||||
$this->assertEquals("HTML Layout 6: HTML <template> & content v=my-value", $instance->getBody());
|
||||
$this->assertEquals("TEXT Layout 6: TEXT <template> & content v=my-value", $instance->getChildren()[0]->getBody());
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$dir = $this->templateHelper->getActiveMailTemplate()->getAbsolutePath();
|
||||
|
||||
ConfigQuery::write('active-mail-template', $this->backup_mail_template);
|
||||
|
||||
$fs = new Filesystem();
|
||||
|
||||
$fs->remove($dir);
|
||||
}
|
||||
}
|
||||
129
tests/phpunit/Thelia/Tests/Model/ModuleConfigTest.php
Normal file
129
tests/phpunit/Thelia/Tests/Model/ModuleConfigTest.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?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\Model;
|
||||
|
||||
use Thelia\Model\Base\ModuleQuery;
|
||||
use Thelia\Model\ModuleConfig;
|
||||
use Thelia\Model\ModuleConfigQuery;
|
||||
|
||||
/**
|
||||
* Class ModuleConfigTest
|
||||
* @package Thelia\Tests\Model
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*/
|
||||
class ModuleConfigTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testGetWithDefault()
|
||||
{
|
||||
$moduleModel = ModuleQuery::create()->findOne();
|
||||
|
||||
$moduleConfig = ModuleConfigQuery::create()->setConfigValue(
|
||||
$moduleModel->getId(),
|
||||
'test-name',
|
||||
'test-value'
|
||||
);
|
||||
|
||||
$val = ModuleConfigQuery::create()->getConfigValue($moduleModel->getId(), 'do-not-exists', 'default-value');
|
||||
|
||||
$this->assertEquals($val, 'default-value');
|
||||
|
||||
$moduleConfig->deleteConfigValue($moduleModel->getId(), 'test-name');
|
||||
}
|
||||
|
||||
public function testSetNoLocale()
|
||||
{
|
||||
$moduleModel = ModuleQuery::create()->findOne();
|
||||
|
||||
$moduleConfig = ModuleConfigQuery::create()->setConfigValue(
|
||||
$moduleModel->getId(),
|
||||
'test-name-1',
|
||||
'test-value'
|
||||
);
|
||||
|
||||
$val = $moduleConfig->getConfigValue($moduleModel->getId(), 'test-name-1');
|
||||
$this->assertEquals($val, 'test-value');
|
||||
|
||||
$val1 = $moduleConfig->getConfigValue($moduleModel->getId(), 'test-name-1', 'default-value', 'fr_FR');
|
||||
$this->assertEquals($val1, 'default-value');
|
||||
|
||||
$moduleConfig->deleteConfigValue($moduleModel->getId(), 'test-name-1');
|
||||
}
|
||||
|
||||
public function testSetLocale()
|
||||
{
|
||||
$moduleModel = ModuleQuery::create()->findOne();
|
||||
|
||||
$moduleConfig = ModuleConfigQuery::create()->setConfigValue(
|
||||
$moduleModel->getId(),
|
||||
'test-name-2',
|
||||
'test-value-uk',
|
||||
'en_UK'
|
||||
);
|
||||
|
||||
$moduleConfig->setConfigValue(
|
||||
$moduleModel->getId(),
|
||||
'test-name-2',
|
||||
'test-value-fr',
|
||||
'fr_FR'
|
||||
);
|
||||
|
||||
$val = $moduleConfig->getConfigValue($moduleModel->getId(), 'test-name-2', null, 'en_UK');
|
||||
$this->assertEquals($val, 'test-value-uk');
|
||||
|
||||
$val1 = $moduleConfig->getConfigValue($moduleModel->getId(), 'test-name-2', null, 'fr_FR');
|
||||
$this->assertEquals($val1, 'test-value-fr');
|
||||
|
||||
$val1 = $moduleConfig->getConfigValue($moduleModel->getId(), 'test-name-2', null, 'en_US');
|
||||
$this->assertNull($val1);
|
||||
|
||||
$moduleConfig->deleteConfigValue($moduleModel->getId(), 'test-name-2');
|
||||
}
|
||||
|
||||
public function testDeleteNotFound()
|
||||
{
|
||||
$moduleModel = ModuleQuery::create()->findOne();
|
||||
|
||||
ModuleConfigQuery::create()->deleteConfigValue($moduleModel->getId(), 'do-not-exists');
|
||||
}
|
||||
|
||||
public function testDelete()
|
||||
{
|
||||
$moduleModel = ModuleQuery::create()->findOne();
|
||||
|
||||
$moduleConfig = ModuleConfigQuery::create()->setConfigValue(
|
||||
$moduleModel->getId(),
|
||||
'test-name-3',
|
||||
'test-value'
|
||||
);
|
||||
ModuleConfigQuery::create()->deleteConfigValue($moduleModel->getId(), 'test-name-3');
|
||||
|
||||
$val1 = $moduleConfig->getConfigValue($moduleModel->getId(), 'test-name-3');
|
||||
$this->assertNull($val1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \LogicException
|
||||
*/
|
||||
public function testSetNotExists()
|
||||
{
|
||||
$moduleModel = ModuleQuery::create()->findOne();
|
||||
|
||||
$moduleConfig = ModuleConfigQuery::create()->setConfigValue(
|
||||
$moduleModel->getId(),
|
||||
'test-name-4',
|
||||
'test-value',
|
||||
null,
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user