1 common.test | CommonHTMLIdentifierTestCase::testBackdropHTMLId() |
Tests that backdrop_html_id() cleans the ID properly.
File
- core/
modules/ simpletest/ tests/ common.test, line 970 - Tests for common.inc functionality.
Class
- CommonHTMLIdentifierTestCase
- Test for cleaning HTML identifiers.
Code
function testBackdropHTMLId() {
// Verify that letters, digits, and hyphens are not stripped from the ID.
$id = 'abcdefghijklmnopqrstuvwxyz-0123456789';
$this->assertIdentical(backdrop_html_id($id), $id, 'Verify valid characters pass through.');
// Verify that invalid characters are stripped from the ID.
$this->assertIdentical(backdrop_html_id('invalid-,./:@\\^`{Üidentifier'), 'invalid-identifier', 'Strip invalid characters.');
// Verify Backdrop coding standards are enforced.
$this->assertIdentical(backdrop_html_id('ID NAME_[1]'), 'id-name-1', 'Enforce Backdrop coding standards.');
// Reset the static cache so we can ensure the unique id count is at zero.
backdrop_static_reset('backdrop_html_id');
// Clean up IDs with invalid starting characters.
$this->assertIdentical(backdrop_html_id('test-unique-id'), 'test-unique-id', 'Test the uniqueness of IDs #1.');
$this->assertIdentical(backdrop_html_id('test-unique-id'), 'test-unique-id--2', 'Test the uniqueness of IDs #2.');
$this->assertIdentical(backdrop_html_id('test-unique-id'), 'test-unique-id--3', 'Test the uniqueness of IDs #3.');
}