2010-06-24 09:40:05 +01:00
|
|
|
<?php
|
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
namespace Symfony\Tests\Component\Form;
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:39:05 +01:00
|
|
|
require_once __DIR__ . '/LocalizedTestCase.php';
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
use Symfony\Component\Form\NumberField;
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:39:05 +01:00
|
|
|
class NumberFieldTest extends LocalizedTestCase
|
2010-06-24 09:40:05 +01:00
|
|
|
{
|
2010-06-24 10:24:08 +01:00
|
|
|
public function testRender()
|
|
|
|
{
|
|
|
|
$field = new NumberField('name');
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
$field->setLocale('de_AT');
|
|
|
|
$field->setData(1234.5678);
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
$html = '<input id="name" name="name" value="1234,568" type="text" class="foobar" />';
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
$this->assertEquals($html, $field->render(array('class' => 'foobar')));
|
|
|
|
}
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
public function testRenderWithPrecision()
|
|
|
|
{
|
|
|
|
$field = new NumberField('name', array('precision' => 4));
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
$field->setLocale('de_AT');
|
|
|
|
$field->setData(1234.5678);
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
$html = '<input id="name" name="name" value="1234,5678" type="text" />';
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
$this->assertEquals($html, $field->render());
|
|
|
|
}
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
public function testRenderWithGrouping()
|
|
|
|
{
|
|
|
|
$field = new NumberField('name', array('grouping' => true));
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
$field->setLocale('de_AT');
|
|
|
|
$field->setData(1234.5678);
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
$html = '<input id="name" name="name" value="1.234,568" type="text" />';
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
$this->assertEquals($html, $field->render());
|
|
|
|
}
|
2010-06-24 09:40:05 +01:00
|
|
|
}
|