You are here

public function FormTest::testRange in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Functional/Form/FormTest.php \Drupal\Tests\system\Functional\Form\FormTest::testRange()
  2. 9 core/modules/system/tests/src/Functional/Form/FormTest.php \Drupal\Tests\system\Functional\Form\FormTest::testRange()

Tests default value handling of #type 'range' elements.

File

core/modules/system/tests/src/Functional/Form/FormTest.php, line 675

Class

FormTest
Tests various form element validation mechanisms.

Namespace

Drupal\Tests\system\Functional\Form

Code

public function testRange() {
  $this
    ->drupalGet('form-test/range');
  $this
    ->submitForm([], 'Submit');
  $values = json_decode($this
    ->getSession()
    ->getPage()
    ->getContent());
  $this
    ->assertEquals(18, $values->with_default_value);
  $this
    ->assertEquals(10.5, $values->float);
  $this
    ->assertEquals(6, $values->integer);
  $this
    ->assertEquals(6.9, $values->offset);
  $this
    ->drupalGet('form-test/range/invalid');
  $this
    ->submitForm([], 'Submit');

  // Verify that the 'range' element has the error class.
  $this
    ->assertSession()
    ->elementExists('xpath', '//input[@type="range" and contains(@class, "error")]');
}