You are here

protected function AssertLegacyTrait::assertFieldById in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php \Drupal\FunctionalTests\AssertLegacyTrait::assertFieldById()

Asserts that a field exists with the given ID and value.

Parameters

string $id: ID of field to assert.

string|\Drupal\Component\Render\MarkupInterface $value: (optional) Value for the field to assert. You may pass in NULL to skip checking the value, while still checking that the field exists. However, the default value ('') asserts that the field value is an empty string.

Throws

\Behat\Mink\Exception\ElementNotFoundException

Deprecated

in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->fieldExists() or $this->assertSession()->buttonExists() or $this->assertSession()->fieldValueEquals() instead.

See also

https://www.drupal.org/node/3129738

1 call to AssertLegacyTrait::assertFieldById()
BrowserTestBaseTest::testAssertFieldById in core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php
Tests legacy field asserts by id and by Xpath.

File

core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php, line 325

Class

AssertLegacyTrait
Provides convenience methods for assertions in browser tests.

Namespace

Drupal\FunctionalTests

Code

protected function assertFieldById($id, $value = '') {
  @trigger_error('AssertLegacyTrait::assertFieldById() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->fieldExists() or $this->assertSession()->buttonExists() or $this->assertSession()->fieldValueEquals() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED);
  $xpath = $this
    ->assertSession()
    ->buildXPathQuery('//textarea[@id=:value]|//input[@id=:value]|//select[@id=:value]', [
    ':value' => $id,
  ]);
  $this
    ->assertFieldByXPath($xpath, $value);
}