Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Xxx\Component\HttpFoundation\Tests\Unit;
- use Xxx\Component\HttpFoundation\JsonFormResponse;
- use Xxx\Tests\Component\HttpFoundation\Form\TestFormType;
- use Symfony\Component\Form\FormError;
- use Symfony\Component\Form\Test\TypeTestCase;
- class JsonFormResponseTest extends TypeTestCase
- {
- public function test_it_should_return_empty_error_array()
- {
- $formData = [
- 'fieldOne' => 'test',
- 'fieldTwo' => 'test2',
- ];
- $errors = json_encode([
- 'test_form' => []
- ]);
- $form = $this->factory->create(new TestFormType(), $formData);
- $response = new JsonFormResponse($form);
- $this->assertEquals($errors, $response->getContent());
- }
- public function test_it_should_return_parent_form_error()
- {
- $formData = [
- 'fieldOne' => 'test',
- 'fieldTwo' => 'test2',
- ];
- $errors = json_encode([
- 'test_form' => [
- 'errors' => [ 'Error in parent form' ]
- ]
- ]);
- $form = $this->factory->create(new TestFormType(), $formData);
- $form->addError(new FormError("Error in parent form"));
- $response = new JsonFormResponse($form);
- $this->assertEquals($errors, $response->getContent());
- }
- public function test_it_should_return_child_form_error()
- {
- $formData = [
- 'fieldOne' => 'test',
- 'fieldTwo' => 'test2',
- ];
- $errors = json_encode([
- 'test_form' => [
- 'fieldOne' => [
- 'errors' => [ 'Error in child form' ]
- ]
- ]
- ]);
- $form = $this->factory->create(new TestFormType(), $formData);
- $form->get('fieldOne')->addError(new FormError("Error in child form"));
- $response = new JsonFormResponse($form);
- $this->assertEquals($errors, $response->getContent());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement