InputFormFieldTest.php 1.8 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\Components\DomCrawler\Field;
  11. require_once __DIR__.'/FormFieldTestCase.php';
  12. use Symfony\Components\DomCrawler\Field\InputFormField;
  13. class InputFormFieldTest extends FormFieldTestCase
  14. {
  15. public function testInitialize()
  16. {
  17. $node = $this->createNode('input', '', array('type' => 'text', 'name' => 'name', 'value' => 'value'));
  18. $field = new InputFormField($node);
  19. $this->assertEquals('value', $field->getValue(), '->initialize() sets the value of the field to the value attribute value');
  20. $node = $this->createNode('textarea', '');
  21. try
  22. {
  23. $field = new InputFormField($node);
  24. $this->fail('->initialize() throws a \LogicException if the node is not an input');
  25. }
  26. catch (\LogicException $e)
  27. {
  28. $this->assertTrue(true, '->initialize() throws a \LogicException if the node is not an input');
  29. }
  30. $node = $this->createNode('input', '', array('type' => 'checkbox'));
  31. try
  32. {
  33. $field = new InputFormField($node);
  34. $this->fail('->initialize() throws a \LogicException if the node is a checkbox');
  35. }
  36. catch (\LogicException $e)
  37. {
  38. $this->assertTrue(true, '->initialize() throws a \LogicException if the node is a checkbox');
  39. }
  40. $node = $this->createNode('input', '', array('type' => 'file'));
  41. try
  42. {
  43. $field = new InputFormField($node);
  44. $this->fail('->initialize() throws a \LogicException if the node is a file');
  45. }
  46. catch (\LogicException $e)
  47. {
  48. $this->assertTrue(true, '->initialize() throws a \LogicException if the node is a file');
  49. }
  50. }
  51. }