You are here

function ElementTest::testPlaceHolderText in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Form/ElementTest.php \Drupal\system\Tests\Form\ElementTest::testPlaceHolderText()

Tests placeholder text for elements that support placeholders.

File

core/modules/system/src/Tests/Form/ElementTest.php, line 29
Contains \Drupal\system\Tests\Form\ElementTest.

Class

ElementTest
Tests building and processing of core form elements.

Namespace

Drupal\system\Tests\Form

Code

function testPlaceHolderText() {
  $this
    ->drupalGet('form-test/placeholder-text');
  $expected = 'placeholder-text';

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

  // Test to make sure textarea has the proper placeholder text.
  $element = $this
    ->xpath('//textarea[@id=:id and @placeholder=:expected]', array(
    ':id' => 'edit-textarea',
    ':expected' => $expected,
  ));
  $this
    ->assertTrue(!empty($element), 'Placeholder text placed in textarea.');
}