function ElementTest::testPlaceHolderText

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Form/ElementTest.php \Drupal\Tests\system\Functional\Form\ElementTest::testPlaceHolderText()
  2. 10 core/modules/system/tests/src/Functional/Form/ElementTest.php \Drupal\Tests\system\Functional\Form\ElementTest::testPlaceHolderText()
  3. 11.x core/modules/system/tests/src/Functional/Form/ElementTest.php \Drupal\Tests\system\Functional\Form\ElementTest::testPlaceHolderText()

Tests placeholder text for elements that support placeholders.

File

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

Class

ElementTest
Tests building and processing of core form elements.

Namespace

Drupal\Tests\system\Functional\Form

Code

public function testPlaceHolderText() {
    $this->drupalGet('form-test/placeholder-text');
    $expected = 'placeholder-text';
    // Test to make sure non-textarea elements have the proper placeholder text.
    foreach ([
        'textfield',
        'tel',
        'url',
        'password',
        'email',
        'number',
    ] as $type) {
        $element = $this->xpath('//input[@id=:id and @placeholder=:expected]', [
            ':id' => 'edit-' . $type,
            ':expected' => $expected,
        ]);
        $this->assertTrue(!empty($element), new FormattableMarkup('Placeholder text placed in @type.', [
            '@type' => $type,
        ]));
    }
    // Test to make sure textarea has the proper placeholder text.
    $element = $this->xpath('//textarea[@id=:id and @placeholder=:expected]', [
        ':id' => 'edit-textarea',
        ':expected' => $expected,
    ]);
    $this->assertTrue(!empty($element), 'Placeholder text placed in textarea.');
}

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