You are here

public function ElementTest::testButtonClasses in Drupal 8

Same name and namespace in other branches
  1. 9 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()

Tests button classes.

File

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

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 ")]'));
}