Commit 8e1ef051 authored by John Fiala's avatar John Fiala
Browse files

Issue #2364673 by jcfiala: Replaced drupal_html_class() with...

Issue #2364673 by jcfiala: Replaced drupal_html_class() with drupal_clean_css_identifier() so that link field classes are not forced to lower case.
parent b373ad65
......@@ -614,7 +614,7 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$entity) {
if (!empty($item['attributes']['class'])) {
$classes = explode(' ', $item['attributes']['class']);
foreach ($classes as &$class) {
$class = drupal_html_class($class);
$class = drupal_clean_css_identifier($class);
}
$item['attributes']['class'] = implode(' ', $classes);
}
......
......@@ -312,4 +312,148 @@ class LinkUITest extends DrupalWebTestcase {
$this->assertFalse($instance['settings']['attributes']['class'], 'By default, no class should be set.');
$this->assertFalse($instance['settings']['title_value'], 'By default, no title should be set.');
}
/**
* If we're creating a new field and just hit 'save' on the default options, we want to make
* sure they are set to the expected results.
*/
function testCRUDCreateFieldWithClass() {
$this->web_user = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
$this->drupalLogin($this->web_user);
// create field
$name = strtolower($this->randomName());
$edit = array(
'fields[_add_new_field][label]' => $name,
'fields[_add_new_field][field_name]' => $name,
'fields[_add_new_field][type]' => 'link_field',
'fields[_add_new_field][widget_type]' => 'link_field',
);
$this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save'));
$this->drupalPost(NULL, array(), t('Save field settings'));
$link_class_name = 'basic-link-' . strtolower($this->randomName());
$edit = array(
'instance[settings][attributes][class]' => $link_class_name,
);
$this->drupalPost(NULL, $edit, t('Save settings'));
// Is field created?
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
node_types_rebuild();
menu_rebuild();
_field_info_collate_fields(TRUE);
$instances = field_info_instances('node', 'page');
$instance = $instances['field_' . $name];
$this->assertFalse($instance['required'], 'Make sure field is not required.');
$this->assertEqual($instance['settings']['title'], 'optional', 'Title should be optional by default.');
$this->assertTrue($instance['settings']['validate_url'], 'Make sure validation is on.');
$this->assertTrue($instance['settings']['enable_tokens'], 'Enable Tokens should be on by default.');
$this->assertEqual($instance['settings']['display']['url_cutoff'], 80, 'Url cutoff should be at 80 characters.');
$this->assertEqual($instance['settings']['attributes']['target'], 'default', 'Target should be "default"');
$this->assertFalse($instance['settings']['attributes']['rel'], 'Rel should be blank by default.');
$this->assertEqual($instance['settings']['attributes']['class'], $link_class_name, 'One class should be set.');
$this->assertFalse($instance['settings']['title_value'], 'By default, no title should be set.');
// Now, let's create a node with this field and make sure the link shows up:
// create page form
$field_name = 'field_' . $name;
$this->drupalGet('node/add/page');
$this->assertField($field_name . '[und][0][url]', 'URL found');
$input = array(
'title' => 'This & That',
'href' => 'http://www.example.com/',
);
$edit = array(
'title' => $field_name,
$field_name . '[und][0][title]' => $input['title'],
$field_name . '[und][0][url]' => $input['href'],
);
$this->drupalPost(NULL, $edit, t('Save'));
$url = $this->getUrl();
// change to anonymous user
$this->drupalLogout();
$this->drupalGet($url);
$this->assertRaw('This & That');
$this->assertPattern('|class\s?=\s?"' . $link_class_name . '"|', "Class $link_class_name exists on page.");
}
/**
* If we're creating a new field and just hit 'save' on the default options, we want to make
* sure they are set to the expected results.
*/
function testCRUDCreateFieldWithTwoClasses() {
$this->web_user = $this->drupalCreateUser(array('administer content types', 'access content', 'create page content'));
$this->drupalLogin($this->web_user);
// create field
$name = strtolower($this->randomName());
$edit = array(
'fields[_add_new_field][label]' => $name,
'fields[_add_new_field][field_name]' => $name,
'fields[_add_new_field][type]' => 'link_field',
'fields[_add_new_field][widget_type]' => 'link_field',
);
$this->drupalPost('admin/structure/types/manage/page/fields', $edit, t('Save'));
$this->drupalPost(NULL, array(), t('Save field settings'));
$link_class_name = 'basic-link ' . strtoupper($this->randomName());
$edit = array(
'instance[settings][attributes][class]' => $link_class_name,
);
$this->drupalPost(NULL, $edit, t('Save settings'));
// Is field created?
$this->assertRaw(t('Saved %label configuration', array('%label' => $name)), 'Field added');
node_types_rebuild();
menu_rebuild();
_field_info_collate_fields(TRUE);
$instances = field_info_instances('node', 'page');
$instance = $instances['field_' . $name];
$this->assertFalse($instance['required'], 'Make sure field is not required.');
$this->assertEqual($instance['settings']['title'], 'optional', 'Title should be optional by default.');
$this->assertTrue($instance['settings']['validate_url'], 'Make sure validation is on.');
$this->assertTrue($instance['settings']['enable_tokens'], 'Enable Tokens should be on by default.');
$this->assertEqual($instance['settings']['display']['url_cutoff'], 80, 'Url cutoff should be at 80 characters.');
$this->assertEqual($instance['settings']['attributes']['target'], 'default', 'Target should be "default"');
$this->assertFalse($instance['settings']['attributes']['rel'], 'Rel should be blank by default.');
$this->assertEqual($instance['settings']['attributes']['class'], $link_class_name, 'Two classes should be set.');
$this->assertFalse($instance['settings']['title_value'], 'By default, no title should be set.');
// Now, let's create a node with this field and make sure the link shows up:
// create page form
$field_name = 'field_' . $name;
$this->drupalGet('node/add/page');
$this->assertField($field_name . '[und][0][url]', 'URL found');
$input = array(
'title' => 'This & That',
'href' => 'http://www.example.com/',
);
$edit = array(
'title' => $field_name,
$field_name . '[und][0][title]' => $input['title'],
$field_name . '[und][0][url]' => $input['href'],
);
$this->drupalPost(NULL, $edit, t('Save'));
$url = $this->getUrl();
// change to anonymous user
$this->drupalLogout();
$this->drupalGet($url);
$this->assertRaw('This & That');
$this->assertPattern('|class\s?=\s?"' . $link_class_name . '"|', "Classes $link_class_name exist on page.");
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment