date_migrate.test 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * @file
  4. * Test for using date fields with Migrate module.
  5. */
  6. /**
  7. * Test date migration.
  8. */
  9. class DateMigrateExampleUnitTest extends DrupalWebTestCase {
  10. /**
  11. * Provides information about this test.
  12. */
  13. public static function getInfo() {
  14. return array(
  15. 'name' => 'Date Migration',
  16. 'description' => 'Test migration into date fields',
  17. 'group' => 'Date',
  18. 'dependencies' => array('migrate', 'features'),
  19. );
  20. }
  21. /**
  22. * Declars the module dependencies for the test.
  23. */
  24. function setUp() {
  25. parent::setUp('migrate', 'features', 'date', 'date_repeat',
  26. 'date_repeat_field', 'date_migrate_example');
  27. // Make sure the migration is registered.
  28. if (function_exists('migrate_static_registration')) {
  29. // Migrate 2.6 and later
  30. migrate_static_registration();
  31. }
  32. else {
  33. // Migrate 2.5 and earlier
  34. migrate_get_module_apis(TRUE);
  35. }
  36. }
  37. /**
  38. * Verify that date fields are imported correctly. When no timezone is
  39. * explicitly provided with the source data, we want the displayed time on the
  40. * Drupal site to match that in the source data. To validate that, we make
  41. * sure we have set a consistent timezone at the PHP and Drupal levels, and
  42. * that the format used on the page is not locale-dependent (no day or month
  43. * names). Then, we can just look for the desired date/time strings in the
  44. * node page.
  45. */
  46. function testDateImport() {
  47. date_default_timezone_set('America/Los_Angeles');
  48. variable_set('date_default_timezone', 'America/Los_Angeles');
  49. variable_set('date_format_medium', 'Y-m-d H:i');
  50. $migration = Migration::getInstance('DateExample');
  51. $result = $migration->processImport();
  52. $this->assertEqual($result, Migration::RESULT_COMPLETED, t('Variety term import returned RESULT_COMPLETED'));
  53. $rawnodes = node_load_multiple(FALSE, array('type' => 'date_migrate_example'), TRUE);
  54. $this->assertEqual(count($rawnodes), 2, t('Two sample nodes created'));
  55. $node = reset($rawnodes);
  56. $this->drupalGet('/node/' . $node->nid);
  57. $this->assertText('2011-05-12 19:43', t('Simple date field found'));
  58. $this->assertText('2011-06-13 18:32 to 2011-07-23 10:32', t('Date range field found'));
  59. $this->assertText('2011-07-22 12:13', t('Datestamp field found'));
  60. $this->assertText('2011-08-01 00:00 to 2011-09-01 00:00', t('Datestamp range field found'));
  61. $this->assertText('2011-11-18 15:00', t('Datetime field with +9 timezone found'));
  62. $this->assertText('2011-10-30 14:43 to 2011-12-31 17:59', t('Datetime range field with -5 timezone found'));
  63. $this->assertText('2011-11-25 09:01', t('First date repeat instance found'));
  64. $this->assertText('2011-12-09 09:01', t('Second date repeat instance found'));
  65. $this->assertNoText('2011-12-23 09:01', t('Skipped date repeat instance not found'));
  66. $this->assertText('2012-05-11 09:01', t('Last date repeat instance found'));
  67. $node = next($rawnodes);
  68. $this->drupalGet('/node/' . $node->nid);
  69. $this->assertText('2012-06-21 15:32', t('First date value found'));
  70. $this->assertText('2012-12-02 11:08', t('Second date value found'));
  71. $this->assertText('2004-02-03 01:15', t('Start for first date range found'));
  72. $this->assertText('2005-03-04 22:11', t('End for first date range found'));
  73. $this->assertText('2014-09-01 17:21', t('Start for second date range found'));
  74. $this->assertText('2015-12-23 00:01', t('End for first second range found'));
  75. }
  76. }