InputFormFieldTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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\InputFormField;
  12. class InputFormFieldTest extends FormFieldTestCase
  13. {
  14. public function testInitialize()
  15. {
  16. $node = $this->createNode('input', '', ['type' => 'text', 'name' => 'name', 'value' => 'value']);
  17. $field = new InputFormField($node);
  18. $this->assertEquals('value', $field->getValue(), '->initialize() sets the value of the field to the value attribute value');
  19. $node = $this->createNode('textarea', '');
  20. try {
  21. $field = new InputFormField($node);
  22. $this->fail('->initialize() throws a \LogicException if the node is not an input');
  23. } catch (\LogicException $e) {
  24. $this->assertTrue(true, '->initialize() throws a \LogicException if the node is not an input');
  25. }
  26. $node = $this->createNode('input', '', ['type' => 'checkbox']);
  27. try {
  28. $field = new InputFormField($node);
  29. $this->fail('->initialize() throws a \LogicException if the node is a checkbox');
  30. } catch (\LogicException $e) {
  31. $this->assertTrue(true, '->initialize() throws a \LogicException if the node is a checkbox');
  32. }
  33. $node = $this->createNode('input', '', ['type' => 'file']);
  34. try {
  35. $field = new InputFormField($node);
  36. $this->fail('->initialize() throws a \LogicException if the node is a file');
  37. } catch (\LogicException $e) {
  38. $this->assertTrue(true, '->initialize() throws a \LogicException if the node is a file');
  39. }
  40. }
  41. }