You are here

date.test in Migrate Extras 6.2

File

tests/date.test
View source
<?php

/**
 * Test date migration.
 */
class MigrateExtrasDateUnitTest extends DrupalWebTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Date migration',
      'description' => 'Test migration of date fields',
      'group' => 'Migrate',
    );
  }
  function setUp() {
    parent::setUp('autoload', 'dbtng', 'migrate', 'migrate_extras', 'content', 'features', 'date_api', 'date_timezone', 'date', 'date_repeat', 'migrate_extras_date');
    drupal_flush_all_caches();
  }

  /**
   * Verify that date fields are imported correctly. When no timezone is explicitly
   * provided with the source data, we want the displayed time on the Drupal site
   * to match that in the source data. To validate that, we make sure we have set
   * a consistent timezone at the PHP and Drupal levels, and that the format used
   * on the page is not locale-dependent (no day or month names). Then, we can just
   * look for the desired date/time strings in the node page.
   */
  function testDateImport() {
    date_default_timezone_set('America/Los_Angeles');
    variable_set('date_default_timezone_name', 'America/Los_Angeles');
    variable_set('date_format_medium', 'Y-m-d H:i');
    $migration = Migration::getInstance('MigrateExampleDate');
    $result = $migration
      ->processImport();
    $this
      ->assertEqual($result, Migration::RESULT_COMPLETED, t('Date import returned RESULT_COMPLETED'));
    $nids = db_select('node', 'n')
      ->fields('n', array(
      'nid',
    ))
      ->condition('type', 'migrate_example_date')
      ->execute()
      ->fetchCol();
    $rawnodes = array();
    foreach ($nids as $nid) {
      $rawnodes[] = node_load($nid);
    }
    if (empty($rawnodes)) {
      $messages = db_select('migrate_message_migrateexampledate', 'd')
        ->fields('d', array(
        'message',
      ))
        ->execute()
        ->fetchCol();
      foreach ($messages as $message) {
        $this
          ->error($message);
      }
    }
    $this
      ->assertEqual(count($rawnodes), 2, t('Two sample nodes created'));
    $node = reset($rawnodes);
    $this
      ->drupalGet('/node/' . $node->nid);
    $this
      ->assertText('2011-05-12 19:43', t('Simple date field found'));
    $this
      ->assertText('2011-06-13 18:32 - 2011-07-23 10:32', t('Date range field found'));
    $this
      ->assertText('2011-07-22 12:13', t('Datestamp field found'));
    $this
      ->assertText('2011-08-01 (All day) - 2011-09-01 (All day)', t('Datestamp range field found'));
    $this
      ->assertText('2011-11-18 15:00', t('Datetime field with +9 timezone found'));
    $this
      ->assertText('2011-10-30 14:43 - 2011-12-31 18:59', t('Datetime range field with -5 timezone found'));
    $this
      ->assertText('2011-11-25 09:01', t('First date repeat instance found'));
    $this
      ->assertText('2011-12-09 09:01', t('Second date repeat instance found'));
    $this
      ->assertNoText('2011-12-23 09:01', t('Skipped date repeat instance not found'));
    $this
      ->assertText('2012-05-11 09:01', t('Last date repeat instance found'));
    $node = next($rawnodes);
    $this
      ->drupalGet('/node/' . $node->nid);
    $this
      ->assertText('2012-06-21 15:32', t('First date value found'));
    $this
      ->assertText('2012-12-02 11:08', t('Second date value found'));
    $this
      ->assertText('2004-02-03 01:15', t('From for first date range found'));
    $this
      ->assertText('2005-03-04 22:11', t('To for first date range found'));
    $this
      ->assertText('2014-09-01 17:21', t('From for second date range found'));
    $this
      ->assertText('2015-12-23 00:01', t('to for first second range found'));
  }

}

Classes

Namesort descending Description
MigrateExtrasDateUnitTest Test date migration.