Newer
Older
eiriksm
committed
<?php
/**
* @file
* Contains FeedsMapperDateMultipleTestCase.
eiriksm
committed
*/
/**
* Test case for CCK date multi-field mapper mappers/date.inc.
eiriksm
committed
*
* @todo: Add test method iCal
* @todo: Add test method for end date
*/
class FeedsMapperDateMultipleTestCase extends FeedsMapperTestCase {
eiriksm
committed
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
public static function getInfo() {
return array(
'name' => 'Mapper: Date, multi value fields',
'description' => 'Test Feeds Mapper support for CCK multi valiue Date fields.',
'group' => 'Feeds',
'dependencies' => array('date', 'feeds_xpathparser'),
);
}
public function setUp() {
parent::setUp(array('date_api', 'date', 'feeds_xpathparser'));
variable_set('date_default_timezone', 'UTC');
}
/**
* Testing import by loading a 4 item XML file.
*/
public function test() {
$this->drupalGet('admin/config/regional/settings');
// Create content type.
$typename = $this->createContentType(array(), array(
'date' => 'date',
));
// Make the field hold unlimited values
$edit = array(
'field[cardinality]' => -1,
);
$this->drupalPost('admin/structure/types/manage/' . $typename . '/fields/field_date', $edit, 'Save settings');
$this->assertText('Saved date_date_label configuration');
// Create and configure importer.
$this->createImporterConfiguration('Multi dates', 'multidates');
$this->setSettings('multidates', NULL, array(
'content_type' => '',
'import_period' => FEEDS_SCHEDULE_NEVER,
));
$this->setPlugin('multidates', 'FeedsFileFetcher');
$this->setPlugin('multidates', 'FeedsXPathParserXML');
$this->setSettings('multidates', 'FeedsNodeProcessor', array(
'bundle' => $typename,
));
$this->addMappings('multidates', array(
0 => array(
'source' => 'xpathparser:0',
'target' => 'title',
),
1 => array(
'source' => 'xpathparser:1',
'target' => 'guid',
),
2 => array(
'source' => 'xpathparser:2',
'target' => 'field_date:start',
),
));
$edit = array(
'xpath[context]' => '//item',
'xpath[sources][xpathparser:0]' => 'title',
'xpath[sources][xpathparser:1]' => 'guid',
'xpath[sources][xpathparser:2]' => 'date',
'xpath[allow_override]' => FALSE,
);
$this->setSettings('multidates', 'FeedsXPathParserXML', $edit);
$edit = array(
'allowed_extensions' => 'xml',
'directory' => 'public://feeds',
);
$this->setSettings('multidates', 'FeedsFileFetcher', $edit);
// Import XML file.
$this->importFile('multidates', $this->absolutePath() . '/tests/feeds/multi-date.xml');
$this->assertText('Created 4 nodes');
// Check the imported nodes.
$values = array(
1 => array(
'01/06/2010 - 15:00',
'01/07/2010 - 15:15',
),
2 => array(
'01/06/2010 - 15:00',
'01/07/2010 - 15:00',
'01/08/2010 - 15:00',
'01/09/2010 - 15:00',
),
3 => array(
'', // Bogus date was filtered out.
),
4 => array(
'01/06/2010 - 14:00',
)
);
foreach ($values as $v => $key) {
$this->drupalGet("node/$v/edit");
foreach ($key as $delta => $value) {
megachriz
committed
$id = 'edit-field-date-und-' . $delta . '-value-date';
// Find actual value.
$xpath = $this->constructFieldXpath('id', $id);
$fields = $this->xpath($xpath);
$field = reset($fields);
$actual = (string) $field['value'];
// Compose assert message.
$message = format_string('Found field by id @id with value @value (actual: @actual).', array(
'@id' => $id,
'@value' => $value,
'@actual' => $actual,
));
$this->assertFieldById($id, $value, $message);
eiriksm
committed
}
}
}