You are here

public function ElementTest::testRadiosChecked 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::testRadiosChecked()
  2. 9 core/modules/system/tests/src/Functional/Form/ElementTest.php \Drupal\Tests\system\Functional\Form\ElementTest::testRadiosChecked()

Tests correct checked attribute for radios element.

File

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

Class

ElementTest
Tests building and processing of core form elements.

Namespace

Drupal\Tests\system\Functional\Form

Code

public function testRadiosChecked() {

  // Verify that there is only one radio option checked.
  $this
    ->drupalGet('form-test/radios-checked');
  $this
    ->assertSession()
    ->elementsCount('xpath', '//input[@name="radios" and @checked]', 1);
  $this
    ->assertSession()
    ->fieldValueEquals("radios", '0');
  $this
    ->assertSession()
    ->elementsCount('xpath', '//input[@name="radios-string" and @checked]', 1);
  $this
    ->assertSession()
    ->fieldValueEquals("radios-string", 'bar');
  $this
    ->assertSession()
    ->elementsCount('xpath', '//input[@name="radios-boolean-true" and @checked]', 1);
  $this
    ->assertSession()
    ->fieldValueEquals("radios-boolean-true", '1');

  // A default value of FALSE indicates that nothing is set.
  $this
    ->assertSession()
    ->elementNotExists('xpath', '//input[@name="radios-boolean-false" and @checked]');
  $this
    ->assertSession()
    ->elementsCount('xpath', '//input[@name="radios-boolean-any" and @checked]', 1);
  $this
    ->assertSession()
    ->fieldValueEquals("radios-boolean-any", 'All');
  $this
    ->assertSession()
    ->elementsCount('xpath', '//input[@name="radios-string-zero" and @checked]', 1);
  $this
    ->assertSession()
    ->fieldValueEquals("radios-string-zero", '0');
  $this
    ->assertSession()
    ->elementsCount('xpath', '//input[@name="radios-int-non-zero" and @checked]', 1);
  $this
    ->assertSession()
    ->fieldValueEquals("radios-int-non-zero", '10');
  $this
    ->assertSession()
    ->elementsCount('xpath', '//input[@name="radios-int-non-zero-as-string" and @checked]', 1);
  $this
    ->assertSession()
    ->fieldValueEquals("radios-int-non-zero-as-string", '100');
  $this
    ->assertSession()
    ->elementsCount('xpath', '//input[@name="radios-empty-string" and @checked]', 1);
  $this
    ->assertSession()
    ->fieldValueEquals("radios-empty-string", '0');
  $this
    ->assertSession()
    ->elementNotExists('xpath', '//input[@name="radios-empty-array" and @checked]');
  $this
    ->assertSession()
    ->elementsCount('xpath', '//input[@name="radios-key-FALSE" and @checked]', 1);
  $this
    ->assertSession()
    ->fieldValueEquals("radios-key-FALSE", '0');
}