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 | |
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')
-rw-r--r-- | modules/block/block.module | 2 | ||||
-rw-r--r-- | modules/filter/filter.module | 2 | ||||
-rw-r--r-- | modules/node/node.module | 2 | ||||
-rw-r--r-- | modules/profile/profile.test | 4 | ||||
-rw-r--r-- | modules/simpletest/tests/common.test | 53 | ||||
-rw-r--r-- | modules/simpletest/tests/form.test | 30 | ||||
-rw-r--r-- | modules/simpletest/tests/form_test.module | 29 | ||||
-rw-r--r-- | modules/system/system.test | 2 |
8 files changed, 59 insertions, 65 deletions
diff --git a/modules/block/block.module b/modules/block/block.module index 66aed9651..14488fe1e 100644 --- a/modules/block/block.module +++ b/modules/block/block.module @@ -797,7 +797,7 @@ function template_preprocess_block(&$variables) { // Create the $content variable that templates expect. $variables['content'] = $variables['elements']['#children']; - $variables['classes_array'][] = 'block-' . $variables['block']->module; + $variables['classes_array'][] = drupal_css_class('block-' . $variables['block']->module); $variables['template_files'][] = 'block-' . $variables['block']->region; $variables['template_files'][] = 'block-' . $variables['block']->module; diff --git a/modules/filter/filter.module b/modules/filter/filter.module index 8b9494d45..142482731 100644 --- a/modules/filter/filter.module +++ b/modules/filter/filter.module @@ -746,7 +746,7 @@ function filter_form($selected_format = NULL, $weight = NULL, $parents = array(' drupal_add_js('misc/form.js'); drupal_add_css(drupal_get_path('module', 'filter') . '/filter.css'); - $element_id = form_clean_id('edit-' . implode('-', $parents)); + $element_id = drupal_css_id('edit-' . implode('-', $parents)); $form = array( '#type' => 'fieldset', diff --git a/modules/node/node.module b/modules/node/node.module index bd99ccc42..20187b30b 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -1195,7 +1195,7 @@ function template_preprocess_node(&$variables) { } // Gather node classes. - $variables['classes_array'][] = 'node-' . $node->type; + $variables['classes_array'][] = drupal_css_class('node-' . $node->type); if ($variables['promote']) { $variables['classes_array'][] = 'node-promoted'; } diff --git a/modules/profile/profile.test b/modules/profile/profile.test index 92b9ee428..507d5ebd3 100644 --- a/modules/profile/profile.test +++ b/modules/profile/profile.test @@ -266,8 +266,8 @@ class ProfileTestAutocomplete extends ProfileTestCase { $this->setProfileField($field, $field['value']); // Set some html for what we want to see in the page output later. - $autocomplete_html = '<input class="autocomplete" type="hidden" id="' . form_clean_id('edit-' . $field['form_name'] . '-autocomplete') . '" value="' . url('profile/autocomplete/' . $field['fid'], array('absolute' => TRUE)) . '" disabled="disabled" />'; - $field_html = '<input type="text" maxlength="255" name="' . $field['form_name'] . '" id="' . form_clean_id('edit-' . $field['form_name']) . '" size="60" value="' . $field['value'] . '" class="form-text form-autocomplete required" />'; + $autocomplete_html = '<input class="autocomplete" type="hidden" id="' . drupal_css_id('edit-' . $field['form_name'] . '-autocomplete') . '" value="' . url('profile/autocomplete/' . $field['fid'], array('absolute' => TRUE)) . '" disabled="disabled" />'; + $field_html = '<input type="text" maxlength="255" name="' . $field['form_name'] . '" id="' . drupal_css_id('edit-' . $field['form_name']) . '" size="60" value="' . $field['value'] . '" class="form-text form-autocomplete required" />'; // Check that autocompletion html is found on the user's profile edit page. $this->drupalGet('user/' . $this->admin_user->uid . '/edit/' . $category); 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 { diff --git a/modules/simpletest/tests/form.test b/modules/simpletest/tests/form.test index 855fb3d08..fb922ec8c 100644 --- a/modules/simpletest/tests/form.test +++ b/modules/simpletest/tests/form.test @@ -333,36 +333,6 @@ class FormsElementsTableSelectFunctionalTest extends DrupalWebTestCase { } /** - * Test the form_clean_id() for expected behavior. - */ -class FormsFormCleanIdFunctionalTest extends DrupalWebTestCase { - - public static function getInfo() { - return array( - 'name' => 'form_clean_id() test', - 'description' => 'Test the function form_clean_id() for expected behavior', - 'group' => 'Form API', - ); - } - - function setUp() { - parent::setUp('form_test'); - } - - /** - * Test the uniqueness of the form_clean_id() function. - */ - function testFormCleanId() { - $this->drupalGet('form_test/form_clean_id'); - $this->assertNoUniqueText('form-test-form-clean-id-presence'); - $this->assertUniqueText('form-test-form-clean-id-presence-1'); - $this->assertUniqueText('form-test-form-clean-id-presence-2'); - $this->assertNoUniqueText('Test Textfield'); - } - -} - -/** * Test using drupal_form_submit in a batch. */ class FormAPITestCase extends DrupalWebTestCase { diff --git a/modules/simpletest/tests/form_test.module b/modules/simpletest/tests/form_test.module index 6d6fd38f8..ee47b4f14 100644 --- a/modules/simpletest/tests/form_test.module +++ b/modules/simpletest/tests/form_test.module @@ -39,13 +39,6 @@ function form_test_menu() { 'type' => MENU_CALLBACK, ); - $items['form_test/form_clean_id'] = array( - 'title' => 'form_clean_id test', - 'page callback' => 'form_test_form_clean_id_page', - 'access arguments' => array('access content'), - 'type' => MENU_CALLBACK, - ); - $items['form_test/drupal_form_submit_batch_api'] = array( 'title' => 'BatchAPI Drupal_form_submit tests', 'page callback' => 'form_test_drupal_form_submit_batch_api', @@ -73,28 +66,6 @@ function form_test_menu() { } /** - * Generate a page with three forms, to test the clean_id generation. - */ -function form_test_form_clean_id_page() { - $build['form_test_test_form1'] = drupal_get_form('form_test_test_form'); - $build['form_test_test_form2'] = drupal_get_form('form_test_test_form'); - $build['form_test_test_form3'] = drupal_get_form('form_test_test_form'); - return $build; -} - -/** - * A simple form to test clean_id generation. - */ -function form_test_test_form($form, &$form_state) { - $form['input'] = array( - '#type' => 'item', - '#title' => 'Test Textfield', - '#markup' => form_clean_id('form_test_form_clean_id_presence'), - ); - return $form; -} - -/** * Create a header and options array. Helper function for callbacks. */ function _form_test_tableselect_get_data() { diff --git a/modules/system/system.test b/modules/system/system.test index 9df53b78f..686d6cdb9 100644 --- a/modules/system/system.test +++ b/modules/system/system.test @@ -252,7 +252,7 @@ class ModuleVersionTestCase extends ModuleTestCase { $n = count($dependencies); for ($i = 0; $i < $n; $i++) { $this->drupalGet('admin/config/modules'); - $checkbox = $this->xpath('//input[@id="edit-modules-Testing-module-test-enable"]'); + $checkbox = $this->xpath('//input[@id="edit-modules-testing-module-test-enable"]'); $this->assertEqual(!empty($checkbox[0]['disabled']), $i % 2, $dependencies[$i]); } } |