FormContextTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.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. require_once __DIR__ . '/Fixtures/TestField.php';
  13. use Symfony\Component\Form\FormContext;
  14. use Symfony\Component\Form\CsrfProvider\DefaultCsrfProvider;
  15. class FormContextTest extends \PHPUnit_Framework_TestCase
  16. {
  17. protected $validator;
  18. protected function setUp()
  19. {
  20. $this->validator = $this->getMock('Symfony\Component\Validator\ValidatorInterface');
  21. }
  22. public function testBuildDefaultWithCsrfProtection()
  23. {
  24. $context = FormContext::buildDefault($this->validator, 'secret');
  25. $expected = array(
  26. 'validator' => $this->validator,
  27. 'csrf_provider' => new DefaultCsrfProvider('secret'),
  28. 'context' => $context,
  29. );
  30. $this->assertEquals($expected, $context->getOptions());
  31. }
  32. public function testBuildDefaultWithoutCsrfProtection()
  33. {
  34. $context = FormContext::buildDefault($this->validator, null, false);
  35. $expected = array(
  36. 'validator' => $this->validator,
  37. 'context' => $context,
  38. );
  39. $this->assertEquals($expected, $context->getOptions());
  40. }
  41. /**
  42. * @expectedException Symfony\Component\Form\Exception\FormException
  43. */
  44. public function testBuildDefaultWithoutCsrfSecretThrowsException()
  45. {
  46. FormContext::buildDefault($this->validator, null, true);
  47. }
  48. }