Projet

Général

Profil

Paste
Télécharger (3,97 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / date / tests / DateMigrateTestCase.test @ 599a39cd

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