From b5447770959e9d447e53e21e63faa98fcc1db329 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sat, 3 Oct 2009 19:16:04 +0000 Subject: - Patch #464862 by JohnAlbin, sun, dereine | dvessel, Jacine, Zarabadoo: added drupal_css_class() to clean class names and rename form_clean_id(). --- modules/simpletest/tests/common.test | 53 ++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'modules/simpletest/tests/common.test') diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test index 123fc1b85..72f92820d 100644 --- a/modules/simpletest/tests/common.test +++ b/modules/simpletest/tests/common.test @@ -572,6 +572,59 @@ class CascadingStylesheetsTestCase extends DrupalWebTestCase { } } +/** + * Test for drupal_add_css(). + */ +class DrupalCSSIdentifierTestCase extends DrupalUnitTestCase { + public static function getInfo() { + return array( + 'name' => 'CSS identifiers', + 'description' => 'Test the functions drupal_css_class() and drupal_css_id() for expected behavior', + 'group' => 'System', + ); + } + + /** + * Tests that drupal_css_class() cleans the class name properly. + */ + function testDrupalCleanCSSIdentifier() { + // Verify that no valid ASCII characters are stripped from the class name. + $class = 'abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789'; + $this->assertIdentical(drupal_clean_css_identifier($class, array()), $class, t('Verify valid ASCII characters pass through.')); + + // Verify that no valid UTF-8 characters are stripped from the class name. + $class = '¡¢£¤¥'; + $this->assertIdentical(drupal_clean_css_identifier($class, array()), $class, t('Verify valid UTF-8 characters pass through.')); + + // Verify that invalid characters (including non-breaking space) are stripped from the class name. + $this->assertIdentical(drupal_clean_css_identifier('invalid !"#$%&\'()*+,./:;<=>?@[\\]^`{|}~ class', array()), 'invalidclass', t('Strip invalid characters.')); + } + + /** + * Tests that drupal_css_class() cleans the class name properly. + */ + function testDrupalCSSClass() { + // Verify Drupal coding standards are enforced. + $this->assertIdentical(drupal_css_class('CLASS NAME_[Ü]'), 'class-name--ü', t('Enforce Drupal coding standards.')); + } + + /** + * Tests that drupal_css_id() cleans the id name properly. + */ + function testDrupalCSSId() { + // Verify Drupal coding standards are enforced. + $this->assertIdentical(drupal_css_id('ID NAME_[Ü]'), 'id-name--ü', t('Enforce Drupal coding standards.')); + + // Reset the static cache so we can ensure the unique id count is at zero. + drupal_static_reset('drupal_css_id'); + + // Clean up IDs with invalid starting characters. + $this->assertIdentical(drupal_css_id('test-unique-id'), 'test-unique-id', t('Test the uniqueness of IDs #1.')); + $this->assertIdentical(drupal_css_id('test-unique-id'), 'test-unique-id-2', t('Test the uniqueness of IDs #2.')); + $this->assertIdentical(drupal_css_id('test-unique-id'), 'test-unique-id-3', t('Test the uniqueness of IDs #3.')); + } +} + /** * Test drupal_http_request(). */ -- cgit v1.2.3