function ElementTest::testRadiosChecked

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

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

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