| 7 common.test | DrupalAttributesUnitTest::testDrupalAttributes() |
Tests that drupal_html_class() cleans the class name properly.
File
- modules/
simpletest/ tests/ common.test, line 2388 - Tests for common.inc functionality.
Code
function testDrupalAttributes() {
// Verify that special characters are HTML encoded.
$this->assertIdentical(drupal_attributes(array('title' => '&"\'<>')), ' title="&"'<>"', t('HTML encode attribute values.'));
// Verify multi-value attributes are concatenated with spaces.
$attributes = array('class' => array('first', 'last'));
$this->assertIdentical(drupal_attributes(array('class' => array('first', 'last'))), ' class="first last"', t('Concatenate multi-value attributes.'));
// Verify empty attribute values are rendered.
$this->assertIdentical(drupal_attributes(array('alt' => '')), ' alt=""', t('Empty attribute value #1.'));
$this->assertIdentical(drupal_attributes(array('alt' => NULL)), ' alt=""', t('Empty attribute value #2.'));
// Verify multiple attributes are rendered.
$attributes = array(
'id' => 'id-test',
'class' => array('first', 'last'),
'alt' => 'Alternate',
);
$this->assertIdentical(drupal_attributes($attributes), ' id="id-test" class="first last" alt="Alternate"', t('Multiple attributes.'));
// Verify empty attributes array is rendered.
$this->assertIdentical(drupal_attributes(array()), '', t('Empty attributes array.'));
}
Login or register to post comments