1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Contains FeedsMapperNodeSummaryTestCase.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Test case for mapping to node summary.
|
10
|
*/
|
11
|
class FeedsMapperNodeSummaryTestCase extends FeedsMapperTestCase {
|
12
|
|
13
|
/**
|
14
|
* {@inheritdoc}
|
15
|
*/
|
16
|
public static function getInfo() {
|
17
|
return array(
|
18
|
'name' => 'Mapper: Text with summary',
|
19
|
'description' => 'Test Feeds Mapper support for text with summary fields.',
|
20
|
'group' => 'Feeds',
|
21
|
);
|
22
|
}
|
23
|
|
24
|
/**
|
25
|
* Tests importing CSV files for text fields with summary.
|
26
|
*/
|
27
|
public function test() {
|
28
|
// Create and configure importer.
|
29
|
$this->createImporterWithSummaryMapper();
|
30
|
|
31
|
// Create a new filter format.
|
32
|
$format = drupal_strtolower($this->randomName());
|
33
|
$edit = array(
|
34
|
'format' => $format,
|
35
|
'name' => $this->randomName(),
|
36
|
// Authenticated users.
|
37
|
'roles[2]' => TRUE,
|
38
|
);
|
39
|
$this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration'));
|
40
|
|
41
|
// The "update existing" and "skip hash check" are turned on so we can test
|
42
|
// later if the summaries of the nodes get overwritten with the values from
|
43
|
// the source.
|
44
|
$this->setSettings('syndication', 'FeedsNodeProcessor', array(
|
45
|
'update_existing' => 2,
|
46
|
'skip_hash_check' => TRUE,
|
47
|
'input_format' => $format,
|
48
|
));
|
49
|
|
50
|
// Import CSV file.
|
51
|
$this->importFile('syndication', $this->absolutePath() . '/tests/feeds/node_summary.csv');
|
52
|
$this->assertText('Created 3 nodes');
|
53
|
$this->assertNodeSummaryValues();
|
54
|
|
55
|
// Check that text format is applied correctly.
|
56
|
$this->drupalGet('node/1/edit');
|
57
|
$this->assertNodeFieldValue('format', $format);
|
58
|
|
59
|
// Check the teasers of the three imported nodes, assumed to be all present
|
60
|
// on the front page.
|
61
|
$this->assertNodeTeaserValues();
|
62
|
|
63
|
// Set a summary and a text for each imported node.
|
64
|
$edit = array(
|
65
|
'body[und][0][summary]' => 'Nam liber tempor summary',
|
66
|
'body[und][0][value]' => 'Nam liber tempor body',
|
67
|
);
|
68
|
$this->drupalPost('node/1/edit', $edit, t('Save'));
|
69
|
$this->drupalPost('node/2/edit', $edit, t('Save'));
|
70
|
$this->drupalPost('node/3/edit', $edit, t('Save'));
|
71
|
|
72
|
// Import the same CSV file again.
|
73
|
$this->importFile('syndication', $this->absolutePath() . '/tests/feeds/node_summary.csv');
|
74
|
$this->assertText('Updated 3 nodes');
|
75
|
$this->assertNodeSummaryValues();
|
76
|
$this->assertNodeTeaserValues();
|
77
|
|
78
|
// The previous texts of the nodes should no longer be visible.
|
79
|
$this->assertNoText('Nam liber tempor summary');
|
80
|
$this->assertNoText('Nam liber tempor body');
|
81
|
|
82
|
// Check that text format is applied correctly.
|
83
|
$this->drupalGet('node/1/edit');
|
84
|
$this->assertNodeFieldValue('format', $format);
|
85
|
$this->drupalGet('node/2/edit');
|
86
|
$this->assertNodeFieldValue('format', $format);
|
87
|
$this->drupalGet('node/3/edit');
|
88
|
$this->assertNodeFieldValue('format', $format);
|
89
|
|
90
|
// Remove the body mapping to check that the text format doesn't get updated
|
91
|
// from the summary.
|
92
|
$this->removeMappings('syndication', array(
|
93
|
2 => array(
|
94
|
'source' => 'body',
|
95
|
'target' => 'body',
|
96
|
),
|
97
|
));
|
98
|
|
99
|
// Change the text format and remove the body mapping to ensure that the
|
100
|
// text format doesn't change.
|
101
|
$this->setSettings('syndication', 'FeedsNodeProcessor', array(
|
102
|
'input_format' => 'plain_text',
|
103
|
));
|
104
|
$this->importFile('syndication', $this->absolutePath() . '/tests/feeds/node_summary.csv');
|
105
|
$this->assertText('Updated 3 nodes');
|
106
|
|
107
|
// Check that text format remains at its previous value.
|
108
|
$this->drupalGet('node/1/edit');
|
109
|
$this->assertNodeFieldValue('format', $format);
|
110
|
$this->drupalGet('node/2/edit');
|
111
|
$this->assertNodeFieldValue('format', $format);
|
112
|
$this->drupalGet('node/3/edit');
|
113
|
$this->assertNodeFieldValue('format', $format);
|
114
|
}
|
115
|
|
116
|
/**
|
117
|
* Creates an importer with a summary mapper.
|
118
|
*
|
119
|
* @param $name
|
120
|
* The natural name of the feed.
|
121
|
* @param $id
|
122
|
* The persistent id of the feed.
|
123
|
*
|
124
|
* @return void
|
125
|
*/
|
126
|
protected function createImporterWithSummaryMapper($name = 'Syndication', $id = 'syndication') {
|
127
|
// Create content type. A field named "body" which is of type "Long text and summary"
|
128
|
// will be created by default, so we don't need to create a field of that type here.
|
129
|
$typename = $this->createContentType(array());
|
130
|
|
131
|
// Create and configure importer.
|
132
|
$this->createImporterConfiguration($name, $id);
|
133
|
$this->setSettings('syndication', NULL, array(
|
134
|
'content_type' => '',
|
135
|
'import_period' => FEEDS_SCHEDULE_NEVER,
|
136
|
));
|
137
|
$this->setPlugin('syndication', 'FeedsFileFetcher');
|
138
|
$this->setPlugin('syndication', 'FeedsCSVParser');
|
139
|
$this->setSettings('syndication', 'FeedsNodeProcessor', array('bundle' => $typename));
|
140
|
$this->addMappings('syndication', array(
|
141
|
0 => array(
|
142
|
'source' => 'title',
|
143
|
'target' => 'title',
|
144
|
),
|
145
|
1 => array(
|
146
|
'source' => 'summary',
|
147
|
'target' => 'body:summary',
|
148
|
),
|
149
|
2 => array(
|
150
|
'source' => 'body',
|
151
|
'target' => 'body',
|
152
|
),
|
153
|
3 => array(
|
154
|
'source' => 'guid',
|
155
|
'target' => 'guid',
|
156
|
'unique' => TRUE,
|
157
|
),
|
158
|
));
|
159
|
}
|
160
|
|
161
|
/**
|
162
|
* Overrides FeedsMapperTestCase::getFormFieldsNames().
|
163
|
*
|
164
|
* Returns different form field names for:
|
165
|
* - body
|
166
|
* This field doesn't have the "field_" prefix.
|
167
|
* - summary
|
168
|
* Which is part of the body field.
|
169
|
* - format
|
170
|
* The format of the body field.
|
171
|
*/
|
172
|
protected function getFormFieldsNames($field_name, $index) {
|
173
|
switch ($field_name) {
|
174
|
case 'body':
|
175
|
return array("body[und][{$index}][value]");
|
176
|
|
177
|
case 'summary':
|
178
|
return array("body[und][{$index}][summary]");
|
179
|
|
180
|
case 'format':
|
181
|
return array("body[und][{$index}][format]");
|
182
|
}
|
183
|
|
184
|
return parent::getFormFieldsNames($field_name, $index);
|
185
|
}
|
186
|
|
187
|
/**
|
188
|
* Checks that the nodes match the imported values.
|
189
|
*/
|
190
|
protected function assertNodeSummaryValues() {
|
191
|
// Check the three imported nodes.
|
192
|
$this->drupalGet('node/1/edit');
|
193
|
$this->assertNodeFieldValue('summary', 'Lorem ipsum summary');
|
194
|
$this->assertNodeFieldValue('body', 'Lorem ipsum body');
|
195
|
$this->drupalGet('node/2/edit');
|
196
|
$this->assertNodeFieldValue('summary', '');
|
197
|
$this->assertNodeFieldValue('body', 'Ut wisi enim ad minim veniam body');
|
198
|
$this->drupalGet('node/3/edit');
|
199
|
$this->assertNodeFieldValue('summary', '');
|
200
|
$this->assertNodeFieldValue('body', '');
|
201
|
}
|
202
|
|
203
|
/**
|
204
|
* Checks the frontpage for teaser values.
|
205
|
*/
|
206
|
protected function assertNodeTeaserValues() {
|
207
|
$this->drupalGet('');
|
208
|
$this->assertText('Lorem ipsum summary');
|
209
|
$this->assertNoText('Lorem ipsum body');
|
210
|
$this->assertText('Ut wisi enim ad minim veniam body');
|
211
|
}
|
212
|
|
213
|
}
|