You are here

protected function WebformAssertLegacyTrait::assertNoFieldByXPath in Webform 6.x

Same name and namespace in other branches
  1. 8.5 tests/src/Traits/WebformAssertLegacyTrait.php \Drupal\Tests\webform\Traits\WebformAssertLegacyTrait::assertNoFieldByXPath()

Asserts that a field does not exist or its value does not match, by XPath.

Parameters

string $xpath: XPath used to find the field.

string $value: (optional) Value of the field, to assert that the field's value on the page does not match it.

string $message: (optional) A message to display with the assertion. Do not translate messages with t().

Throws

\Behat\Mink\Exception\ExpectationException

3 calls to WebformAssertLegacyTrait::assertNoFieldByXPath()
WebformAssertLegacyTrait::assertNoField in tests/src/Traits/WebformAssertLegacyTrait.php
Asserts that a field does NOT exist with the given name or ID.
WebformAssertLegacyTrait::assertNoFieldById in tests/src/Traits/WebformAssertLegacyTrait.php
Asserts that a field does not exist with the given ID and value.
WebformAssertLegacyTrait::assertNoFieldByName in tests/src/Traits/WebformAssertLegacyTrait.php
Asserts that a field does not exist with the given name and value.

File

tests/src/Traits/WebformAssertLegacyTrait.php, line 520

Class

WebformAssertLegacyTrait
Provides convenience methods for assertions in browser tests.

Namespace

Drupal\Tests\webform\Traits

Code

protected function assertNoFieldByXPath($xpath, $value = NULL, $message = '') {
  $fields = $this
    ->xpath($xpath);
  if (!empty($fields)) {
    if (isset($value)) {
      $found = FALSE;
      try {
        $this
          ->assertFieldsByValue($fields, $value);
        $found = TRUE;
      } catch (\Exception $e) {
      }
      if ($found) {
        throw new ExpectationException(sprintf('The field resulting from %s was found with the provided value %s.', $xpath, $value), $this
          ->getSession()
          ->getDriver());
      }
    }
    else {
      throw new ExpectationException(sprintf('The field resulting from %s was found.', $xpath), $this
        ->getSession()
        ->getDriver());
    }
  }
}