You are here

public function ChoiceFormFieldTest::testSelects in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/dom-crawler/Tests/Field/ChoiceFormFieldTest.php \Symfony\Component\DomCrawler\Tests\Field\ChoiceFormFieldTest::testSelects()

File

vendor/symfony/dom-crawler/Tests/Field/ChoiceFormFieldTest.php, line 83

Class

ChoiceFormFieldTest

Namespace

Symfony\Component\DomCrawler\Tests\Field

Code

public function testSelects() {
  $node = $this
    ->createSelectNode(array(
    'foo' => false,
    'bar' => false,
  ));
  $field = new ChoiceFormField($node);
  $this
    ->assertTrue($field
    ->hasValue(), '->hasValue() returns true for selects');
  $this
    ->assertEquals('foo', $field
    ->getValue(), '->getValue() returns the first option if none are selected');
  $this
    ->assertFalse($field
    ->isMultiple(), '->isMultiple() returns false when no multiple attribute is defined');
  $node = $this
    ->createSelectNode(array(
    'foo' => false,
    'bar' => true,
  ));
  $field = new ChoiceFormField($node);
  $this
    ->assertEquals('bar', $field
    ->getValue(), '->getValue() returns the selected option');
  $field
    ->setValue('foo');
  $this
    ->assertEquals('foo', $field
    ->getValue(), '->setValue() changes the selected option');
  try {
    $field
      ->setValue('foobar');
    $this
      ->fail('->setValue() throws an \\InvalidArgumentException if the value is not one of the selected options');
  } catch (\InvalidArgumentException $e) {
    $this
      ->assertTrue(true, '->setValue() throws an \\InvalidArgumentException if the value is not one of the selected options');
  }
  try {
    $field
      ->setValue(array(
      'foobar',
    ));
    $this
      ->fail('->setValue() throws an \\InvalidArgumentException if the value is an array');
  } catch (\InvalidArgumentException $e) {
    $this
      ->assertTrue(true, '->setValue() throws an \\InvalidArgumentException if the value is an array');
  }
}