You are here

protected function ThunderFormFieldTestTrait::setCheckbox in Thunder 8.3

Same name and namespace in other branches
  1. 8.5 tests/src/FunctionalJavascript/ThunderFormFieldTestTrait.php \Drupal\Tests\thunder\FunctionalJavascript\ThunderFormFieldTestTrait::setCheckbox()
  2. 8.2 tests/src/FunctionalJavascript/ThunderFormFieldTestTrait.php \Drupal\Tests\thunder\FunctionalJavascript\ThunderFormFieldTestTrait::setCheckbox()
  3. 8.4 tests/src/FunctionalJavascript/ThunderFormFieldTestTrait.php \Drupal\Tests\thunder\FunctionalJavascript\ThunderFormFieldTestTrait::setCheckbox()
  4. 6.2.x tests/src/FunctionalJavascript/ThunderFormFieldTestTrait.php \Drupal\Tests\thunder\FunctionalJavascript\ThunderFormFieldTestTrait::setCheckbox()
  5. 6.0.x tests/src/FunctionalJavascript/ThunderFormFieldTestTrait.php \Drupal\Tests\thunder\FunctionalJavascript\ThunderFormFieldTestTrait::setCheckbox()
  6. 6.1.x tests/src/FunctionalJavascript/ThunderFormFieldTestTrait.php \Drupal\Tests\thunder\FunctionalJavascript\ThunderFormFieldTestTrait::setCheckbox()

Set value for group of checkboxes.

Existing selection will be cleared before new values are applied.

Parameters

\Behat\Mink\Element\DocumentElement $page: Current active page.

string $fieldName: Field name.

string $value: Comma separated values for checkboxes.

1 call to ThunderFormFieldTestTrait::setCheckbox()
ThunderFormFieldTestTrait::setFieldValue in tests/src/FunctionalJavascript/ThunderFormFieldTestTrait.php
Set value for defined field name on current page.

File

tests/src/FunctionalJavascript/ThunderFormFieldTestTrait.php, line 26

Class

ThunderFormFieldTestTrait
Trait for manipulation of form fields.

Namespace

Drupal\Tests\thunder\FunctionalJavascript

Code

protected function setCheckbox(DocumentElement $page, $fieldName, $value) {

  // UnCheck all checkboxes and check defined.
  $this
    ->getSession()
    ->executeScript("jQuery('input[name*=\"{$fieldName}\"]').prop('checked', false);");
  $checkNames = explode(',', $value);
  foreach ($checkNames as $checkName) {
    $checkBoxName = $fieldName . '[' . trim($checkName) . ']';
    $this
      ->scrollElementInView('[name="' . $checkBoxName . '"]');
    $page
      ->checkField($checkBoxName);
  }
}