You are here

public function ChoiceFormFieldTest::testMultipleSelects 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::testMultipleSelects()

File

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

Class

ChoiceFormFieldTest

Namespace

Symfony\Component\DomCrawler\Tests\Field

Code

public function testMultipleSelects() {
  $node = $this
    ->createSelectNode(array(
    'foo' => false,
    'bar' => false,
  ), array(
    'multiple' => 'multiple',
  ));
  $field = new ChoiceFormField($node);
  $this
    ->assertEquals(array(), $field
    ->getValue(), '->setValue() returns an empty array if multiple is true and no option is selected');
  $field
    ->setValue('foo');
  $this
    ->assertEquals(array(
    'foo',
  ), $field
    ->getValue(), '->setValue() returns an array of options if multiple is true');
  $field
    ->setValue('bar');
  $this
    ->assertEquals(array(
    'bar',
  ), $field
    ->getValue(), '->setValue() returns an array of options if multiple is true');
  $field
    ->setValue(array(
    'foo',
    'bar',
  ));
  $this
    ->assertEquals(array(
    'foo',
    'bar',
  ), $field
    ->getValue(), '->setValue() returns an array of options if multiple is true');
  $node = $this
    ->createSelectNode(array(
    'foo' => true,
    'bar' => true,
  ), array(
    'multiple' => 'multiple',
  ));
  $field = new ChoiceFormField($node);
  $this
    ->assertEquals(array(
    'foo',
    'bar',
  ), $field
    ->getValue(), '->getValue() returns the selected options');
  try {
    $field
      ->setValue(array(
      'foobar',
    ));
    $this
      ->fail('->setValue() throws an \\InvalidArgumentException if the value is not one of the options');
  } catch (\InvalidArgumentException $e) {
    $this
      ->assertTrue(true, '->setValue() throws an \\InvalidArgumentException if the value is not one of the options');
  }
}