Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Xxx\Component\HttpFoundation\Tests\Unit;
  4.  
  5. use Xxx\Component\HttpFoundation\JsonFormResponse;
  6. use Xxx\Tests\Component\HttpFoundation\Form\TestFormType;
  7. use Symfony\Component\Form\FormError;
  8. use Symfony\Component\Form\Test\TypeTestCase;
  9.  
  10. class JsonFormResponseTest extends TypeTestCase
  11. {
  12. public function test_it_should_return_empty_error_array()
  13. {
  14. $formData = [
  15. 'fieldOne' => 'test',
  16. 'fieldTwo' => 'test2',
  17. ];
  18.  
  19. $errors = json_encode([
  20. 'test_form' => []
  21. ]);
  22.  
  23. $form = $this->factory->create(new TestFormType(), $formData);
  24.  
  25. $response = new JsonFormResponse($form);
  26.  
  27. $this->assertEquals($errors, $response->getContent());
  28. }
  29.  
  30. public function test_it_should_return_parent_form_error()
  31. {
  32. $formData = [
  33. 'fieldOne' => 'test',
  34. 'fieldTwo' => 'test2',
  35. ];
  36.  
  37. $errors = json_encode([
  38. 'test_form' => [
  39. 'errors' => [ 'Error in parent form' ]
  40. ]
  41. ]);
  42.  
  43. $form = $this->factory->create(new TestFormType(), $formData);
  44. $form->addError(new FormError("Error in parent form"));
  45.  
  46. $response = new JsonFormResponse($form);
  47.  
  48. $this->assertEquals($errors, $response->getContent());
  49. }
  50.  
  51. public function test_it_should_return_child_form_error()
  52. {
  53. $formData = [
  54. 'fieldOne' => 'test',
  55. 'fieldTwo' => 'test2',
  56. ];
  57.  
  58. $errors = json_encode([
  59. 'test_form' => [
  60. 'fieldOne' => [
  61. 'errors' => [ 'Error in child form' ]
  62. ]
  63. ]
  64. ]);
  65.  
  66. $form = $this->factory->create(new TestFormType(), $formData);
  67. $form->get('fieldOne')->addError(new FormError("Error in child form"));
  68.  
  69. $response = new JsonFormResponse($form);
  70.  
  71. $this->assertEquals($errors, $response->getContent());
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement