1 common.test CommonBackdropAttributesUnitTestCase::testBackdropAttributes()

Tests that backdrop_html_class() cleans the class name properly.

File

core/modules/simpletest/tests/common.test, line 2990
Tests for common.inc functionality.

Class

CommonBackdropAttributesUnitTestCase
Tests the backdrop_attributes() functionality.

Code

function testBackdropAttributes() {
  // Verify that special characters are HTML encoded.
  $this->assertIdentical(backdrop_attributes(array('title' => '&"\'<>')), ' title="&amp;&quot;&#039;&lt;&gt;"', 'HTML encode attribute values.');

  // Verify multi-value attributes are concatenated with spaces.
  $attributes = array('class' => array('first', 'last'));
  $this->assertIdentical(backdrop_attributes(array('class' => array('first', 'last'))), ' class="first last"', 'Concatenate multi-value attributes.');

  // Verify empty attribute values are rendered.
  $this->assertIdentical(backdrop_attributes(array('alt' => '')), ' alt=""', 'Empty attribute value #1.');
  $this->assertIdentical(backdrop_attributes(array('alt' => NULL)), ' alt=""', 'Empty attribute value #2.');

  // Verify multiple attributes are rendered.
  $attributes = array(
    'id' => 'id-test',
    'class' => array('first', 'last'),
    'alt' => 'Alternate',
  );
  $this->assertIdentical(backdrop_attributes($attributes), ' id="id-test" class="first last" alt="Alternate"', 'Multiple attributes.');

  // Verify empty attributes array is rendered.
  $this->assertIdentical(backdrop_attributes(array()), '', 'Empty attributes array.');
}