function WebAssertTest::testFieldAssertsForButton

Same name in this branch
  1. 10 core/tests/Drupal/FunctionalTests/WebAssertTest.php \Drupal\FunctionalTests\WebAssertTest::testFieldAssertsForButton()
Same name in other branches
  1. 11.x core/tests/Drupal/FunctionalTests/WebAssertTest.php \Drupal\FunctionalTests\WebAssertTest::testFieldAssertsForButton()
  2. 11.x core/tests/Drupal/Tests/Core/Test/WebAssertTest.php \Drupal\Tests\Core\Test\WebAssertTest::testFieldAssertsForButton()

Tests legacy field asserts for button field type.

@covers ::buttonExists @covers ::buttonNotExists

File

core/tests/Drupal/Tests/Core/Test/WebAssertTest.php, line 359

Class

WebAssertTest
Tests WebAssert functionality.

Namespace

Drupal\Tests\Core\Test

Code

public function testFieldAssertsForButton() : void {
    $this->visit('', <<<HTML
      <input type="submit" id="edit-save" value="Save" name="op">
      <input type="submit" id="duplicate_button" value="Duplicate button 1" name="duplicate_button">
      <input type="submit" id="duplicate_button" value="Duplicate button 2" name="duplicate_button">
HTML
);
    // Verify if the test passes with button ID.
    $this->assertSession()
        ->buttonExists('edit-save');
    // Verify if the test passes with button Value.
    $this->assertSession()
        ->buttonExists('Save');
    // Verify if the test passes with button Name.
    $this->assertSession()
        ->buttonExists('op');
    // Verify if the test passes with button ID.
    $this->assertSession()
        ->buttonNotExists('i-do-not-exist');
    // Verify if the test passes with button Value.
    $this->assertSession()
        ->buttonNotExists('I do not exist');
    // Verify if the test passes with button Name.
    $this->assertSession()
        ->buttonNotExists('no');
    // Test that multiple fields with the same name are validated correctly.
    $this->assertSession()
        ->buttonExists('duplicate_button');
    $this->assertSession()
        ->buttonExists('Duplicate button 1');
    $this->assertSession()
        ->buttonExists('Duplicate button 2');
    $this->assertSession()
        ->buttonNotExists('Rabbit');
    try {
        $this->assertSession()
            ->buttonNotExists('Duplicate button 2');
        $this->fail('The "duplicate_button" field with the value Duplicate button 2 was not found.');
    } catch (ExpectationException $e) {
        // Expected exception; just continue testing.
    }
    $this->addToAssertionCount(11);
}

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