You are here

public function ElementTest::testButtonClasses in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Functional/Form/ElementTest.php \Drupal\Tests\system\Functional\Form\ElementTest::testButtonClasses()
  2. 9 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 126

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
    ->assertCount(2, $this
    ->xpath('//*[contains(concat(" ", @class, " "), " button ")]'));
  $this
    ->assertCount(1, $this
    ->xpath('//*[contains(concat(" ", @class, " "), " button--foo ")]'));
  $this
    ->assertCount(1, $this
    ->xpath('//*[contains(concat(" ", @class, " "), " button--danger ")]'));
}