FormContextTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Tests\Component\Form;
  11. require_once __DIR__ . '/Fixtures/Author.php';
  12. use Symfony\Component\Form\FormContext;
  13. use Symfony\Component\Form\CsrfProvider\DefaultCsrfProvider;
  14. class FormContextTest extends \PHPUnit_Framework_TestCase
  15. {
  16. protected $validator;
  17. protected function setUp()
  18. {
  19. $this->validator = $this->getMock('Symfony\Component\Validator\ValidatorInterface');
  20. }
  21. public function testBuildDefaultWithCsrfProtection()
  22. {
  23. $context = FormContext::buildDefault($this->validator, 'secret');
  24. $expected = array(
  25. 'validator' => $this->validator,
  26. 'csrf_provider' => new DefaultCsrfProvider('secret'),
  27. 'context' => $context,
  28. );
  29. $this->assertEquals($expected, $context->getOptions());
  30. }
  31. public function testBuildDefaultWithoutCsrfProtection()
  32. {
  33. $context = FormContext::buildDefault($this->validator, null, false);
  34. $expected = array(
  35. 'validator' => $this->validator,
  36. 'context' => $context,
  37. );
  38. $this->assertEquals($expected, $context->getOptions());
  39. }
  40. /**
  41. * @expectedException Symfony\Component\Form\Exception\FormException
  42. */
  43. public function testBuildDefaultWithoutCsrfSecretThrowsException()
  44. {
  45. FormContext::buildDefault($this->validator, null, true);
  46. }
  47. }