From eeea885543c86419bbba2c241cc46f86d8f0696e Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 2 Sep 2013 23:36:34 +0200 Subject: [PATCH 1/8] create new smarty function for displaying date in expected format --- core/lib/Thelia/Config/Resources/config.xml | 5 + .../Core/HttpFoundation/Session/Session.php | 7 +- .../Core/Template/Smarty/Plugins/Format.php | 94 +++++++++++++++++++ core/lib/Thelia/Core/TheliaHttpKernel.php | 2 +- core/lib/Thelia/Model/Lang.php | 24 ++++- .../Template/Smarty/Plugins/FormatTest.php | 58 ++++++++++++ install/sqldb.map | 2 + reset_install.sh | 2 +- 8 files changed, 187 insertions(+), 7 deletions(-) create mode 100644 core/lib/Thelia/Core/Template/Smarty/Plugins/Format.php create mode 100644 core/lib/Thelia/Tests/Core/Template/Smarty/Plugins/FormatTest.php create mode 100644 install/sqldb.map diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 733e4303a..4c1bf61f8 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -121,6 +121,11 @@ + + + + + diff --git a/core/lib/Thelia/Core/HttpFoundation/Session/Session.php b/core/lib/Thelia/Core/HttpFoundation/Session/Session.php index 738cb531d..5f311ad0e 100755 --- a/core/lib/Thelia/Core/HttpFoundation/Session/Session.php +++ b/core/lib/Thelia/Core/HttpFoundation/Session/Session.php @@ -55,12 +55,15 @@ class Session extends BaseSession return $this; } + /** + * @return \Thelia\Model\Lang|null + */ public function getLang() { - return $this->get("lang", substr($this->getLocale(), 0, 2)); + return $this->get("lang"); } - public function setLang($lang) + public function setLang(Lang $lang) { $this->set("lang", $lang); diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Format.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Format.php new file mode 100644 index 000000000..c2fe1652d --- /dev/null +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Format.php @@ -0,0 +1,94 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Template\Smarty\Plugins; + +use Thelia\Core\HttpFoundation\Request; +use Thelia\Core\Template\Smarty\AbstractSmartyPlugin; +use Thelia\Core\Template\Smarty\SmartyPluginDescriptor; + +/** + * Class Format + * @package Thelia\Core\Template\Smarty\Plugins + * @author Manuel Raynaud + */ +class Format extends AbstractSmartyPlugin +{ + protected $request; + + public function __construct(Request $request) + { + $this->request = $request; + } + + /** + * @param $params + * @param $smarty + */ + public function formatDate($params, &$smarty = null) + { + $date = $params["date"]; + + if(!$date instanceof \DateTime) { + return ""; + } + + $format = null; + $output = array_key_exists("output", $params) ? $params["output"] : null; + + if (array_key_exists("format", $params)) { + $format = $params["format"]; + } else { + $session = $this->request->getSession(); + $lang = $session->getLang(); + + if($lang) { + switch ($output) { + case "date" : + $format = $lang->getDateFormat(); + break; + case "time" : + $format = $lang->getTimeFormat(); + break; + default: + case "datetime" : + $format = $lang->getDateTimeFormat(); + break; + } + } + } + + return $date->format($format); + + } + + /** + * @return an array of SmartyPluginDescriptor + */ + public function getPluginDescriptors() + { + return array( + new SmartyPluginDescriptor("function", "format_date", $this, "formatDate") + ); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/TheliaHttpKernel.php b/core/lib/Thelia/Core/TheliaHttpKernel.php index 94ab09f1b..7109f5ba2 100755 --- a/core/lib/Thelia/Core/TheliaHttpKernel.php +++ b/core/lib/Thelia/Core/TheliaHttpKernel.php @@ -126,7 +126,7 @@ class TheliaHttpKernel extends HttpKernel if ($lang) { $request->getSession() - ->setLang($lang->getCode()) + ->setLang($lang) ->setLocale($lang->getLocale()) ; } diff --git a/core/lib/Thelia/Model/Lang.php b/core/lib/Thelia/Model/Lang.php index 3339dec64..cb89b53e1 100755 --- a/core/lib/Thelia/Model/Lang.php +++ b/core/lib/Thelia/Model/Lang.php @@ -24,15 +24,33 @@ class Lang extends BaseLang { return $default_lang; } - public function getDateFormat() { + public function getDateFormat() + { return "d/m/Y"; } - public function getTimeFormat() { + public function getTimeFormat() + { return "H:i:s"; } - public function getDateTimeFormat() { + public function getDateTimeFormat() + { return "d/m/Y H:i:s"; } + + public function getDecimalSeparator() + { + return "."; + } + + public function getThousandSeparator() + { + return " "; + } + + public function getDecimals() + { + return 2; + } } diff --git a/core/lib/Thelia/Tests/Core/Template/Smarty/Plugins/FormatTest.php b/core/lib/Thelia/Tests/Core/Template/Smarty/Plugins/FormatTest.php new file mode 100644 index 000000000..439ab7ee0 --- /dev/null +++ b/core/lib/Thelia/Tests/Core/Template/Smarty/Plugins/FormatTest.php @@ -0,0 +1,58 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Tests\Core\Smarty\Plugins; + +use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; +use Thelia\Core\HttpFoundation\Request; +use Thelia\Core\HttpFoundation\Session\Session; +use Thelia\Core\Template\Smarty\Plugins\Format; + +class FormatTest extends \PHPUnit_Framework_TestCase +{ + protected $request; + protected $session; + + public function setUp() + { + $this->session = new Session(new MockArraySessionStorage()); + $this->request = new Request(); + + $this->request->setSession($this->session); + } + + public function testFormatDateWithSpecificFormat() + { + $dateTime = new \DateTime(); + $format = "Y-m-d H:i:s"; + + $formatClass = new Format($this->request); + + $render = $formatClass->formatDate(array( + "date" => $dateTime, + "format" => $format + )); + + $this->assertEquals($dateTime->format($format), $render); + } + +} \ No newline at end of file diff --git a/install/sqldb.map b/install/sqldb.map new file mode 100644 index 000000000..63a93baa8 --- /dev/null +++ b/install/sqldb.map @@ -0,0 +1,2 @@ +# Sqlfile -> Database map +thelia.sql=thelia diff --git a/reset_install.sh b/reset_install.sh index f3a635a9b..5c51ac60c 100755 --- a/reset_install.sh +++ b/reset_install.sh @@ -9,7 +9,7 @@ if [ ! -f local/config/database.yml ]; then echo "[FAILED] Please add your database informations in local/config/database.yml and start this script again." else echo -e "\n\e[01;34m[INFO] Downloading vendors\e[00m\n" - php composer install --prefer-dist --no-dev + composer install cd local/config/ From 92b64db156b10ec830426bfdf940758a7702bf0e Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 2 Sep 2013 23:51:51 +0200 Subject: [PATCH 2/8] complete test for format_date smarty function --- .../Template/Smarty/Plugins/FormatTest.php | 97 ++++++++++++++++++- 1 file changed, 94 insertions(+), 3 deletions(-) diff --git a/core/lib/Thelia/Tests/Core/Template/Smarty/Plugins/FormatTest.php b/core/lib/Thelia/Tests/Core/Template/Smarty/Plugins/FormatTest.php index 439ab7ee0..bce527d41 100644 --- a/core/lib/Thelia/Tests/Core/Template/Smarty/Plugins/FormatTest.php +++ b/core/lib/Thelia/Tests/Core/Template/Smarty/Plugins/FormatTest.php @@ -30,14 +30,12 @@ use Thelia\Core\Template\Smarty\Plugins\Format; class FormatTest extends \PHPUnit_Framework_TestCase { protected $request; - protected $session; public function setUp() { - $this->session = new Session(new MockArraySessionStorage()); $this->request = new Request(); - $this->request->setSession($this->session); + $this->request->setSession(new Session(new MockArraySessionStorage())); } public function testFormatDateWithSpecificFormat() @@ -55,4 +53,97 @@ class FormatTest extends \PHPUnit_Framework_TestCase $this->assertEquals($dateTime->format($format), $render); } + public function testFormatDateWithDefaultSessionParam() + { + $dateTime = new \DateTime(); + + $langMock = $this->getLangMock(); + $this->request->getSession()->setLang($langMock); + + $formatClass = new Format($this->request); + + $render = $formatClass->formatDate(array("date" => $dateTime)); + + $this->assertEquals($dateTime->format("Y-m-d H:i:s"), $render); + } + + public function testFormatDateWithDateSessionParam() + { + $dateTime = new \DateTime(); + + $langMock = $this->getLangMock(); + $this->request->getSession()->setLang($langMock); + + $formatClass = new Format($this->request); + + $render = $formatClass->formatDate(array( + "date" => $dateTime, + "output" => "date" + )); + + $this->assertEquals($dateTime->format("Y-m-d"), $render); + } + + public function testFormatDateWithTimeSessionParam() + { + $dateTime = new \DateTime(); + + $langMock = $this->getLangMock(); + $this->request->getSession()->setLang($langMock); + + $formatClass = new Format($this->request); + + $render = $formatClass->formatDate(array( + "date" => $dateTime, + "output" => "time" + )); + + $this->assertEquals($dateTime->format("H:i:s"), $render); + } + + public function testFormatDateWithDateTimeSessionParam() + { + $dateTime = new \DateTime(); + + $langMock = $this->getLangMock(); + $this->request->getSession()->setLang($langMock); + + $formatClass = new Format($this->request); + + $render = $formatClass->formatDate(array( + "date" => $dateTime, + "output" => "datetime" + )); + + $this->assertEquals($dateTime->format("Y-m-d H:i:s"), $render); + } + + public function getLangMock() + { + $mock = $this->getMock( + "Thelia\Model\Lang", + array( + "getDateFormat", + "getTimeFormat", + "getDateTimeFormat" + ) + ); + + $mock->expects($this->any()) + ->method("getDateFormat") + ->will($this->returnValue("Y-m-d")); + + $mock->expects($this->any()) + ->method("getTimeFormat") + ->will($this->returnValue("H:i:s")); + + $mock->expects($this->any()) + ->method("getDateTimeFormat") + ->will($this->returnValue("Y-m-d H:i:s")); + + return $mock; + } + + + } \ No newline at end of file From 0d261373f8d4ee261ac1acb5c7267a7e8be36ab0 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 3 Sep 2013 00:05:37 +0200 Subject: [PATCH 3/8] add some phpdoc --- .../Core/Template/Smarty/Plugins/Format.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Format.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Format.php index c2fe1652d..ce7ba68c8 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Format.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Format.php @@ -42,10 +42,15 @@ class Format extends AbstractSmartyPlugin } /** - * @param $params - * @param $smarty + * return date in expected format + * + * ex : {format_date date=$dateTimeObject format="Y-m-d H:i:s"} + * + * @param array $params + * @param null $template + * @return string */ - public function formatDate($params, &$smarty = null) + public function formatDate($params, $template = null) { $date = $params["date"]; @@ -82,13 +87,19 @@ class Format extends AbstractSmartyPlugin } + public function formatNumber($params, $template = null) + { + + } + /** * @return an array of SmartyPluginDescriptor */ public function getPluginDescriptors() { return array( - new SmartyPluginDescriptor("function", "format_date", $this, "formatDate") + new SmartyPluginDescriptor("function", "format_date", $this, "formatDate"), + new SmartyPluginDescriptor("function", "format_number", $this, "formatNumber") ); } } \ No newline at end of file From cf53e45ef0af8519bc7b1e64d2b78db7bb4a2c63 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 3 Sep 2013 07:57:14 +0200 Subject: [PATCH 4/8] remove sqlmap file --- install/sqldb.map | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 install/sqldb.map diff --git a/install/sqldb.map b/install/sqldb.map deleted file mode 100644 index 63a93baa8..000000000 --- a/install/sqldb.map +++ /dev/null @@ -1,2 +0,0 @@ -# Sqlfile -> Database map -thelia.sql=thelia From 7718c90e60b16927308b12d687156a77abc8b98f Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 3 Sep 2013 08:34:46 +0200 Subject: [PATCH 5/8] create foramt_number smarty function --- .../Exception/SmartyPluginException.php | 33 ++++++++++++ .../Core/Template/Smarty/Plugins/Format.php | 50 ++++++++++++++++++- core/lib/Thelia/Model/Lang.php | 2 +- 3 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 core/lib/Thelia/Core/Template/Smarty/Exception/SmartyPluginException.php diff --git a/core/lib/Thelia/Core/Template/Smarty/Exception/SmartyPluginException.php b/core/lib/Thelia/Core/Template/Smarty/Exception/SmartyPluginException.php new file mode 100644 index 000000000..fdaf93608 --- /dev/null +++ b/core/lib/Thelia/Core/Template/Smarty/Exception/SmartyPluginException.php @@ -0,0 +1,33 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Template\Smarty\Exception; + + +/** + * Class SmartyPluginException + * @package Thelia\Core\Template\Smarty\Exception + * @author Manuel Raynaud + */ +class SmartyPluginException extends \SmartyException +{} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Format.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Format.php index ce7ba68c8..7404a2a6f 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Format.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Format.php @@ -25,9 +25,13 @@ namespace Thelia\Core\Template\Smarty\Plugins; use Thelia\Core\HttpFoundation\Request; use Thelia\Core\Template\Smarty\AbstractSmartyPlugin; +use Thelia\Core\Template\Smarty\Exception\SmartyPluginException; use Thelia\Core\Template\Smarty\SmartyPluginDescriptor; /** + * + * format_date and format_date smarty function. + * * Class Format * @package Thelia\Core\Template\Smarty\Plugins * @author Manuel Raynaud @@ -44,14 +48,31 @@ class Format extends AbstractSmartyPlugin /** * return date in expected format * - * ex : {format_date date=$dateTimeObject format="Y-m-d H:i:s"} + * available parameters : + * date => DateTime objet (mandatory) + * format => expected format + * output => list of default system format. Values available : + * date => date format + * time => time format + * datetime => datetime format (default) + * + * ex : + * {format_date date=$dateTimeObject format="Y-m-d H:i:s"} will output the format with specific format + * {format_date date=$dateTimeObject output="date"} will output the date using the default date system format + * {format_date date=$dateTimeObject} will output with the default datetime system format * * @param array $params * @param null $template + * @throws \Thelia\Core\Template\Smarty\Exception\SmartyPluginException * @return string */ public function formatDate($params, $template = null) { + + if (array_key_exists("date", $params) === false) { + throw new SmartyPluginException("date is a mandatory parameter in format_date function"); + } + $date = $params["date"]; if(!$date instanceof \DateTime) { @@ -87,9 +108,36 @@ class Format extends AbstractSmartyPlugin } + /** + * + * display numbers in expected format + * + * available parameters : + * number => int or float number + * decimals => how many decimals format expected + * dec_point => separator for the decimal point + * thousands_sep => thousands separator + * + * + * @param $params + * @param null $template + * @throws \Thelia\Core\Template\Smarty\Exception\SmartyPluginException + * @return string the expected number formatted + */ public function formatNumber($params, $template = null) { + if (array_key_exists("number", $params) === false) { + throw new SmartyPluginException("number is a mandatory parameter in format_number function"); + } + $lang = $this->request->getSession()->getLang(); + + $number = $params["number"]; + $decimals = array_key_exists("decimals", $params) ? $params["decimals"] : $lang->getDecimals(); + $decPoint = array_key_exists("dec_point", $params) ? $params["dec_point"] : $lang->getDecimalSeparator(); + $thousandsSep = array_key_exists("thousands_sep", $params) ? $params["thousands_sep"] : $lang->getThousandsSeparator(); + + return number_format($number, $decimals, $decPoint, $thousandsSep); } /** diff --git a/core/lib/Thelia/Model/Lang.php b/core/lib/Thelia/Model/Lang.php index cb89b53e1..654c89719 100755 --- a/core/lib/Thelia/Model/Lang.php +++ b/core/lib/Thelia/Model/Lang.php @@ -44,7 +44,7 @@ class Lang extends BaseLang { return "."; } - public function getThousandSeparator() + public function getThousandsSeparator() { return " "; } From 1f50158398a38975e9285b4a77556d9420b78db1 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 3 Sep 2013 08:43:00 +0200 Subject: [PATCH 6/8] test foramt_date without datetime object --- .../Template/Smarty/Plugins/FormatTest.php | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/core/lib/Thelia/Tests/Core/Template/Smarty/Plugins/FormatTest.php b/core/lib/Thelia/Tests/Core/Template/Smarty/Plugins/FormatTest.php index bce527d41..210e02f43 100644 --- a/core/lib/Thelia/Tests/Core/Template/Smarty/Plugins/FormatTest.php +++ b/core/lib/Thelia/Tests/Core/Template/Smarty/Plugins/FormatTest.php @@ -27,6 +27,9 @@ use Thelia\Core\HttpFoundation\Request; use Thelia\Core\HttpFoundation\Session\Session; use Thelia\Core\Template\Smarty\Plugins\Format; +/** + * @coversDefaultClass \Thelia\Core\Template\Smarty\Plugins\Format + */ class FormatTest extends \PHPUnit_Framework_TestCase { protected $request; @@ -38,6 +41,12 @@ class FormatTest extends \PHPUnit_Framework_TestCase $this->request->setSession(new Session(new MockArraySessionStorage())); } + /** + * + * test formatDate method with expected format + * + * @covers ::formatDate + */ public function testFormatDateWithSpecificFormat() { $dateTime = new \DateTime(); @@ -53,6 +62,12 @@ class FormatTest extends \PHPUnit_Framework_TestCase $this->assertEquals($dateTime->format($format), $render); } + /** + * + * test formatDate method with date default format + * + * @covers ::formatDate + */ public function testFormatDateWithDefaultSessionParam() { $dateTime = new \DateTime(); @@ -67,6 +82,12 @@ class FormatTest extends \PHPUnit_Framework_TestCase $this->assertEquals($dateTime->format("Y-m-d H:i:s"), $render); } + /** + * + * test formatDate method with time default format + * + * @covers ::formatDate + */ public function testFormatDateWithDateSessionParam() { $dateTime = new \DateTime(); @@ -84,6 +105,12 @@ class FormatTest extends \PHPUnit_Framework_TestCase $this->assertEquals($dateTime->format("Y-m-d"), $render); } + /** + * + * test formatDate method with datetime default format + * + * @covers ::formatDate + */ public function testFormatDateWithTimeSessionParam() { $dateTime = new \DateTime(); @@ -101,6 +128,12 @@ class FormatTest extends \PHPUnit_Framework_TestCase $this->assertEquals($dateTime->format("H:i:s"), $render); } + /** + * + * test formatDate method without output or expected format. datetime format must be return + * + * @covers ::formatDate + */ public function testFormatDateWithDateTimeSessionParam() { $dateTime = new \DateTime(); @@ -118,6 +151,25 @@ class FormatTest extends \PHPUnit_Framework_TestCase $this->assertEquals($dateTime->format("Y-m-d H:i:s"), $render); } + /** + * @covers ::formatDate + * @expectedException \Thelia\Core\Template\Smarty\Exception\SmartyPluginException + */ + public function testFormatDateWithoutDate() + { + $dateTime = new \DateTime(); + + $formatClass = new Format($this->request); + + $render = $formatClass->formatDate(array()); + + $this->assertEquals($dateTime->format("Y-m-d H:i:s"), $render); + } + + /** + * create a mock for Thelia\Model\Lang class + * @return \Thelia\Model\Lang instance + */ public function getLangMock() { $mock = $this->getMock( From 29dc067076efc5ba46af042d5f0c5304eec05319 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 3 Sep 2013 09:06:02 +0200 Subject: [PATCH 7/8] complete test for foramt_number smarty function --- .../Core/Template/Smarty/Plugins/Format.php | 1 + .../Template/Smarty/Plugins/FormatTest.php | 75 ++++++++++++++++++- 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Format.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Format.php index 7404a2a6f..d4b6c246f 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Format.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Format.php @@ -118,6 +118,7 @@ class Format extends AbstractSmartyPlugin * dec_point => separator for the decimal point * thousands_sep => thousands separator * + * ex : {format_number number="1246.12" decimals="1" dec_point="," thousands_sep=" "} will output "1 246,1" * * @param $params * @param null $template diff --git a/core/lib/Thelia/Tests/Core/Template/Smarty/Plugins/FormatTest.php b/core/lib/Thelia/Tests/Core/Template/Smarty/Plugins/FormatTest.php index 210e02f43..38c00b55f 100644 --- a/core/lib/Thelia/Tests/Core/Template/Smarty/Plugins/FormatTest.php +++ b/core/lib/Thelia/Tests/Core/Template/Smarty/Plugins/FormatTest.php @@ -152,6 +152,8 @@ class FormatTest extends \PHPUnit_Framework_TestCase } /** + * test formatDate without mandatory parameters + * * @covers ::formatDate * @expectedException \Thelia\Core\Template\Smarty\Exception\SmartyPluginException */ @@ -166,6 +168,62 @@ class FormatTest extends \PHPUnit_Framework_TestCase $this->assertEquals($dateTime->format("Y-m-d H:i:s"), $render); } + + /** + * test formatNumber without mandatory parameters + * + * @covers ::formatNumber + * @expectedException \Thelia\Core\Template\Smarty\Exception\SmartyPluginException + */ + public function testFormatNumberWithoutParams() + { + $formatClass = new Format($this->request); + + $render = $formatClass->formatNumber(array()); + } + + /** + * test formatDate specifying all parameters + * + * @covers ::formatNumber + */ + public function testFormatNumberWithAllParams() + { + $formatClass = new Format($this->request); + + $number = 1256.12; + $decimals = 1; + $decPoint = ","; + $thousandsSep = " "; + + $render = $formatClass->formatNumber(array( + "number" => $number, + "decimals" => $decimals, + "dec_point" => $decPoint, + "thousands_sep" => $thousandsSep + )); + + $this->assertEquals($render, "1 256,1"); + } + + /** + * @covers ::formatNumber + */ + public function testFormatNumberWithDefaultParameters() + { + $number = 1234.56; + $langMock = $this->getLangMock(); + $this->request->getSession()->setLang($langMock); + + $formatClass = new Format($this->request); + + $render = $formatClass->formatNumber(array( + "number" => $number + )); + + $this->assertEquals( $render, number_format($number, 2, ",", " ")); + } + /** * create a mock for Thelia\Model\Lang class * @return \Thelia\Model\Lang instance @@ -177,7 +235,10 @@ class FormatTest extends \PHPUnit_Framework_TestCase array( "getDateFormat", "getTimeFormat", - "getDateTimeFormat" + "getDateTimeFormat", + "getDecimalSeparator", + "getThousandsSeparator", + "getDecimals" ) ); @@ -193,6 +254,18 @@ class FormatTest extends \PHPUnit_Framework_TestCase ->method("getDateTimeFormat") ->will($this->returnValue("Y-m-d H:i:s")); + $mock->expects($this->any()) + ->method("getDecimals") + ->will($this->returnValue(2)); + + $mock->expects($this->any()) + ->method("getDecimalSeparator") + ->will($this->returnValue(",")); + + $mock->expects($this->any()) + ->method("getThousandsSeparator") + ->will($this->returnValue(" ")); + return $mock; } From dce816d77cbcd84b697dbb98810d0c626b991d96 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 3 Sep 2013 09:22:12 +0200 Subject: [PATCH 8/8] fix typo in phpdoc --- core/lib/Thelia/Core/Template/Smarty/Plugins/Format.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Format.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Format.php index d4b6c246f..a095f214a 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Format.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Format.php @@ -49,7 +49,7 @@ class Format extends AbstractSmartyPlugin * return date in expected format * * available parameters : - * date => DateTime objet (mandatory) + * date => DateTime object (mandatory) * format => expected format * output => list of default system format. Values available : * date => date format