function DrupalAttributesUnitTest::testDrupalAttributes

7.x common.test DrupalAttributesUnitTest::testDrupalAttributes()

Tests that drupal_html_class() cleans the class name properly.

File

drupal/modules/simpletest/tests/common.test, line 2404
Tests for common.inc functionality.

Class

DrupalAttributesUnitTest
Tests for the format_date() function.

Code

function testDrupalAttributes() {
  // Verify that special characters are HTML encoded.
  $this->assertIdentical(drupal_attributes(array('title' => '&"\'<>')), ' title="&amp;&quot;&#039;&lt;&gt;"', 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.'));
}