function FormTest::testRange

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Form/FormTest.php \Drupal\Tests\system\Functional\Form\FormTest::testRange()
  2. 8.9.x core/modules/system/tests/src/Functional/Form/FormTest.php \Drupal\Tests\system\Functional\Form\FormTest::testRange()
  3. 10 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 674

Class

FormTest
Tests various form element validation mechanisms.

Namespace

Drupal\Tests\system\Functional\Form

Code

public function testRange() : void {
    $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")]');
}

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