function BrowserTestBaseTest::testFieldAssertsForButton

Same name and namespace in other branches
  1. 9 core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php \Drupal\FunctionalTests\BrowserTestBaseTest::testFieldAssertsForButton()

Tests legacy field asserts for button field type.

File

core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php, line 504

Class

BrowserTestBaseTest
Tests BrowserTestBase functionality.

Namespace

Drupal\FunctionalTests

Code

public function testFieldAssertsForButton() {
    $this->drupalGet('test-field-xpath');
    $this->assertFieldById('edit-save', NULL);
    // Test that the assertion fails correctly if the field value is passed in
    // rather than the id.
    try {
        $this->assertFieldById('Save', NULL);
        $this->fail('The field with id of "Save" was found.');
    } catch (ExpectationFailedException $e) {
        // Expected exception; just continue testing.
    }
    $this->assertNoFieldById('Save', NULL);
    // Test that the assertion fails correctly if the id of an actual field is
    // passed in.
    try {
        $this->assertNoFieldById('edit-save', NULL);
        $this->fail('The field with id of "edit-save" was not found.');
    } catch (ExpectationException $e) {
        // Expected exception; just continue testing.
    }
    // Test that multiple fields with the same name are validated correctly.
    $this->assertFieldByName('duplicate_button', 'Duplicate button 1');
    $this->assertFieldByName('duplicate_button', 'Duplicate button 2');
    $this->assertNoFieldByName('duplicate_button', 'Rabbit');
    try {
        $this->assertNoFieldByName('duplicate_button', '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.
    }
}

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