You are here

public function FormTest::testRange in Drupal 8

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

Class

FormTest
Tests various form element validation mechanisms.

Namespace

Drupal\Tests\system\Functional\Form

Code

public function testRange() {
  $this
    ->drupalPostForm('form-test/range', [], 'Submit');
  $values = json_decode($this
    ->getSession()
    ->getPage()
    ->getContent());
  $this
    ->assertEqual($values->with_default_value, 18);
  $this
    ->assertEqual($values->float, 10.5);
  $this
    ->assertEqual($values->integer, 6);
  $this
    ->assertEqual($values->offset, 6.9);
  $this
    ->drupalPostForm('form-test/range/invalid', [], 'Submit');
  $this
    ->assertFieldByXPath('//input[@type="range" and contains(@class, "error")]', NULL, 'Range element has the error class.');
}