|
11 | 11 |
|
12 | 12 | namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
13 | 13 |
|
| 14 | +use Symfony\Component\Form\Exception\TransformationFailedException; |
14 | 15 | use Symfony\Component\Form\Extension\Core\Type\MoneyType;
|
15 | 16 | use Symfony\Component\Intl\Util\IntlTestHelper;
|
16 | 17 |
|
@@ -146,4 +147,54 @@ public function testIntegerInputWithoutDivisor()
|
146 | 147 |
|
147 | 148 | $this->assertSame(1234567, $form->getData());
|
148 | 149 | }
|
| 150 | + |
| 151 | + public function testDefaultFormattingWithScaleAndStringInput() |
| 152 | + { |
| 153 | + $form = $this->factory->create(static::TESTED_TYPE, null, ['scale' => 2, 'input' => 'string']); |
| 154 | + $form->setData('12345.67890'); |
| 155 | + |
| 156 | + $this->assertSame('12345.68', $form->createView()->vars['value']); |
| 157 | + } |
| 158 | + |
| 159 | + public function testStringInputWithFloatData() |
| 160 | + { |
| 161 | + $this->expectException(TransformationFailedException::class); |
| 162 | + $this->expectExceptionMessage('Expected a numeric string.'); |
| 163 | + |
| 164 | + $this->factory->create(static::TESTED_TYPE, 12345.6789, [ |
| 165 | + 'input' => 'string', |
| 166 | + 'scale' => 2, |
| 167 | + ]); |
| 168 | + } |
| 169 | + |
| 170 | + public function testStringInputWithIntData() |
| 171 | + { |
| 172 | + $this->expectException(TransformationFailedException::class); |
| 173 | + $this->expectExceptionMessage('Expected a numeric string.'); |
| 174 | + |
| 175 | + $this->factory->create(static::TESTED_TYPE, 12345, [ |
| 176 | + 'input' => 'string', |
| 177 | + 'scale' => 2, |
| 178 | + ]); |
| 179 | + } |
| 180 | + |
| 181 | + public function testSubmitStringInputWithDefaultScale() |
| 182 | + { |
| 183 | + $form = $this->factory->create(static::TESTED_TYPE, null, ['input' => 'string']); |
| 184 | + $form->submit('1.234'); |
| 185 | + |
| 186 | + $this->assertSame('1.23', $form->getData()); |
| 187 | + $this->assertSame(1.23, $form->getNormData()); |
| 188 | + $this->assertSame('1.23', $form->getViewData()); |
| 189 | + } |
| 190 | + |
| 191 | + public function testSubmitStringInputWithScale() |
| 192 | + { |
| 193 | + $form = $this->factory->create(static::TESTED_TYPE, null, ['input' => 'string', 'scale' => 3]); |
| 194 | + $form->submit('1.234'); |
| 195 | + |
| 196 | + $this->assertSame('1.234', $form->getData()); |
| 197 | + $this->assertSame(1.234, $form->getNormData()); |
| 198 | + $this->assertSame('1.234', $form->getViewData()); |
| 199 | + } |
149 | 200 | }
|
0 commit comments