protected function AssertLegacyTrait::assertFieldsByValue in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php \Drupal\FunctionalTests\AssertLegacyTrait::assertFieldsByValue()
Asserts that a field exists in the current page with a given Xpath result.
Parameters
\Behat\Mink\Element\NodeElement[] $fields: Xml elements.
string $value: (optional) Value of the field to assert. You may pass in NULL (default) to skip checking the actual value, while still checking that the field exists.
string $message: (optional) A message to display with the assertion. Do not translate messages with t().
Deprecated
in drupal:8.3.0 and is removed from drupal:10.0.0. Use iteration over the fields yourself instead and directly check the values in the test.
See also
https://www.drupal.org/node/3129738
3 calls to AssertLegacyTrait::assertFieldsByValue()
- AssertLegacyTrait::assertFieldByXPath in core/tests/ Drupal/ FunctionalTests/ AssertLegacyTrait.php 
- Asserts that a field exists in the current page by the given XPath.
- AssertLegacyTrait::assertNoFieldByXPath in core/tests/ Drupal/ FunctionalTests/ AssertLegacyTrait.php 
- Asserts that a field does not exist or its value does not match, by XPath.
- BrowserTestBaseTest::testAssertFieldsByValue in core/tests/ Drupal/ FunctionalTests/ BrowserTestBaseTest.php 
- Tests legacy assertFieldsByValue().
File
- core/tests/ Drupal/ FunctionalTests/ AssertLegacyTrait.php, line 742 
Class
- AssertLegacyTrait
- Provides convenience methods for assertions in browser tests.
Namespace
Drupal\FunctionalTestsCode
protected function assertFieldsByValue($fields, $value = NULL, $message = '') {
  @trigger_error('AssertLegacyTrait::assertFieldsByValue() is deprecated in drupal:8.3.0 and is removed from drupal:10.0.0. Use iteration over the fields yourself instead and directly check the values in the test. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED);
  // If value specified then check array for match.
  $found = TRUE;
  if (isset($value)) {
    $found = FALSE;
    if ($fields) {
      foreach ($fields as $field) {
        if ($field
          ->getAttribute('type') == 'checkbox') {
          if (is_bool($value)) {
            $found = $field
              ->isChecked() == $value;
          }
          else {
            $found = TRUE;
          }
        }
        elseif ($field
          ->getAttribute('value') == $value) {
          // Input element with correct value.
          $found = TRUE;
        }
        elseif ($field
          ->find('xpath', '//option[@value = ' . (new Escaper())
          ->escapeLiteral($value) . ' and @selected = "selected"]')) {
          // Select element with an option.
          $found = TRUE;
        }
        elseif ($field
          ->getTagName() === 'textarea' && $field
          ->getValue() == $value) {
          // Text area with correct text. Use getValue() here because
          // getText() would remove any newlines in the value.
          $found = TRUE;
        }
        elseif ($field
          ->getTagName() !== 'input' && $field
          ->getText() == $value) {
          $found = TRUE;
        }
      }
    }
  }
  $this
    ->assertTrue($fields && $found, $message);
}