Error message

You are browsing documentation for drupal 7.x, which is not supported anymore. Read the updated version of this page for drupal 11.x (the latest version).

function DrupalHTMLIdentifierTestCase::testDrupalHTMLId

Tests that drupal_html_id() cleans the ID properly.

File

modules/simpletest/tests/common.test, line 1070

Class

DrupalHTMLIdentifierTestCase
Test for cleaning HTML identifiers.

Code

function testDrupalHTMLId() {
 // Verify that letters, digits, and hyphens are not stripped from the ID.
 $id = 'abcdefghijklmnopqrstuvwxyz-0123456789';
 $this->assertIdentical (drupal_html_id ($id), $id, 'Verify valid characters pass through.');
 // Verify that invalid characters are stripped from the ID.
 $this->assertIdentical (drupal_html_id ('invalid,./:@\\^`{Üidentifier'), 'invalididentifier', 'Strip invalid characters.');
 // Verify Drupal coding standards are enforced.
 $this->assertIdentical (drupal_html_id ('ID NAME_[1]'), 'id-name-1', 'Enforce Drupal coding standards.');
 // Reset the static cache so we can ensure the unique id count is at zero.
 drupal_static_reset ('drupal_html_id');
 // Clean up IDs with invalid starting characters.
 $this->assertIdentical (drupal_html_id ('test-unique-id'), 'test-unique-id', 'Test the uniqueness of IDs #1.');
 $this->assertIdentical (drupal_html_id ('test-unique-id'), 'test-unique-id--2', 'Test the uniqueness of IDs #2.');
 $this->assertIdentical (drupal_html_id ('test-unique-id'), 'test-unique-id--3', 'Test the uniqueness of IDs #3.');
}

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