1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Helper module for Feeds tests.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Implements hook_menu().
|
10
|
*/
|
11
|
function feeds_tests_menu() {
|
12
|
$items['testing/feeds/flickr.xml'] = array(
|
13
|
'page callback' => 'feeds_tests_flickr',
|
14
|
'access arguments' => array('access content'),
|
15
|
'type' => MENU_CALLBACK,
|
16
|
);
|
17
|
$items['testing/feeds/files.csv'] = array(
|
18
|
'page callback' => 'feeds_tests_files',
|
19
|
'access arguments' => array('access content'),
|
20
|
'type' => MENU_CALLBACK,
|
21
|
);
|
22
|
$items['testing/feeds/files-remote.csv'] = array(
|
23
|
'page callback' => 'feeds_tests_files_remote',
|
24
|
'access arguments' => array('access content'),
|
25
|
'type' => MENU_CALLBACK,
|
26
|
);
|
27
|
$items['testing/feeds/files-empty-alt-title.csv'] = array(
|
28
|
'page callback' => 'feeds_tests_files_empty_alt_title',
|
29
|
'access arguments' => array('access content'),
|
30
|
'type' => MENU_CALLBACK,
|
31
|
);
|
32
|
$items['testing/feeds/files-empty.csv'] = array(
|
33
|
'page callback' => 'feeds_tests_files_empty',
|
34
|
'access arguments' => array('access content'),
|
35
|
'type' => MENU_CALLBACK,
|
36
|
);
|
37
|
$items['testing/feeds/nodes.csv'] = array(
|
38
|
'page callback' => 'feeds_tests_nodes',
|
39
|
'access arguments' => array('access content'),
|
40
|
'type' => MENU_CALLBACK,
|
41
|
);
|
42
|
if (module_exists('rules')) {
|
43
|
$items['testing/feeds/trigger-rules-event'] = array(
|
44
|
'page callback' => 'feeds_tests_trigger_rules_event',
|
45
|
'access arguments' => array('access content'),
|
46
|
'type' => MENU_CALLBACK,
|
47
|
);
|
48
|
}
|
49
|
return $items;
|
50
|
}
|
51
|
|
52
|
/**
|
53
|
* Implements hook_theme().
|
54
|
*/
|
55
|
function feeds_tests_theme() {
|
56
|
return array(
|
57
|
'feeds_tests_flickr' => array(
|
58
|
'variables' => array('image_urls' => array()),
|
59
|
'path' => drupal_get_path('module', 'feeds_tests') . '/feeds',
|
60
|
'template' => 'feeds-tests-flickr',
|
61
|
),
|
62
|
'feeds_tests_files' => array(
|
63
|
'variables' => array('files' => array()),
|
64
|
'path' => drupal_get_path('module', 'feeds_tests') . '/feeds',
|
65
|
'template' => 'feeds-tests-files',
|
66
|
),
|
67
|
'feeds_tests_files_empty' => array(
|
68
|
'variables' => array('files' => array()),
|
69
|
'path' => drupal_get_path('module', 'feeds_tests') . '/feeds',
|
70
|
'template' => 'feeds-tests-files-empty',
|
71
|
),
|
72
|
);
|
73
|
}
|
74
|
|
75
|
/**
|
76
|
* Implements hook_node_load().
|
77
|
*/
|
78
|
function feeds_tests_node_load($nodes) {
|
79
|
// Eventually keep track of nodes that get loaded.
|
80
|
if (variable_get('feeds_track_node_loads', FALSE)) {
|
81
|
$loads = variable_get('feeds_loaded_nodes', array());
|
82
|
$loads = array_merge($loads, array_keys($nodes));
|
83
|
variable_set('feeds_loaded_nodes', $loads);
|
84
|
}
|
85
|
}
|
86
|
|
87
|
/**
|
88
|
* Implements hook_cron_queue_alter().
|
89
|
*
|
90
|
* Changes runtime limit for feeds_source_import queue.
|
91
|
*
|
92
|
* @see FeedsFileFetcherTestCase::testRemoveFileAfterImportInBackground()
|
93
|
* @see FeedsFileHTTPTestCase::testImportSourceWithMultipleCronRuns()
|
94
|
*/
|
95
|
function feeds_tests_cron_queue_info_alter(&$queues) {
|
96
|
$feeds_source_import_queue_time = variable_get('feeds_tests_feeds_source_import_queue_time', FALSE);
|
97
|
if ($feeds_source_import_queue_time && isset($queues['feeds_source_import'])) {
|
98
|
$queues['feeds_source_import']['time'] = $feeds_source_import_queue_time;
|
99
|
}
|
100
|
}
|
101
|
|
102
|
/**
|
103
|
* Implements hook_form_FORM_ID_alter() for form feedsimporter_feeds_form().
|
104
|
*
|
105
|
* Adds an extra checkbox setting.
|
106
|
*
|
107
|
* @see feeds_tests_config_defaults()
|
108
|
*/
|
109
|
function feeds_tests_form_feedsimporter_feeds_form_alter(&$form, &$form_state) {
|
110
|
if (variable_get('feeds_tests_hook_config_defaults', FALSE)) {
|
111
|
$config = $form['#configurable']->getConfig();
|
112
|
|
113
|
$form['feeds_tests_extra_setting'] = array(
|
114
|
'#type' => 'checkbox',
|
115
|
'#title' => t('Extra setting'),
|
116
|
'#default_value' => $config['feeds_tests_extra_setting'],
|
117
|
);
|
118
|
}
|
119
|
}
|
120
|
|
121
|
/**
|
122
|
* Implements hook_form_FORM_ID_alter() for form feedshttpfetcher_feeds_form().
|
123
|
*
|
124
|
* Adds an extra checkbox setting.
|
125
|
*
|
126
|
* @see feeds_tests_fetcher_config_defaults()
|
127
|
*/
|
128
|
function feeds_tests_form_feedshttpfetcher_feeds_form_alter(&$form, &$form_state) {
|
129
|
if (variable_get('feeds_tests_hook_config_defaults', FALSE)) {
|
130
|
$config = $form['#configurable']->getConfig();
|
131
|
|
132
|
$form['feeds_tests_fetcher_extra_setting'] = array(
|
133
|
'#type' => 'checkbox',
|
134
|
'#title' => t('Extra setting'),
|
135
|
'#default_value' => $config['feeds_tests_fetcher_extra_setting'],
|
136
|
);
|
137
|
}
|
138
|
}
|
139
|
|
140
|
/**
|
141
|
* Implements hook_form_FORM_ID_alter() for form feedscsvparser_feeds_form().
|
142
|
*
|
143
|
* Adds an extra checkbox setting.
|
144
|
*
|
145
|
* @see feeds_tests_parser_config_defaults()
|
146
|
*/
|
147
|
function feeds_tests_form_feedscsvparser_feeds_form_alter(&$form, &$form_state) {
|
148
|
if (variable_get('feeds_tests_hook_config_defaults', FALSE)) {
|
149
|
$config = $form['#configurable']->getConfig();
|
150
|
|
151
|
$form['feeds_tests_parser_extra_setting'] = array(
|
152
|
'#type' => 'checkbox',
|
153
|
'#title' => t('Extra setting'),
|
154
|
'#default_value' => $config['feeds_tests_parser_extra_setting'],
|
155
|
);
|
156
|
}
|
157
|
}
|
158
|
|
159
|
/**
|
160
|
* Implements hook_form_FORM_ID_alter() for form feedsnodeprocessor_feeds_form().
|
161
|
*
|
162
|
* Adds an extra custom setting.
|
163
|
*
|
164
|
* @see feeds_tests_processor_config_defaults()
|
165
|
*/
|
166
|
function feeds_tests_form_feedsnodeprocessor_feeds_form_alter(&$form, &$form_state) {
|
167
|
if (variable_get('feeds_tests_hook_config_defaults', FALSE)) {
|
168
|
$config = $form['#configurable']->getConfig();
|
169
|
|
170
|
$form['feeds_tests_processor_extra_setting'] = array(
|
171
|
'#type' => 'textfield',
|
172
|
'#title' => t('Extra setting'),
|
173
|
'#default_value' => $config['feeds_tests_processor_extra_setting'],
|
174
|
);
|
175
|
}
|
176
|
}
|
177
|
|
178
|
/**
|
179
|
* Outputs flickr test feed.
|
180
|
*/
|
181
|
function feeds_tests_flickr() {
|
182
|
$images = array(
|
183
|
0 => "tubing.jpeg",
|
184
|
1 => "foosball.jpeg",
|
185
|
2 => "attersee.jpeg",
|
186
|
3 => "hstreet.jpeg",
|
187
|
4 => "la fayette.jpeg",
|
188
|
);
|
189
|
$path = drupal_get_path('module', 'feeds_tests') . '/feeds/assets';
|
190
|
foreach ($images as &$image) {
|
191
|
$image = file_create_url("$path/$image");
|
192
|
}
|
193
|
drupal_add_http_header('Content-Type', 'application/rss+xml; charset=utf-8');
|
194
|
print theme('feeds_tests_flickr', array('image_urls' => $images));
|
195
|
}
|
196
|
|
197
|
/**
|
198
|
* Outputs a CSV file pointing to files.
|
199
|
*/
|
200
|
function feeds_tests_files() {
|
201
|
$images = array(
|
202
|
0 => "tubing.jpeg",
|
203
|
1 => "foosball.jpeg",
|
204
|
2 => "attersee.jpeg",
|
205
|
3 => "hstreet.jpeg",
|
206
|
4 => "la fayette.jpeg",
|
207
|
);
|
208
|
foreach ($images as &$image) {
|
209
|
$image = "public://images/$image";
|
210
|
}
|
211
|
drupal_add_http_header('Content-Type', 'text/plain; charset=utf-8');
|
212
|
print theme('feeds_tests_files', array('files' => $images));
|
213
|
}
|
214
|
|
215
|
/**
|
216
|
* Outputs a CSV file pointing to files to download.
|
217
|
*/
|
218
|
function feeds_tests_files_remote() {
|
219
|
$images = array(
|
220
|
0 => 'tubing.jpeg',
|
221
|
1 => 'foosball.jpeg',
|
222
|
2 => 'attersee.jpeg',
|
223
|
3 => 'hstreet.jpeg',
|
224
|
4 => 'la fayette.jpeg',
|
225
|
);
|
226
|
$path = drupal_get_path('module', 'feeds_tests') . '/feeds/assets';
|
227
|
foreach ($images as &$image) {
|
228
|
$image = file_create_url("$path/$image");
|
229
|
}
|
230
|
drupal_add_http_header('Content-Type', 'text/plain; charset=utf-8');
|
231
|
print theme('feeds_tests_files', array('files' => $images));
|
232
|
}
|
233
|
|
234
|
/**
|
235
|
* Outputs a CSV file pointing to files without alt/title.
|
236
|
*
|
237
|
* This is used to test if alt/title attributes are removed on a second import.
|
238
|
*/
|
239
|
function feeds_tests_files_empty_alt_title() {
|
240
|
$images = array(
|
241
|
0 => 'tubing.jpeg',
|
242
|
1 => 'foosball.jpeg',
|
243
|
2 => 'attersee.jpeg',
|
244
|
3 => 'hstreet.jpeg',
|
245
|
4 => 'la fayette.jpeg',
|
246
|
);
|
247
|
$path = drupal_get_path('module', 'feeds_tests') . '/feeds/assets';
|
248
|
foreach ($images as &$image) {
|
249
|
$image = file_create_url("$path/$image");
|
250
|
}
|
251
|
drupal_add_http_header('Content-Type', 'text/plain; charset=utf-8');
|
252
|
print theme('feeds_tests_files_empty', array('files' => $images));
|
253
|
}
|
254
|
|
255
|
/**
|
256
|
* Outputs a CSV file pointing to no files.
|
257
|
*
|
258
|
* This is used to test if files are removed on a second import.
|
259
|
*/
|
260
|
function feeds_tests_files_empty() {
|
261
|
$images = array(
|
262
|
0 => '',
|
263
|
1 => '',
|
264
|
2 => '',
|
265
|
3 => '',
|
266
|
4 => '',
|
267
|
);
|
268
|
drupal_add_http_header('Content-Type', 'text/plain; charset=utf-8');
|
269
|
print theme('feeds_tests_files_empty', array('files' => $images));
|
270
|
}
|
271
|
|
272
|
/**
|
273
|
* Page callback. Generates a test feed and simulates last-modified.
|
274
|
*
|
275
|
* This is used to test the following:
|
276
|
* - Ensure that the source is not refetched on a second import when the
|
277
|
* source did not change.
|
278
|
* - Ensure that the source *is* refetched on a second import when the
|
279
|
* source *did* change.
|
280
|
*
|
281
|
* @see FeedsFileHTTPTestCase::testHttpRequestUsingFileCache()
|
282
|
* @see FeedsFileHTTPTestCase::testSourceCaching()
|
283
|
* @see FeedsFileHTTPTestCase::testChangedSource()
|
284
|
* @see FeedsFileHTTPTestCase::testImportSourceWithMultipleCronRuns()
|
285
|
*/
|
286
|
function feeds_tests_nodes() {
|
287
|
if (variable_get('feeds_tests_nodes_changed', FALSE)) {
|
288
|
$file = 'nodes_changes2.csv';
|
289
|
$last_modified = strtotime('Sun, 30 Mar 2016 10:19:55 GMT');
|
290
|
}
|
291
|
else {
|
292
|
$file = 'nodes.csv';
|
293
|
$last_modified = strtotime('Sun, 19 Nov 1978 05:00:00 GMT');
|
294
|
}
|
295
|
|
296
|
$if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) : FALSE;
|
297
|
$if_none_match = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) : FALSE;
|
298
|
|
299
|
// Set header with last modified date.
|
300
|
drupal_add_http_header('Last-Modified', gmdate(DATE_RFC7231, $last_modified));
|
301
|
|
302
|
// Return 304 not modified if last modified.
|
303
|
if ($last_modified == $if_modified_since) {
|
304
|
drupal_add_http_header('Status', '304 Not Modified');
|
305
|
return;
|
306
|
}
|
307
|
|
308
|
// The following headers force validation of cache:
|
309
|
drupal_add_http_header('Expires', $last_modified);
|
310
|
drupal_add_http_header('Cache-Control', 'must-revalidate');
|
311
|
drupal_add_http_header('Content-Type', 'text/plain; charset=utf-8');
|
312
|
|
313
|
// Read actual feed from file.
|
314
|
$csv = file_get_contents(drupal_get_path('module', 'feeds') . '/tests/feeds/' . $file);
|
315
|
|
316
|
print $csv;
|
317
|
}
|
318
|
|
319
|
/**
|
320
|
* Implements hook_query_TAG_alter() for tag 'term_access'.
|
321
|
*/
|
322
|
function feeds_tests_query_term_access_alter(QueryAlterableInterface $query) {
|
323
|
global $user;
|
324
|
|
325
|
$allowed_user = variable_get('feeds_tests_term_reference_allowed_user', NULL);
|
326
|
if (is_null($allowed_user)) {
|
327
|
// No allowed user set. Abort.
|
328
|
return;
|
329
|
}
|
330
|
|
331
|
// Read meta-data from query, if provided.
|
332
|
if (!$account = $query->getMetaData('account')) {
|
333
|
$account = $user;
|
334
|
}
|
335
|
|
336
|
// If the current active user is the set user, abort.
|
337
|
if ($account->uid == $allowed_user) {
|
338
|
return;
|
339
|
}
|
340
|
|
341
|
// If $account can bypass node access, or there are no node access
|
342
|
// modules, we don't need to alter the query.
|
343
|
if (user_access('bypass node access', $account)) {
|
344
|
return;
|
345
|
}
|
346
|
|
347
|
// Disallow any terms.
|
348
|
$tables = $query->getTables();
|
349
|
foreach ($tables as $talias => $tableinfo) {
|
350
|
$table = $tableinfo['table'];
|
351
|
if (!($table instanceof SelectQueryInterface) && $table == 'taxonomy_term_data') {
|
352
|
$query->condition("$talias.tid", 0);
|
353
|
}
|
354
|
}
|
355
|
}
|
356
|
|
357
|
/**
|
358
|
* Page callback. Triggers the rules event 'feeds_tests_rules_event'.
|
359
|
*/
|
360
|
function feeds_tests_trigger_rules_event() {
|
361
|
rules_invoke_event('feeds_tests_rules_event');
|
362
|
return array(
|
363
|
'#markup' => 'Rules event "feeds_tests_rules_event" triggered.',
|
364
|
);
|
365
|
}
|
366
|
|
367
|
/**
|
368
|
* Implements hook_feeds_processor_targets().
|
369
|
*/
|
370
|
function feeds_tests_feeds_processor_targets($entity_type, $bundle) {
|
371
|
$targets = array();
|
372
|
|
373
|
// Tests that old keys still work.
|
374
|
$targets['test_target_compat'] = array(
|
375
|
'name' => t('Old style target'),
|
376
|
'callback' => 'feeds_tests_mapper_set_target',
|
377
|
'summary_callback' => 'feeds_tests_mapper_summary',
|
378
|
'form_callback' => 'feeds_tests_mapper_form',
|
379
|
);
|
380
|
|
381
|
$targets['test_target'] = array(
|
382
|
'name' => t('Test Target'),
|
383
|
'description' => t('This is a test target.'),
|
384
|
'callback' => 'feeds_tests_mapper_set_target',
|
385
|
'summary_callbacks' => array('feeds_tests_mapper_summary', 'feeds_tests_mapper_summary_2'),
|
386
|
'form_callbacks' => array('feeds_tests_mapper_form', 'feeds_tests_mapper_form_2'),
|
387
|
'preprocess_callbacks' => array(array(new FeedsTestsPreprocess(), 'callback')),
|
388
|
);
|
389
|
|
390
|
$targets['test_unique_target'] = array(
|
391
|
'name' => t('Test unique target'),
|
392
|
'description' => t('This is a unique test target.'),
|
393
|
'callback' => 'feeds_tests_mapper_set_target',
|
394
|
'optional_unique' => TRUE,
|
395
|
'unique_callbacks' => array('feeds_tests_mapper_unique'),
|
396
|
'preprocess_callbacks' => array(
|
397
|
array('FeedsTestsPreprocess', 'callback'),
|
398
|
// Make sure that invalid callbacks are filtered.
|
399
|
'__feeds_tests_invalid_callback',
|
400
|
),
|
401
|
);
|
402
|
|
403
|
return $targets;
|
404
|
}
|
405
|
|
406
|
/**
|
407
|
* Implements hook_feeds_processor_targets_alter().
|
408
|
*/
|
409
|
function feeds_tests_feeds_processor_targets_alter(array &$targets, $entity_type, $bundle) {
|
410
|
if (!isset($targets['test_target'])) {
|
411
|
return;
|
412
|
}
|
413
|
|
414
|
$targets['test_target']['description'] = t('The target description was altered.');
|
415
|
}
|
416
|
|
417
|
/**
|
418
|
* Preprocess callback for test_target.
|
419
|
*
|
420
|
* @see feeds_tests_feeds_processor_targets()
|
421
|
*/
|
422
|
function feeds_tests_preprocess_callback(array $target, array &$mapping) {
|
423
|
$mapping['required_value'] = TRUE;
|
424
|
}
|
425
|
|
426
|
/**
|
427
|
* Set target value on entity.
|
428
|
*
|
429
|
* @see my_module_set_target()
|
430
|
*/
|
431
|
function feeds_tests_mapper_set_target(FeedsSource $source, $entity, $target, array $values, array $mapping) {
|
432
|
if (empty($mapping['required_value'])) {
|
433
|
trigger_error('The required value was not set.', E_USER_ERROR);
|
434
|
}
|
435
|
|
436
|
$entity->body['und'][0]['value'] = serialize($mapping);
|
437
|
}
|
438
|
|
439
|
/**
|
440
|
* Provides setting summary for the mapper.
|
441
|
*
|
442
|
* @see my_module_summary_callback()
|
443
|
*/
|
444
|
function feeds_tests_mapper_summary(array $mapping, $target, array $form, array $form_state) {
|
445
|
$options = array(
|
446
|
'option1' => t('Option 1'),
|
447
|
'option2' => t('Another Option'),
|
448
|
'option3' => t('Option for select'),
|
449
|
'option4' => t('Another One'),
|
450
|
);
|
451
|
|
452
|
$items = array();
|
453
|
if (!empty($mapping['checkbox']) && $mapping['checkbox']) {
|
454
|
$items[] = t('Checkbox active.');
|
455
|
}
|
456
|
else {
|
457
|
$items[] = t('Checkbox inactive.');
|
458
|
}
|
459
|
if (!empty($mapping['textfield'])) {
|
460
|
$items[] = t('<strong>Textfield value</strong>: %textfield', array('%textfield' => $mapping['textfield']));
|
461
|
}
|
462
|
if (!empty($mapping['textarea'])) {
|
463
|
$items[] = t('<strong>Textarea value</strong>: %textarea', array('%textarea' => $mapping['textarea']));
|
464
|
}
|
465
|
if (!empty($mapping['radios'])) {
|
466
|
$items[] = t('<strong>Radios value</strong>: %radios', array('%radios' => $options[$mapping['radios']]));
|
467
|
}
|
468
|
if (!empty($mapping['select'])) {
|
469
|
$items[] = t('<strong>Select value</strong>: %select', array('%select' => $options[$mapping['select']]));
|
470
|
}
|
471
|
$list = array(
|
472
|
'#type' => 'ul',
|
473
|
'#theme' => 'item_list',
|
474
|
'#items' => $items,
|
475
|
);
|
476
|
return drupal_render($list);
|
477
|
}
|
478
|
|
479
|
/**
|
480
|
* Provides a second summary callback.
|
481
|
*
|
482
|
* @see my_module_summary_callback()
|
483
|
*/
|
484
|
function feeds_tests_mapper_summary_2(array $mapping, $target, array $form, array $form_state) {
|
485
|
$mapping += array('second_value' => '');
|
486
|
return t('Second summary: @value', array('@value' => $mapping['second_value']));
|
487
|
}
|
488
|
|
489
|
/**
|
490
|
* Provides the form with mapper settings.
|
491
|
*/
|
492
|
function feeds_tests_mapper_form(array $mapping, $target, array $form, array $form_state) {
|
493
|
$mapping += array(
|
494
|
'checkbox' => FALSE,
|
495
|
'textfield' => '',
|
496
|
'textarea' => '',
|
497
|
'radios' => NULL,
|
498
|
'select' => NULL,
|
499
|
);
|
500
|
return array(
|
501
|
'checkbox' => array(
|
502
|
'#type' => 'checkbox',
|
503
|
'#title' => t('A checkbox'),
|
504
|
'#default_value' => !empty($mapping['checkbox']),
|
505
|
),
|
506
|
'textfield' => array(
|
507
|
'#type' => 'textfield',
|
508
|
'#title' => t('A text field'),
|
509
|
'#default_value' => $mapping['textfield'],
|
510
|
'#required' => TRUE,
|
511
|
),
|
512
|
'textarea' => array(
|
513
|
'#type' => 'textarea',
|
514
|
'#title' => t('A textarea'),
|
515
|
'#default_value' => $mapping['textarea'],
|
516
|
),
|
517
|
'radios' => array(
|
518
|
'#type' => 'radios',
|
519
|
'#title' => t('Some radios'),
|
520
|
'#options' => array('option1' => t('Option 1'), 'option2' => t('Another Option')),
|
521
|
'#default_value' => $mapping['radios'],
|
522
|
),
|
523
|
'select' => array(
|
524
|
'#type' => 'select',
|
525
|
'#title' => t('A select list'),
|
526
|
'#options' => array('option3' => t('Option for select'), 'option4' => t('Another One')),
|
527
|
'#default_value' => $mapping['select'],
|
528
|
),
|
529
|
);
|
530
|
}
|
531
|
|
532
|
/**
|
533
|
* Provides a second settings form.
|
534
|
*/
|
535
|
function feeds_tests_mapper_form_2(array $mapping, $target, array $form, array $form_state) {
|
536
|
return array(
|
537
|
'second_value' => array(
|
538
|
'#type' => 'textfield',
|
539
|
'#title' => t('The second callback value'),
|
540
|
'#default_value' => !empty($mapping['second_value']) ? $mapping['second_value'] : '',
|
541
|
),
|
542
|
);
|
543
|
}
|
544
|
|
545
|
/**
|
546
|
* Callback for unique_callbacks for test_target mapper.
|
547
|
*
|
548
|
* @see feeds_tests_feeds_processor_targets()
|
549
|
*/
|
550
|
function feeds_tests_mapper_unique(FeedsSource $source, $entity_type, $bundle, $target, array $values) {
|
551
|
$query = new EntityFieldQuery();
|
552
|
$result = $query
|
553
|
->entityCondition('entity_type', $entity_type)
|
554
|
->entityCondition('bundle', $bundle)
|
555
|
->fieldCondition('field_alpha', 'value', $values)
|
556
|
->execute();
|
557
|
|
558
|
if (!empty($result[$entity_type])) {
|
559
|
return key($result[$entity_type]);
|
560
|
}
|
561
|
}
|
562
|
|
563
|
/**
|
564
|
* Implements hook_feeds_after_parse().
|
565
|
*/
|
566
|
function feeds_tests_feeds_after_parse(FeedsSource $source, FeedsParserResult $result) {
|
567
|
// Empties the list of items to import in case the test says that there are
|
568
|
// items in there with encoding issues. These items can not be processed
|
569
|
// during tests without having a test failure because in < PHP 5.4 that would
|
570
|
// produce the following warning:
|
571
|
// > htmlspecialchars(): Invalid multibyte sequence in argument.
|
572
|
// @see FeedsCSVParserTestCase::testMbstringExtensionDisabled()
|
573
|
if (variable_get('feeds_tests_feeds_after_parse_empty_items', FALSE)) {
|
574
|
// Remove all items. No items will be processed.
|
575
|
$result->items = array();
|
576
|
}
|
577
|
|
578
|
if ($source->id == 'user_import') {
|
579
|
foreach ($result->items as &$item) {
|
580
|
if (!empty($item['roles']) && strpos($item['roles'], '|')) {
|
581
|
// Convert roles value to multiple values.
|
582
|
// @see FeedsCSVtoUsersTest::testRoleTargetWithoutRoleCreation()
|
583
|
// @see FeedsCSVtoUsersTest::testRoleTargetWithRoleCreation()
|
584
|
// @see FeedsCSVtoUsersTest::testRoleTargetWithAllowedRoles()
|
585
|
$item['roles'] = explode('|', $item['roles']);
|
586
|
}
|
587
|
if (!empty($item['rids']) && strpos($item['rids'], '|')) {
|
588
|
// Convert roles value to multiple values.
|
589
|
// @see FeedsCSVtoUsersTest::testRoleTargetRids()
|
590
|
$item['rids'] = explode('|', $item['rids']);
|
591
|
}
|
592
|
}
|
593
|
}
|
594
|
|
595
|
// Casts the 'uid' value to a float to ensure float values don't result into
|
596
|
// array_flip() warnings when using the value to load an user.
|
597
|
// @see FeedsRSStoNodesTest::testUidTargetWithFloat()
|
598
|
if (variable_get('feeds_tests_feeds_after_parse_uid_float_value', FALSE)) {
|
599
|
foreach ($result->items as &$item) {
|
600
|
$item['uid'] = (float) $item['uid'];
|
601
|
}
|
602
|
}
|
603
|
|
604
|
// Conditionally set the 'uid' value to the current user.
|
605
|
// @see FeedsAccountSwitcherTest
|
606
|
if (variable_get('feeds_tests_set_uid_current_user', FALSE)) {
|
607
|
foreach ($result->items as &$item) {
|
608
|
$item['uid'] = $GLOBALS['user']->uid;
|
609
|
}
|
610
|
}
|
611
|
|
612
|
// Conditionally abort the import abruptly.
|
613
|
// @see FeedsAccountSwitcherTest
|
614
|
if (variable_get('feeds_tests_trigger_import_disruption', FALSE)) {
|
615
|
die();
|
616
|
}
|
617
|
}
|
618
|
|
619
|
/**
|
620
|
* Implements hook_feeds_after_save().
|
621
|
*
|
622
|
* @see FeedsFileFetcherTestCase::testRemoveFileAfterImportInBackground()
|
623
|
* @see FeedsFileHTTPTestCase::testImportSourceWithMultipleCronRuns()
|
624
|
*/
|
625
|
function feeds_tests_feeds_after_save() {
|
626
|
$sleep = variable_get('feeds_tests_feeds_after_save_sleep', FALSE);
|
627
|
if ($sleep) {
|
628
|
sleep($sleep);
|
629
|
}
|
630
|
}
|
631
|
|
632
|
/**
|
633
|
* Helper class to ensure callbacks can be objects.
|
634
|
*/
|
635
|
class FeedsTestsPreprocess {
|
636
|
|
637
|
/**
|
638
|
* Preprocess callback for test_target.
|
639
|
*
|
640
|
* @see feeds_tests_feeds_processor_targets()
|
641
|
*/
|
642
|
public static function callback(array $target, array &$mapping) {
|
643
|
$mapping['required_value'] = TRUE;
|
644
|
}
|
645
|
|
646
|
}
|