function HtmlIdentifierUnitTest::testDrupalCleanCSSIdentifier

Tests that drupal_clean_css_identifier() cleans the identifier properly.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Common/HtmlIdentifierUnitTest.php, line 27
Definition of Drupal\system\Tests\Common\HtmlIdentifierUnitTest.

Class

HtmlIdentifierUnitTest
Tests cleaning HTML identifiers.

Namespace

Drupal\system\Tests\Common

Code

function testDrupalCleanCSSIdentifier() {

  // Verify that no valid ASCII characters are stripped from the identifier.
  $identifier = 'abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789';
  $this
    ->assertIdentical(drupal_clean_css_identifier($identifier, array()), $identifier, 'Verify valid ASCII characters pass through.');

  // Verify that valid UTF-8 characters are not stripped from the identifier.
  $identifier = '¡¢£¤¥';
  $this
    ->assertIdentical(drupal_clean_css_identifier($identifier, array()), $identifier, 'Verify valid UTF-8 characters pass through.');

  // Verify that invalid characters (including non-breaking space) are stripped from the identifier.
  $this
    ->assertIdentical(drupal_clean_css_identifier('invalid !"#$%&\'()*+,./:;<=>?@[\\]^`{|}~ identifier', array()), 'invalididentifier', 'Strip invalid characters.');

  // Verify that double underscores are not stripped from the identifier.
  $identifier = 'css__identifier__with__double__underscores';
  $this
    ->assertIdentical(drupal_clean_css_identifier($identifier), $identifier, 'Verify double underscores pass through.');
}