function FormElementMaxlengthTest::testAttributes

Same name in other branches
  1. 9 core/modules/system/tests/src/Kernel/Form/FormElementMaxlengthTest.php \Drupal\Tests\system\Kernel\Form\FormElementMaxlengthTest::testAttributes()
  2. 8.9.x core/modules/system/tests/src/Kernel/Form/FormElementMaxlengthTest.php \Drupal\Tests\system\Kernel\Form\FormElementMaxlengthTest::testAttributes()
  3. 11.x core/modules/system/tests/src/Kernel/Form/FormElementMaxlengthTest.php \Drupal\Tests\system\Kernel\Form\FormElementMaxlengthTest::testAttributes()

Ensures maxlength attribute can be used in compatible elements.

File

core/modules/system/tests/src/Kernel/Form/FormElementMaxlengthTest.php, line 67

Class

FormElementMaxlengthTest
Tests the maxlength HTML attribute on form elements.

Namespace

Drupal\Tests\system\Kernel\Form

Code

public function testAttributes() : void {
    
    /** @var \Drupal\Core\Form\FormBuilderInterface $form_builder */
    $form_builder = $this->container
        ->get('form_builder');
    $form_state = new FormState();
    $elements = $form_builder->buildForm($this, $form_state);
    $this->render($elements);
    $css_selector_converter = new CssSelectorConverter();
    $elements = $this->xpath($css_selector_converter->toXPath('input[name=title][maxlength=255]'));
    $this->assertCount(1, $elements, 'Text field has correct maxlength in form.');
    $elements = $this->xpath($css_selector_converter->toXPath('textarea[name=description][maxlength=255]'));
    $this->assertCount(1, $elements, 'Textarea field has correct maxlength in form.');
}

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