You are here

public function ElementTest::testWrapperIds in Drupal 8

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

Tests wrapper ids for checkboxes and radios.

File

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

Class

ElementTest
Tests building and processing of core form elements.

Namespace

Drupal\Tests\system\Functional\Form

Code

public function testWrapperIds() {
  $this
    ->drupalGet('form-test/checkboxes-radios');

  // Verify that wrapper id is different from element id.
  foreach ([
    'checkboxes',
    'radios',
  ] as $type) {
    $element_ids = $this
      ->xpath('//div[@id=:id]', [
      ':id' => 'edit-' . $type,
    ]);
    $wrapper_ids = $this
      ->xpath('//fieldset[@id=:id]', [
      ':id' => 'edit-' . $type . '--wrapper',
    ]);
    $this
      ->assertCount(1, $element_ids, new FormattableMarkup('A single element id found for type %type', [
      '%type' => $type,
    ]));
    $this
      ->assertCount(1, $wrapper_ids, new FormattableMarkup('A single wrapper id found for type %type', [
      '%type' => $type,
    ]));
  }
}