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