2010-06-24 09:40:05 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Symfony\Tests\Components\Form;
|
|
|
|
|
2010-06-24 10:39:05 +01:00
|
|
|
require_once __DIR__ . '/LocalizedTestCase.php';
|
2010-06-24 09:40:05 +01:00
|
|
|
|
|
|
|
use Symfony\Components\Form\PercentField;
|
|
|
|
|
2010-06-24 10:39:05 +01:00
|
|
|
class PercentFieldTest extends LocalizedTestCase
|
2010-06-24 09:40:05 +01:00
|
|
|
{
|
2010-06-24 10:24:08 +01:00
|
|
|
public function testRender()
|
|
|
|
{
|
|
|
|
$field = new PercentField('name');
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
$field->setLocale('de_DE');
|
|
|
|
$field->setData(0.12);
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
$html = '<input id="name" name="name" value="12" 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 testRenderWithPrecision()
|
|
|
|
{
|
|
|
|
$field = new PercentField('name', array('precision' => 2));
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
$field->setLocale('de_DE');
|
|
|
|
$field->setData(0.1234);
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
$html = '<input id="name" name="name" value="12,34" 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 testRenderWithInteger()
|
|
|
|
{
|
|
|
|
$field = new PercentField('name', array('type' => 'integer'));
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
$field->setLocale('de_DE');
|
|
|
|
$field->setData(123);
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
$html = '<input id="name" name="name" value="123" 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
|
|
|
}
|