function ViewTestBase::helperButtonHasLabel

Same name and namespace in other branches
  1. 11.x core/modules/views/tests/src/Functional/ViewTestBase.php \Drupal\Tests\views\Functional\ViewTestBase::helperButtonHasLabel()
  2. 10 core/modules/views/tests/src/Functional/ViewTestBase.php \Drupal\Tests\views\Functional\ViewTestBase::helperButtonHasLabel()
  3. 8.9.x core/modules/views/src/Tests/ViewTestBase.php \Drupal\views\Tests\ViewTestBase::helperButtonHasLabel()
  4. 8.9.x core/modules/views/tests/src/Functional/ViewTestBase.php \Drupal\Tests\views\Functional\ViewTestBase::helperButtonHasLabel()

Asserts the existence of a button with a certain ID and label.

Parameters

string $id: The HTML ID of the button

string $expected_label: The expected label for the button.

string $message: (optional) A custom message to display with the assertion. If no custom message is provided, the message will indicate the button label.

Throws

\Behat\Mink\Exception\ElementNotFoundException

File

core/modules/views/tests/src/Functional/ViewTestBase.php, line 111

Class

ViewTestBase
Defines a base class for Views testing in the full web test environment.

Namespace

Drupal\Tests\views\Functional

Code

protected function helperButtonHasLabel($id, $expected_label, $message = 'Label has the expected value: %label.') {
  $xpath = $this->assertSession()
    ->buildXPathQuery('//button[@id=:value]|//input[@id=:value]', [
    ':value' => $id,
  ]);
  $field = $this->getSession()
    ->getPage()
    ->find('xpath', $xpath);
  if (empty($field)) {
    throw new ElementNotFoundException($this->getSession()
      ->getDriver(), 'form field', 'id', $field);
  }
  $this->assertEquals($expected_label, $field->getValue());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.