1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
41cc1b08
|
Assos Assos
|
* Contains FeedsMapperLinkTestCase.
|
6 |
85ad3d82
|
Assos Assos
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
41cc1b08
|
Assos Assos
|
* Test case for CCK link mapper mappers/date.inc.
|
10 |
85ad3d82
|
Assos Assos
|
*/
|
11 |
|
|
class FeedsMapperLinkTestCase extends FeedsMapperTestCase {
|
12 |
41cc1b08
|
Assos Assos
|
|
13 |
|
|
/**
|
14 |
|
|
* Title for link fields with a static title.
|
15 |
|
|
*
|
16 |
|
|
* @var string
|
17 |
|
|
*/
|
18 |
|
|
private $staticTitle;
|
19 |
|
|
|
20 |
|
|
/**
|
21 |
|
|
* Name of created content type.
|
22 |
|
|
*
|
23 |
|
|
* @var string
|
24 |
|
|
*/
|
25 |
|
|
private $contentType;
|
26 |
|
|
|
27 |
85ad3d82
|
Assos Assos
|
public static function getInfo() {
|
28 |
|
|
return array(
|
29 |
|
|
'name' => 'Mapper: Link',
|
30 |
|
|
'description' => 'Test Feeds Mapper support for Link fields.',
|
31 |
|
|
'group' => 'Feeds',
|
32 |
|
|
'dependencies' => array('link'),
|
33 |
|
|
);
|
34 |
|
|
}
|
35 |
|
|
|
36 |
|
|
public function setUp() {
|
37 |
|
|
parent::setUp(array('link'));
|
38 |
|
|
|
39 |
41cc1b08
|
Assos Assos
|
$this->staticTitle = $this->randomName();
|
40 |
85ad3d82
|
Assos Assos
|
|
41 |
|
|
// Create content type.
|
42 |
41cc1b08
|
Assos Assos
|
$this->contentType = $this->createContentType(array(), array(
|
43 |
85ad3d82
|
Assos Assos
|
'alpha' => array(
|
44 |
|
|
'type' => 'link_field',
|
45 |
|
|
'instance_settings' => array(
|
46 |
|
|
'instance[settings][title]' => 'required',
|
47 |
|
|
),
|
48 |
|
|
),
|
49 |
|
|
'beta' => array(
|
50 |
|
|
'type' => 'link_field',
|
51 |
|
|
'instance_settings' => array(
|
52 |
|
|
'instance[settings][title]' => 'none',
|
53 |
|
|
),
|
54 |
|
|
),
|
55 |
|
|
'gamma' => array(
|
56 |
|
|
'type' => 'link_field',
|
57 |
|
|
'instance_settings' => array(
|
58 |
|
|
'instance[settings][title]' => 'optional',
|
59 |
|
|
),
|
60 |
|
|
),
|
61 |
|
|
'omega' => array(
|
62 |
|
|
'type' => 'link_field',
|
63 |
|
|
'instance_settings' => array(
|
64 |
|
|
'instance[settings][title]' => 'value',
|
65 |
41cc1b08
|
Assos Assos
|
'instance[settings][title_value]' => $this->staticTitle,
|
66 |
85ad3d82
|
Assos Assos
|
),
|
67 |
|
|
),
|
68 |
|
|
));
|
69 |
41cc1b08
|
Assos Assos
|
}
|
70 |
85ad3d82
|
Assos Assos
|
|
71 |
41cc1b08
|
Assos Assos
|
/**
|
72 |
|
|
* Basic test loading a single entry CSV file.
|
73 |
|
|
*/
|
74 |
|
|
public function test() {
|
75 |
85ad3d82
|
Assos Assos
|
// Create importer configuration.
|
76 |
|
|
$this->createImporterConfiguration(); //Create a default importer configuration
|
77 |
41cc1b08
|
Assos Assos
|
$this->setSettings('syndication', 'FeedsNodeProcessor', array('bundle' => $this->contentType)); //Processor settings
|
78 |
85ad3d82
|
Assos Assos
|
$this->addMappings('syndication', array(
|
79 |
|
|
0 => array(
|
80 |
|
|
'source' => 'title',
|
81 |
|
|
'target' => 'title'
|
82 |
|
|
),
|
83 |
|
|
1 => array(
|
84 |
|
|
'source' => 'timestamp',
|
85 |
|
|
'target' => 'created'
|
86 |
|
|
),
|
87 |
|
|
2 => array(
|
88 |
|
|
'source' => 'description',
|
89 |
|
|
'target' => 'body'
|
90 |
|
|
),
|
91 |
|
|
3 => array(
|
92 |
|
|
'source' => 'url',
|
93 |
|
|
'target' => 'field_alpha:url'
|
94 |
|
|
),
|
95 |
|
|
4 => array(
|
96 |
|
|
'source' => 'title',
|
97 |
|
|
'target' => 'field_alpha:title'
|
98 |
|
|
),
|
99 |
|
|
5 => array(
|
100 |
|
|
'source' => 'url',
|
101 |
|
|
'target' => 'field_beta:url'
|
102 |
|
|
),
|
103 |
|
|
6 => array(
|
104 |
|
|
'source' => 'url',
|
105 |
|
|
'target' => 'field_gamma:url'
|
106 |
|
|
),
|
107 |
|
|
7 => array(
|
108 |
|
|
'source' => 'title',
|
109 |
|
|
'target' => 'field_gamma:title'
|
110 |
|
|
),
|
111 |
|
|
8 => array(
|
112 |
|
|
'source' => 'url',
|
113 |
|
|
'target' => 'field_omega:url'
|
114 |
|
|
),
|
115 |
|
|
));
|
116 |
|
|
|
117 |
|
|
// Import RSS file.
|
118 |
|
|
$nid = $this->createFeedNode();
|
119 |
|
|
// Assert 10 items aggregated after creation of the node.
|
120 |
|
|
$this->assertText('Created 10 nodes');
|
121 |
|
|
|
122 |
|
|
// Edit the imported node.
|
123 |
|
|
$this->drupalGet('node/2/edit');
|
124 |
|
|
|
125 |
|
|
$url = 'http://developmentseed.org/blog/2009/oct/06/open-atrium-translation-workflow-two-way-updating';
|
126 |
|
|
$title = 'Open Atrium Translation Workflow: Two Way Translation Updates';
|
127 |
|
|
$this->assertNodeFieldValue('alpha', array('url' => $url, 'static' => $title));
|
128 |
|
|
$this->assertNodeFieldValue('beta', array('url' => $url));
|
129 |
|
|
$this->assertNodeFieldValue('gamma', array('url' => $url, 'static' => $title));
|
130 |
41cc1b08
|
Assos Assos
|
$this->assertNodeFieldValue('omega', array('url' => $url, 'static' => $this->staticTitle));
|
131 |
85ad3d82
|
Assos Assos
|
|
132 |
|
|
// Test the static title.
|
133 |
|
|
$this->drupalGet('node/2');
|
134 |
41cc1b08
|
Assos Assos
|
$this->assertText($this->staticTitle, 'Static title link found.');
|
135 |
|
|
}
|
136 |
|
|
|
137 |
|
|
/**
|
138 |
|
|
* Tests if values are cleared out when an empty value or no value
|
139 |
|
|
* is provided.
|
140 |
|
|
*/
|
141 |
|
|
public function testClearOutValues() {
|
142 |
|
|
// Create and configure importer.
|
143 |
|
|
$this->createImporterConfiguration('Content CSV', 'csv');
|
144 |
|
|
$this->setSettings('csv', NULL, array(
|
145 |
|
|
'content_type' => '',
|
146 |
|
|
'import_period' => FEEDS_SCHEDULE_NEVER,
|
147 |
|
|
));
|
148 |
|
|
$this->setPlugin('csv', 'FeedsFileFetcher');
|
149 |
|
|
$this->setPlugin('csv', 'FeedsCSVParser');
|
150 |
|
|
$this->setSettings('csv', 'FeedsNodeProcessor', array(
|
151 |
|
|
'bundle' => $this->contentType,
|
152 |
|
|
'update_existing' => 1,
|
153 |
|
|
));
|
154 |
|
|
$this->addMappings('csv', array(
|
155 |
|
|
0 => array(
|
156 |
|
|
'source' => 'guid',
|
157 |
|
|
'target' => 'guid',
|
158 |
|
|
'unique' => TRUE,
|
159 |
|
|
),
|
160 |
|
|
1 => array(
|
161 |
|
|
'source' => 'title',
|
162 |
|
|
'target' => 'title'
|
163 |
|
|
),
|
164 |
|
|
2 => array(
|
165 |
|
|
'source' => 'url',
|
166 |
|
|
'target' => 'field_alpha:url'
|
167 |
|
|
),
|
168 |
|
|
3 => array(
|
169 |
|
|
'source' => 'link_title',
|
170 |
|
|
'target' => 'field_alpha:title'
|
171 |
|
|
),
|
172 |
|
|
4 => array(
|
173 |
|
|
'source' => 'url',
|
174 |
|
|
'target' => 'field_beta:url'
|
175 |
|
|
),
|
176 |
|
|
5 => array(
|
177 |
|
|
'source' => 'link_title',
|
178 |
|
|
'target' => 'field_beta:title'
|
179 |
|
|
),
|
180 |
|
|
6 => array(
|
181 |
|
|
'source' => 'url',
|
182 |
|
|
'target' => 'field_gamma:url'
|
183 |
|
|
),
|
184 |
|
|
7 => array(
|
185 |
|
|
'source' => 'link_title',
|
186 |
|
|
'target' => 'field_gamma:title'
|
187 |
|
|
),
|
188 |
|
|
8 => array(
|
189 |
|
|
'source' => 'url',
|
190 |
|
|
'target' => 'field_omega:url'
|
191 |
|
|
),
|
192 |
|
|
9 => array(
|
193 |
|
|
'source' => 'link_title',
|
194 |
|
|
'target' => 'field_omega:title'
|
195 |
|
|
),
|
196 |
|
|
));
|
197 |
|
|
|
198 |
|
|
// Import CSV file.
|
199 |
|
|
$this->importFile('csv', $this->absolutePath() . '/tests/feeds/content_link.csv');
|
200 |
|
|
$this->assertText('Created 2 nodes');
|
201 |
|
|
|
202 |
|
|
// Check the imported nodes.
|
203 |
|
|
$link_values = array(
|
204 |
|
|
1 => array(
|
205 |
|
|
'title' => 'Feeds',
|
206 |
|
|
'url' => 'https://www.drupal.org/project/feeds',
|
207 |
|
|
),
|
208 |
|
|
2 => array(
|
209 |
|
|
'title' => 'Framework for expected behavior when importing empty/blank values',
|
210 |
|
|
'url' => 'https://www.drupal.org/node/1107522',
|
211 |
|
|
),
|
212 |
|
|
);
|
213 |
|
|
|
214 |
|
|
for ($i = 1; $i <= 2; $i++) {
|
215 |
|
|
$this->drupalGet("node/$i/edit");
|
216 |
|
|
$this->assertNodeFieldValue('alpha', array(
|
217 |
|
|
'url' => $link_values[$i]['url'],
|
218 |
|
|
'title' => $link_values[$i]['title'],
|
219 |
|
|
));
|
220 |
|
|
$this->assertNodeFieldValue('beta', array(
|
221 |
|
|
'url' => $link_values[$i]['url'],
|
222 |
|
|
));
|
223 |
|
|
$this->assertNodeFieldValue('gamma', array(
|
224 |
|
|
'url' => $link_values[$i]['url'],
|
225 |
|
|
'title' => $link_values[$i]['title'],
|
226 |
|
|
));
|
227 |
|
|
$this->assertNodeFieldValue('omega', array(
|
228 |
|
|
'url' => $link_values[$i]['url'],
|
229 |
|
|
));
|
230 |
|
|
|
231 |
|
|
// Test static title.
|
232 |
|
|
$this->drupalGet("node/$i");
|
233 |
|
|
$this->assertText($this->staticTitle, 'Static title link found.');
|
234 |
|
|
}
|
235 |
|
|
|
236 |
|
|
// Import CSV file with empty values.
|
237 |
|
|
$this->importFile('csv', $this->absolutePath() . '/tests/feeds/content_empty.csv');
|
238 |
|
|
$this->assertText('Updated 2 nodes');
|
239 |
|
|
|
240 |
|
|
// Check if all values were cleared out for both nodes.
|
241 |
|
|
for ($i = 1; $i <= 2; $i++) {
|
242 |
|
|
$this->drupalGet("node/$i/edit");
|
243 |
|
|
$this->assertNoNodeFieldValue('alpha', array(
|
244 |
|
|
'url' => $link_values[$i]['url'],
|
245 |
|
|
'title' => $link_values[$i]['title'],
|
246 |
|
|
));
|
247 |
|
|
$this->assertNoNodeFieldValue('beta', array(
|
248 |
|
|
'url' => $link_values[$i]['url'],
|
249 |
|
|
));
|
250 |
|
|
$this->assertNoNodeFieldValue('gamma', array(
|
251 |
|
|
'url' => $link_values[$i]['url'],
|
252 |
|
|
'title' => $link_values[$i]['title'],
|
253 |
|
|
));
|
254 |
|
|
$this->assertNoNodeFieldValue('omega', array(
|
255 |
|
|
'url' => $link_values[$i]['url'],
|
256 |
|
|
));
|
257 |
|
|
// Check labels.
|
258 |
|
|
$this->drupalGet('node/' . $i);
|
259 |
|
|
$this->assertNoText('alpha_link_field_label');
|
260 |
|
|
$this->assertNoText('beta_link_field_label');
|
261 |
|
|
$this->assertNoText('gamma_link_field_label');
|
262 |
|
|
$this->assertNoText('omega_link_field_label');
|
263 |
|
|
|
264 |
|
|
// Assert that the static title is no longer shown.
|
265 |
|
|
$this->assertNoText($this->staticTitle, 'Static title link not found.');
|
266 |
|
|
}
|
267 |
|
|
|
268 |
|
|
// Re-import the first file again and check if the values returned.
|
269 |
|
|
$this->importFile('csv', $this->absolutePath() . '/tests/feeds/content_link.csv');
|
270 |
|
|
$this->assertText('Updated 2 nodes');
|
271 |
|
|
for ($i = 1; $i <= 2; $i++) {
|
272 |
|
|
$this->drupalGet("node/$i/edit");
|
273 |
|
|
$this->assertNodeFieldValue('alpha', array(
|
274 |
|
|
'url' => $link_values[$i]['url'],
|
275 |
|
|
'title' => $link_values[$i]['title'],
|
276 |
|
|
));
|
277 |
|
|
$this->assertNodeFieldValue('beta', array(
|
278 |
|
|
'url' => $link_values[$i]['url'],
|
279 |
|
|
));
|
280 |
|
|
$this->assertNodeFieldValue('gamma', array(
|
281 |
|
|
'url' => $link_values[$i]['url'],
|
282 |
|
|
'title' => $link_values[$i]['title'],
|
283 |
|
|
));
|
284 |
|
|
$this->assertNodeFieldValue('omega', array(
|
285 |
|
|
'url' => $link_values[$i]['url'],
|
286 |
|
|
));
|
287 |
|
|
}
|
288 |
|
|
|
289 |
|
|
// Import CSV file with non-existent values.
|
290 |
|
|
$this->importFile('csv', $this->absolutePath() . '/tests/feeds/content_non_existent.csv');
|
291 |
|
|
$this->assertText('Updated 2 nodes');
|
292 |
|
|
|
293 |
|
|
// Check if all values were cleared out for node 1.
|
294 |
|
|
$this->drupalGet("node/1/edit");
|
295 |
|
|
$this->assertNoNodeFieldValue('alpha', array(
|
296 |
|
|
'url' => $link_values[1]['url'],
|
297 |
|
|
'title' => $link_values[1]['title'],
|
298 |
|
|
));
|
299 |
|
|
$this->assertNoNodeFieldValue('beta', array(
|
300 |
|
|
'url' => $link_values[1]['url'],
|
301 |
|
|
));
|
302 |
|
|
$this->assertNoNodeFieldValue('gamma', array(
|
303 |
|
|
'url' => $link_values[1]['url'],
|
304 |
|
|
'title' => $link_values[1]['title'],
|
305 |
|
|
));
|
306 |
|
|
$this->assertNoNodeFieldValue('omega', array(
|
307 |
|
|
'url' => $link_values[1]['url'],
|
308 |
|
|
));
|
309 |
|
|
$this->drupalGet('node/1');
|
310 |
|
|
$this->assertNoText('alpha_link_field_label');
|
311 |
|
|
$this->assertNoText('beta_link_field_label');
|
312 |
|
|
$this->assertNoText('gamma_link_field_label');
|
313 |
|
|
$this->assertNoText('omega_link_field_label');
|
314 |
85ad3d82
|
Assos Assos
|
|
315 |
41cc1b08
|
Assos Assos
|
// Assert that the static title is no longer shown.
|
316 |
|
|
$this->assertNoText($this->staticTitle, 'Static title link not found.');
|
317 |
85ad3d82
|
Assos Assos
|
}
|
318 |
|
|
|
319 |
|
|
/**
|
320 |
|
|
* Override parent::getFormFieldsNames().
|
321 |
|
|
*/
|
322 |
|
|
protected function getFormFieldsNames($field_name, $index) {
|
323 |
|
|
if (in_array($field_name, array('alpha', 'beta', 'gamma', 'omega'))) {
|
324 |
|
|
$fields = array("field_{$field_name}[und][{$index}][url]");
|
325 |
|
|
if (in_array($field_name, array('alpha', 'gamma'))) {
|
326 |
|
|
$fields[] = "field_{$field_name}[und][{$index}][title]";
|
327 |
|
|
}
|
328 |
|
|
return $fields;
|
329 |
|
|
}
|
330 |
|
|
else {
|
331 |
|
|
return parent::getFormFieldsNames($field_name, $index);
|
332 |
|
|
}
|
333 |
|
|
}
|
334 |
|
|
|
335 |
|
|
/**
|
336 |
|
|
* Override parent::getFormFieldsValues().
|
337 |
|
|
*/
|
338 |
|
|
protected function getFormFieldsValues($field_name, $value) {
|
339 |
|
|
if (in_array($field_name, array('alpha', 'beta', 'gamma', 'omega'))) {
|
340 |
|
|
if (!is_array($value)) {
|
341 |
|
|
$value = array('url' => $value);
|
342 |
|
|
}
|
343 |
|
|
$values = array($value['url']);
|
344 |
|
|
if (in_array($field_name, array('alpha', 'gamma'))) {
|
345 |
|
|
$values[] = isset($value['title']) ? $value['title'] : '';
|
346 |
|
|
}
|
347 |
|
|
return $values;
|
348 |
|
|
}
|
349 |
|
|
else {
|
350 |
|
|
return parent::getFormFieldsValues($field_name, $index);
|
351 |
|
|
}
|
352 |
|
|
}
|
353 |
41cc1b08
|
Assos Assos
|
|
354 |
85ad3d82
|
Assos Assos
|
} |