InputFormFieldTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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\DomCrawler\Field;
  11. require_once __DIR__.'/FormFieldTestCase.php';
  12. use Symfony\Component\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. $field = new InputFormField($node);
  23. $this->fail('->initialize() throws a \LogicException if the node is not an input');
  24. } catch (\LogicException $e) {
  25. $this->assertTrue(true, '->initialize() throws a \LogicException if the node is not an input');
  26. }
  27. $node = $this->createNode('input', '', array('type' => 'checkbox'));
  28. try {
  29. $field = new InputFormField($node);
  30. $this->fail('->initialize() throws a \LogicException if the node is a checkbox');
  31. } catch (\LogicException $e) {
  32. $this->assertTrue(true, '->initialize() throws a \LogicException if the node is a checkbox');
  33. }
  34. $node = $this->createNode('input', '', array('type' => 'file'));
  35. try {
  36. $field = new InputFormField($node);
  37. $this->fail('->initialize() throws a \LogicException if the node is a file');
  38. } catch (\LogicException $e) {
  39. $this->assertTrue(true, '->initialize() throws a \LogicException if the node is a file');
  40. }
  41. }
  42. }