TextareaFormFieldTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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\Component\DomCrawler\Tests\Field;
  11. use Symfony\Component\DomCrawler\Field\TextareaFormField;
  12. class TextareaFormFieldTest extends FormFieldTestCase
  13. {
  14. public function testInitialize()
  15. {
  16. $node = $this->createNode('textarea', 'foo bar');
  17. $field = new TextareaFormField($node);
  18. $this->assertEquals('foo bar', $field->getValue(), '->initialize() sets the value of the field to the textarea node value');
  19. $node = $this->createNode('input', '');
  20. try {
  21. $field = new TextareaFormField($node);
  22. $this->fail('->initialize() throws a \LogicException if the node is not a textarea');
  23. } catch (\LogicException $e) {
  24. $this->assertTrue(true, '->initialize() throws a \LogicException if the node is not a textarea');
  25. }
  26. // Ensure that valid HTML can be used on a textarea.
  27. $node = $this->createNode('textarea', 'foo bar <h1>Baz</h1>');
  28. $field = new TextareaFormField($node);
  29. $this->assertEquals('foo bar <h1>Baz</h1>', $field->getValue(), '->initialize() sets the value of the field to the textarea node value');
  30. // Ensure that we don't do any DOM manipulation/validation by passing in
  31. // "invalid" HTML.
  32. $node = $this->createNode('textarea', 'foo bar <h1>Baz</h2>');
  33. $field = new TextareaFormField($node);
  34. $this->assertEquals('foo bar <h1>Baz</h2>', $field->getValue(), '->initialize() sets the value of the field to the textarea node value');
  35. }
  36. }