function ElementTest::testButtonClasses

Same name and namespace in other branches
  1. 8.9.x core/modules/system/tests/src/Functional/Form/ElementTest.php \Drupal\Tests\system\Functional\Form\ElementTest::testButtonClasses()
  2. 10 core/modules/system/tests/src/Functional/Form/ElementTest.php \Drupal\Tests\system\Functional\Form\ElementTest::testButtonClasses()
  3. 11.x core/modules/system/tests/src/Functional/Form/ElementTest.php \Drupal\Tests\system\Functional\Form\ElementTest::testButtonClasses()

Tests button classes.

File

core/modules/system/tests/src/Functional/Form/ElementTest.php, line 124

Class

ElementTest
Tests building and processing of core form elements.

Namespace

Drupal\Tests\system\Functional\Form

Code

public function testButtonClasses() {
    $this->drupalGet('form-test/button-class');
    // Just contains(@class, "button") won't do because then
    // "button--foo" would contain "button". Instead, check
    // " button ". Make sure it matches in the beginning and the end too
    // by adding a space before and after.
    $this->assertSession()
        ->elementsCount('xpath', '//*[contains(concat(" ", @class, " "), " button ")]', 2);
    $this->assertSession()
        ->elementsCount('xpath', '//*[contains(concat(" ", @class, " "), " button--foo ")]', 1);
    $this->assertSession()
        ->elementsCount('xpath', '//*[contains(concat(" ", @class, " "), " button--danger ")]', 1);
}

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