4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Form\Tests\Extension\Core\Type
;
14 use Symfony\Component\Intl\Util\IntlTestHelper
;
16 class NumberTypeTest
extends TypeTestCase
18 protected function setUp()
22 // we test against "de_DE", so we need the full implementation
23 IntlTestHelper
::requireFullIntl($this);
25 \Locale
::setDefault('de_DE');
28 public function testDefaultFormatting()
30 $form = $this->factory
->create('number');
31 $form->setData('12345.67890');
32 $view = $form->createView();
34 $this->assertSame('12345,679', $view->vars
['value']);
37 public function testDefaultFormattingWithGrouping()
39 $form = $this->factory
->create('number', null, array('grouping' => true));
40 $form->setData('12345.67890');
41 $view = $form->createView();
43 $this->assertSame('12.345,679', $view->vars
['value']);
46 public function testDefaultFormattingWithPrecision()
48 $form = $this->factory
->create('number', null, array('precision' => 2));
49 $form->setData('12345.67890');
50 $view = $form->createView();
52 $this->assertSame('12345,68', $view->vars
['value']);
55 public function testDefaultFormattingWithRounding()
57 $form = $this->factory
->create('number', null, array('precision' => 0, 'rounding_mode' => \NumberFormatter
::ROUND_UP
));
58 $form->setData('12345.54321');
59 $view = $form->createView();
61 $this->assertSame('12346', $view->vars
['value']);