|
18 | 18 | use Symfony\Component\Form\Exception\TransformationFailedException;
|
19 | 19 | use Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper;
|
20 | 20 | use Symfony\Component\Form\Extension\Validator\ViolationMapper\ViolationMapper;
|
| 21 | +use Symfony\Component\Form\FileUploadError; |
21 | 22 | use Symfony\Component\Form\Form;
|
22 | 23 | use Symfony\Component\Form\FormConfigBuilder;
|
23 | 24 | use Symfony\Component\Form\FormError;
|
24 | 25 | use Symfony\Component\Form\FormInterface;
|
25 | 26 | use Symfony\Component\Form\Tests\Extension\Validator\ViolationMapper\Fixtures\Issue;
|
26 | 27 | use Symfony\Component\PropertyAccess\PropertyPath;
|
| 28 | +use Symfony\Component\Validator\Constraints\File; |
27 | 29 | use Symfony\Component\Validator\ConstraintViolation;
|
28 | 30 | use Symfony\Component\Validator\ConstraintViolationInterface;
|
29 | 31 |
|
@@ -1590,4 +1592,53 @@ public function testBacktrackIfSeveralSubFormsWithSamePropertyPath()
|
1590 | 1592 | $this->assertEquals([$this->getFormError($violation2, $grandChild2)], iterator_to_array($grandChild2->getErrors()), $grandChild2->getName().' should have an error, but has none');
|
1591 | 1593 | $this->assertEquals([$this->getFormError($violation3, $grandChild3)], iterator_to_array($grandChild3->getErrors()), $grandChild3->getName().' should have an error, but has none');
|
1592 | 1594 | }
|
| 1595 | + |
| 1596 | + public function testFileUploadErrorIsNotRemovedIfNoFileSizeConstraintViolationWasRaised() |
| 1597 | + { |
| 1598 | + $form = $this->getForm('form'); |
| 1599 | + $form->addError(new FileUploadError( |
| 1600 | + 'The file is too large. Allowed maximum size is 2 MB.', |
| 1601 | + 'The file is too large. Allowed maximum size is {{ limit }} {{ suffix }}.', |
| 1602 | + [ |
| 1603 | + '{{ limit }}' => '2', |
| 1604 | + '{{ suffix }}' => 'MB', |
| 1605 | + ] |
| 1606 | + )); |
| 1607 | + |
| 1608 | + $this->mapper->mapViolation($this->getConstraintViolation('data'), $form); |
| 1609 | + |
| 1610 | + $this->assertCount(2, $form->getErrors()); |
| 1611 | + } |
| 1612 | + |
| 1613 | + public function testFileUploadErrorIsRemovedIfFileSizeConstraintViolationWasRaised() |
| 1614 | + { |
| 1615 | + $form = $this->getForm('form'); |
| 1616 | + $form->addError(new FileUploadError( |
| 1617 | + 'The file is too large. Allowed maximum size is 2 MB.', |
| 1618 | + 'The file is too large. Allowed maximum size is {{ limit }} {{ suffix }}.', |
| 1619 | + [ |
| 1620 | + '{{ limit }}' => '2', |
| 1621 | + '{{ suffix }}' => 'MB', |
| 1622 | + ] |
| 1623 | + )); |
| 1624 | + |
| 1625 | + $violation = new ConstraintViolation( |
| 1626 | + 'The file is too large (3 MB). Allowed maximum size is 2 MB.', |
| 1627 | + 'The file is too large ({{ size }} {{ suffix }}). Allowed maximum size is {{ limit }} {{ suffix }}.', |
| 1628 | + [ |
| 1629 | + '{{ limit }}' => '2', |
| 1630 | + '{{ size }}' => '3', |
| 1631 | + '{{ suffix }}' => 'MB', |
| 1632 | + ], |
| 1633 | + 'data', |
| 1634 | + '', |
| 1635 | + null, |
| 1636 | + null, |
| 1637 | + File::TOO_LARGE_ERROR |
| 1638 | + ); |
| 1639 | + $this->mapper->mapViolation($this->getConstraintViolation('data'), $form); |
| 1640 | + $this->mapper->mapViolation($violation, $form); |
| 1641 | + |
| 1642 | + $this->assertCount(2, $form->getErrors()); |
| 1643 | + } |
1593 | 1644 | }
|
0 commit comments