complete test for foramt_number smarty function
This commit is contained in:
@@ -118,6 +118,7 @@ class Format extends AbstractSmartyPlugin
|
|||||||
* dec_point => separator for the decimal point
|
* dec_point => separator for the decimal point
|
||||||
* thousands_sep => thousands separator
|
* thousands_sep => thousands separator
|
||||||
*
|
*
|
||||||
|
* ex : {format_number number="1246.12" decimals="1" dec_point="," thousands_sep=" "} will output "1 246,1"
|
||||||
*
|
*
|
||||||
* @param $params
|
* @param $params
|
||||||
* @param null $template
|
* @param null $template
|
||||||
|
|||||||
@@ -152,6 +152,8 @@ class FormatTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* test formatDate without mandatory parameters
|
||||||
|
*
|
||||||
* @covers ::formatDate
|
* @covers ::formatDate
|
||||||
* @expectedException \Thelia\Core\Template\Smarty\Exception\SmartyPluginException
|
* @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);
|
$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
|
* create a mock for Thelia\Model\Lang class
|
||||||
* @return \Thelia\Model\Lang instance
|
* @return \Thelia\Model\Lang instance
|
||||||
@@ -177,7 +235,10 @@ class FormatTest extends \PHPUnit_Framework_TestCase
|
|||||||
array(
|
array(
|
||||||
"getDateFormat",
|
"getDateFormat",
|
||||||
"getTimeFormat",
|
"getTimeFormat",
|
||||||
"getDateTimeFormat"
|
"getDateTimeFormat",
|
||||||
|
"getDecimalSeparator",
|
||||||
|
"getThousandsSeparator",
|
||||||
|
"getDecimals"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -193,6 +254,18 @@ class FormatTest extends \PHPUnit_Framework_TestCase
|
|||||||
->method("getDateTimeFormat")
|
->method("getDateTimeFormat")
|
||||||
->will($this->returnValue("Y-m-d H:i:s"));
|
->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;
|
return $mock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user