You are here

public function DateTestCase::testMarkup in Microdata 7

Tests whether microdata is correctly outputted, depending on the field formatter type.

File

modules/date/date.test, line 141
Tests for Date module.

Class

DateTestCase
Test Date module microdata placement.

Code

public function testMarkup() {
  $date_start = strtotime("10/07/2010T10:30");
  $date_end = strtotime("10/08/2010T10:30");
  $node = $this
    ->drupalCreateNode(array(
    'type' => $this->bundleType,
    'promote' => 1,
  ));
  foreach ($this->dateTypes as $date_type) {
    foreach ($this->fieldFormatterTypes as $type) {
      $edit["{$date_type}_{$type}[und][0][value][year]"] = date('Y', $date_start);
      $edit["{$date_type}_{$type}[und][0][value][month]"] = date('m', $date_start);
      $edit["{$date_type}_{$type}[und][0][value][day]"] = date('j', $date_start);
      $edit["{$date_type}_{$type}[und][0][value][hour]"] = date('H', $date_start);
      $edit["{$date_type}_{$type}[und][0][value][minute]"] = date('i', $date_start);
      $edit["{$date_type}_{$type}[und][0][show_todate]"] = '1';
      $edit["{$date_type}_{$type}[und][0][value2][year]"] = date('Y', $date_end);
      $edit["{$date_type}_{$type}[und][0][value2][month]"] = date('m', $date_end);
      $edit["{$date_type}_{$type}[und][0][value2][day]"] = date('j', $date_end);
      $edit["{$date_type}_{$type}[und][0][value2][hour]"] = date('H', $date_end);
      $edit["{$date_type}_{$type}[und][0][value2][minute]"] = date('i', $date_end);
    }
  }
  $edit["single_date[und][0][value][year]"] = date('Y', $date_start);
  $edit["single_date[und][0][value][month]"] = date('m', $date_start);
  $edit["single_date[und][0][value][day]"] = date('j', $date_start);
  $edit["single_date[und][0][value][hour]"] = date('H', $date_start);
  $edit["single_date[und][0][value][minute]"] = date('i', $date_start);
  $this
    ->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));

  // Get the microdata result for the page.
  $md = $this
    ->parseMicrodata();

  // Get the entity as a microdata item.
  $item = $md->items[0];
  foreach ($this->dateTypes as $date_type) {
    foreach ($this->fieldFormatterTypes as $type) {
      $text_itemprop = "{$date_type}_{$type}_start";
      $this
        ->assertEqual($this
        ->iso8601($date_start), $item->properties[$text_itemprop][0], "Itemprop is placed on {$text_itemprop}");
      $text_itemprop = "{$date_type}_{$type}_end";
      $this
        ->assertEqual($this
        ->iso8601($date_end), $item->properties[$text_itemprop][0], "Itemprop is placed on {$text_itemprop}");
    }
  }

  // Single date.
  $text_itemprop = "single_date_start";
  $this
    ->assertTrue(array_search($this
    ->iso8601($date_start), $item->properties[$text_itemprop]) !== FALSE, "Itemprop is placed on single date.");
  $this
    ->assertTrue(count($item->properties[$text_itemprop]) == 1, "Only machine readable value found for single date.");
  $text_itemprop = "single_date_end";
  $this
    ->assertTrue(!isset($item->properties[$text_itemprop][0]), "Microdata is not placed for single date ending value.");
}