diff options
author | Dries Buytaert <dries@buytaert.net> | 2009-10-03 19:16:04 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2009-10-03 19:16:04 +0000 |
commit | b5447770959e9d447e53e21e63faa98fcc1db329 (patch) | |
tree | 3f38cba8adefd9108019b010cde327e68bec0ebb /modules/simpletest/tests/common.test | |
parent | b5199f2297c7cac6d03980bea6be9a02bbdf1738 (diff) | |
download | brdo-b5447770959e9d447e53e21e63faa98fcc1db329.tar.gz brdo-b5447770959e9d447e53e21e63faa98fcc1db329.tar.bz2 |
- Patch #464862 by JohnAlbin, sun, dereine | dvessel, Jacine, Zarabadoo: added drupal_css_class() to clean class names and rename form_clean_id().
Diffstat (limited to 'modules/simpletest/tests/common.test')
-rw-r--r-- | modules/simpletest/tests/common.test | 53 |
1 files changed, 53 insertions, 0 deletions
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 @@ -573,6 +573,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(). */ class DrupalHTTPRequestTestCase extends DrupalWebTestCase { |