1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Test case for CCK date field mapper mappers/date.inc.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Class for testing Feeds <em>content</em> mapper.
|
10 |
|
|
*
|
11 |
|
|
* @todo: Add test method iCal
|
12 |
|
|
* @todo: Add test method for end date
|
13 |
|
|
*/
|
14 |
|
|
class FeedsMapperDateTestCase extends FeedsMapperTestCase {
|
15 |
|
|
public static function getInfo() {
|
16 |
|
|
return array(
|
17 |
|
|
'name' => 'Mapper: Date',
|
18 |
|
|
'description' => 'Test Feeds Mapper support for CCK Date fields.',
|
19 |
|
|
'group' => 'Feeds',
|
20 |
|
|
'dependencies' => array('date'),
|
21 |
|
|
);
|
22 |
|
|
}
|
23 |
|
|
|
24 |
|
|
public function setUp() {
|
25 |
|
|
parent::setUp(array('date_api', 'date'));
|
26 |
|
|
variable_set('date_default_timezone', 'UTC');
|
27 |
|
|
}
|
28 |
|
|
|
29 |
|
|
/**
|
30 |
|
|
* Basic test loading a single entry CSV file.
|
31 |
|
|
*/
|
32 |
|
|
public function test() {
|
33 |
|
|
$this->drupalGet('admin/config/regional/settings');
|
34 |
|
|
|
35 |
|
|
// Create content type.
|
36 |
|
|
$typename = $this->createContentType(array(), array(
|
37 |
|
|
'date' => 'date',
|
38 |
|
|
'datestamp' => 'datestamp',
|
39 |
|
|
//'datetime' => 'datetime', // REMOVED because the field is broken ATM.
|
40 |
|
|
));
|
41 |
|
|
|
42 |
|
|
// Hack to get date fields to not round to every 15 minutes.
|
43 |
|
|
foreach (array('date', 'datestamp') as $field) {
|
44 |
|
|
$field = 'field_' . $field;
|
45 |
|
|
$edit = array(
|
46 |
|
|
'widget_type' => 'date_select',
|
47 |
|
|
);
|
48 |
|
|
$this->drupalPost('admin/structure/types/manage/' . $typename . '/fields/' . $field . '/widget-type', $edit, 'Continue');
|
49 |
|
|
$edit = array(
|
50 |
|
|
'instance[widget][settings][increment]' => 1,
|
51 |
|
|
);
|
52 |
|
|
$this->drupalPost('admin/structure/types/manage/' . $typename . '/fields/' . $field, $edit, 'Save settings');
|
53 |
|
|
$edit = array(
|
54 |
|
|
'widget_type' => 'date_text',
|
55 |
|
|
);
|
56 |
|
|
$this->drupalPost('admin/structure/types/manage/' . $typename . '/fields/' . $field . '/widget-type', $edit, 'Continue');
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
// Create and configure importer.
|
60 |
|
|
$this->createImporterConfiguration('Date RSS', 'daterss');
|
61 |
|
|
$this->setSettings('daterss', NULL, array(
|
62 |
|
|
'content_type' => '',
|
63 |
|
|
'import_period' => FEEDS_SCHEDULE_NEVER,
|
64 |
|
|
));
|
65 |
|
|
$this->setPlugin('daterss', 'FeedsFileFetcher');
|
66 |
|
|
$this->setSettings('daterss', 'FeedsNodeProcessor', array(
|
67 |
|
|
'bundle' => $typename,
|
68 |
|
|
));
|
69 |
|
|
$this->addMappings('daterss', array(
|
70 |
|
|
0 => array(
|
71 |
|
|
'source' => 'title',
|
72 |
|
|
'target' => 'title',
|
73 |
|
|
),
|
74 |
|
|
1 => array(
|
75 |
|
|
'source' => 'description',
|
76 |
|
|
'target' => 'body',
|
77 |
|
|
),
|
78 |
|
|
2 => array(
|
79 |
|
|
'source' => 'timestamp',
|
80 |
|
|
'target' => 'field_date:start',
|
81 |
|
|
),
|
82 |
|
|
3 => array(
|
83 |
|
|
'source' => 'timestamp',
|
84 |
|
|
'target' => 'field_datestamp:start',
|
85 |
|
|
),
|
86 |
|
|
));
|
87 |
|
|
|
88 |
|
|
$edit = array(
|
89 |
|
|
'allowed_extensions' => 'rss2',
|
90 |
|
|
);
|
91 |
|
|
$this->drupalPost('admin/structure/feeds/daterss/settings/FeedsFileFetcher', $edit, 'Save');
|
92 |
|
|
|
93 |
|
|
// Import CSV file.
|
94 |
|
|
$this->importFile('daterss', $this->absolutePath() . '/tests/feeds/googlenewstz.rss2');
|
95 |
|
|
$this->assertText('Created 6 nodes');
|
96 |
|
|
|
97 |
|
|
// Check the imported nodes.
|
98 |
|
|
$values = array(
|
99 |
|
|
'01/06/2010 - 19:26',
|
100 |
|
|
'01/06/2010 - 10:21',
|
101 |
|
|
'01/06/2010 - 13:42',
|
102 |
|
|
'01/06/2010 - 06:05',
|
103 |
|
|
'01/06/2010 - 11:26',
|
104 |
|
|
'01/07/2010 - 00:26',
|
105 |
|
|
);
|
106 |
|
|
for ($i = 1; $i <= 6; $i++) {
|
107 |
|
|
$this->drupalGet("node/$i/edit");
|
108 |
|
|
$this->assertNodeFieldValue('date', $values[$i-1]);
|
109 |
|
|
$this->assertNodeFieldValue('datestamp', $values[$i-1]);
|
110 |
|
|
}
|
111 |
|
|
}
|
112 |
|
|
|
113 |
|
|
protected function getFormFieldsNames($field_name, $index) {
|
114 |
|
|
if (in_array($field_name, array('date', 'datetime', 'datestamp'))) {
|
115 |
|
|
return array("field_{$field_name}[und][{$index}][value][date]");
|
116 |
|
|
}
|
117 |
|
|
else {
|
118 |
|
|
return parent::getFormFieldsNames($field_name, $index);
|
119 |
|
|
}
|
120 |
|
|
}
|
121 |
|
|
} |