You are here

function ParserIcalDateTestCase::testBasic in iCal feed parser 7.2

Basic test.

Covers: mapping onto different types of date field; Start and End dates; All day events; single and multiple day.

File

tests/parser_ical_date.test, line 19
Test case for CCK ical date field text mapper.

Class

ParserIcalDateTestCase
Class for testing Feeds <em>content</em> mapper.

Code

function testBasic() {

  // Create content type for feed items.
  $fields = array(
    'pidt_date' => array(
      'type' => 'date',
      'settings' => array(
        'field[settings][enddate_get]' => 1,
      ),
    ),
    'pidt_datetime' => array(
      'type' => 'datetime',
      'settings' => array(
        'field[settings][enddate_get]' => 1,
      ),
    ),
    'pidt_datestamp' => array(
      'type' => 'datestamp',
      'settings' => array(
        'field[settings][enddate_get]' => 1,
      ),
    ),
  );
  $typename = $this
    ->createContentType(array(), $fields);

  // Create and configure feed importer.
  $this
    ->createImporterConfiguration('iCal importer', 'ical');
  $this
    ->setSettings('ical', NULL, array(
    'import_period' => FEEDS_SCHEDULE_NEVER,
  ));
  $this
    ->setPlugin('ical', 'FeedsFileFetcher');
  $this
    ->setSettings('ical', 'FeedsFileFetcher', array(
    'allowed_extensions' => 'ics ical',
  ));
  $this
    ->configureParser();
  $this
    ->setSettings('ical', 'FeedsNodeProcessor', array(
    'content_type' => $typename,
  ));
  $mappings = array(
    array(
      'source' => 'summary',
      'target' => 'title',
    ),
    array(
      'source' => 'description',
      'target' => 'body',
    ),
  );
  foreach ($fields as $name => $field) {
    $mappings[] = array(
      'source' => 'dtstart',
      'target' => "field_{$name}:start",
    );
    $mappings[] = array(
      'source' => 'dtend',
      'target' => "field_{$name}:end",
    );
  }
  $this
    ->addMappings('ical', $mappings);

  // Import iCal file
  $this
    ->importFile('ical', $this
    ->absolutePath() . '/tests/feeds/date.ics');
  $this
    ->assertText('Created 7 nodes');

  // Check dates
  $dates = array(
    // all timezone Pacific/Apia
    1 => array(
      'start' => '2009-01-31 19:30',
      'end' => '2009-01-31 20:30',
    ),
    2 => array(
      'start' => '2009-01-01 07:00',
      'end' => '2009-01-01 08:00',
    ),
    //      3 => array('start' => '2009-09-01 19:00', 'end' => '2009-09-01 20:00'), // broken but shouldn't be
    4 => array(
      'start' => '2009-09-30 08:00',
      'end' => '2009-10-01 09:00',
    ),
  );
  foreach ($dates as $nid => $date) {
    $this
      ->drupalGet("node/{$nid}/edit");
    foreach ($fields as $name => $field) {
      $this
        ->assertNodeFieldValue($name, $date['start'], array(
        0,
        'value',
      ));
      $this
        ->assertNodeFieldValue($name, $date['end'], array(
        0,
        'value2',
      ));
    }
  }
}