1 theme.test ThemeDatetime::testThemeDatetime()

Test function theme_datetime().

File

core/modules/simpletest/tests/theme.test, line 779
Tests for the theme API.

Class

ThemeDatetime
Tests for theme_datetime().

Code

function testThemeDatetime() {
  // Create timestamp and formatted date for testing.
  $timestamp = 1421394600;
  $date = format_date($timestamp);

  // Test with timestamp.
  $variables = array(
    'timestamp' => $timestamp,
  );
  $this->assertEqual('<time datetime="2015-01-16T07:50:00+0000">' . $date . '</time>', theme('datetime', $variables));

  // Test with text and timestamp.
  $variables = array(
    'timestamp' => $timestamp,
    'text' => "Backdrop's birthday",
  );
  $this->assertEqual('<time datetime="2015-01-16T07:50:00+0000">Backdrop&#039;s birthday</time>', theme('datetime', $variables));

  // Test with datetime attribute.
  $variables = array(
    'attributes' => array(
      'datetime' => '2015-01-16',
    ),
  );
  $this->assertEqual('<time datetime="2015-01-16">2015-01-16</time>', theme('datetime', $variables));

  // Test with text and datetime attribute.
  $variables = array(
    'text' => "Backdrop's birthday",
    'attributes' => array(
      'datetime' => '2015-01-16',
    ),
  );
  $this->assertEqual('<time datetime="2015-01-16">Backdrop&#039;s birthday</time>', theme('datetime', $variables));

  // Test with HTML text.
  $variables = array(
    'timestamp' => $timestamp,
    'text' => "<span>Backdrop's birthday</span>",
    'html' => TRUE,
  );
  $this->assertEqual('<time datetime="2015-01-16T07:50:00+0000"><span>Backdrop\'s birthday</span></time>', theme('datetime', $variables));
}