function WebAssertTest::testFieldAssertsForButton

Same name in this branch
  1. 11.x core/tests/Drupal/Tests/Core/Test/WebAssertTest.php \Drupal\Tests\Core\Test\WebAssertTest::testFieldAssertsForButton()
Same name in other branches
  1. 10 core/tests/Drupal/FunctionalTests/WebAssertTest.php \Drupal\FunctionalTests\WebAssertTest::testFieldAssertsForButton()
  2. 10 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/FunctionalTests/WebAssertTest.php, line 312

Class

WebAssertTest
Tests WebAssert functionality.

Namespace

Drupal\FunctionalTests

Code

public function testFieldAssertsForButton() : void {
    $this->drupalGet('test-field-xpath');
    // 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) {
        // Expected exception; just continue testing.
    }
}

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