contrib modules security updates
This commit is contained in:
@@ -19,6 +19,21 @@ function feeds_tests_menu() {
|
||||
'access arguments' => array('access content'),
|
||||
'type' => MENU_CALLBACK,
|
||||
);
|
||||
$items['testing/feeds/files-remote.csv'] = array(
|
||||
'page callback' => 'feeds_tests_files_remote',
|
||||
'access arguments' => array('access content'),
|
||||
'type' => MENU_CALLBACK,
|
||||
);
|
||||
$items['testing/feeds/files-empty-alt-title.csv'] = array(
|
||||
'page callback' => 'feeds_tests_files_empty_alt_title',
|
||||
'access arguments' => array('access content'),
|
||||
'type' => MENU_CALLBACK,
|
||||
);
|
||||
$items['testing/feeds/files-empty.csv'] = array(
|
||||
'page callback' => 'feeds_tests_files_empty',
|
||||
'access arguments' => array('access content'),
|
||||
'type' => MENU_CALLBACK,
|
||||
);
|
||||
return $items;
|
||||
}
|
||||
|
||||
@@ -37,6 +52,11 @@ function feeds_tests_theme() {
|
||||
'path' => drupal_get_path('module', 'feeds_tests') . '/feeds',
|
||||
'template' => 'feeds-tests-files',
|
||||
),
|
||||
'feeds_tests_files_empty' => array(
|
||||
'variables' => array('files' => array()),
|
||||
'path' => drupal_get_path('module', 'feeds_tests') . '/feeds',
|
||||
'template' => 'feeds-tests-files-empty',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -53,7 +73,7 @@ function feeds_tests_flickr() {
|
||||
);
|
||||
$path = drupal_get_path('module', 'feeds_tests') . '/feeds/assets';
|
||||
foreach ($images as &$image) {
|
||||
$image = url("$path/$image", array('absolute' => TRUE));
|
||||
$image = file_create_url("$path/$image");
|
||||
}
|
||||
drupal_add_http_header('Content-Type', 'application/rss+xml; charset=utf-8');
|
||||
print theme('feeds_tests_flickr', array('image_urls' => $images));
|
||||
@@ -78,16 +98,119 @@ function feeds_tests_files() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_feeds_processor_targets_alter()
|
||||
* Outputs a CSV file pointing to files to download.
|
||||
*/
|
||||
function feeds_tests_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) {
|
||||
$targets['test_target'] = array(
|
||||
'name' => t('Test Target'),
|
||||
'description' => t('This is a test target.'),
|
||||
function feeds_tests_files_remote() {
|
||||
$images = array(
|
||||
0 => 'tubing.jpeg',
|
||||
1 => 'foosball.jpeg',
|
||||
2 => 'attersee.jpeg',
|
||||
3 => 'hstreet.jpeg',
|
||||
4 => 'la fayette.jpeg',
|
||||
);
|
||||
$path = drupal_get_path('module', 'feeds_tests') . '/feeds/assets';
|
||||
foreach ($images as &$image) {
|
||||
$image = file_create_url("$path/$image");
|
||||
}
|
||||
drupal_add_http_header('Content-Type', 'text/plain; charset=utf-8');
|
||||
print theme('feeds_tests_files', array('files' => $images));
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a CSV file pointing to files without alt/title.
|
||||
*
|
||||
* This is used to test if alt/title attributes are removed on a second import.
|
||||
*/
|
||||
function feeds_tests_files_empty_alt_title() {
|
||||
$images = array(
|
||||
0 => 'tubing.jpeg',
|
||||
1 => 'foosball.jpeg',
|
||||
2 => 'attersee.jpeg',
|
||||
3 => 'hstreet.jpeg',
|
||||
4 => 'la fayette.jpeg',
|
||||
);
|
||||
$path = drupal_get_path('module', 'feeds_tests') . '/feeds/assets';
|
||||
foreach ($images as &$image) {
|
||||
$image = file_create_url("$path/$image");
|
||||
}
|
||||
drupal_add_http_header('Content-Type', 'text/plain; charset=utf-8');
|
||||
print theme('feeds_tests_files_empty', array('files' => $images));
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a CSV file pointing to no files.
|
||||
*
|
||||
* This is used to test if files are removed on a second import.
|
||||
*/
|
||||
function feeds_tests_files_empty() {
|
||||
$images = array(
|
||||
0 => '',
|
||||
1 => '',
|
||||
2 => '',
|
||||
3 => '',
|
||||
4 => '',
|
||||
);
|
||||
drupal_add_http_header('Content-Type', 'text/plain; charset=utf-8');
|
||||
print theme('feeds_tests_files_empty', array('files' => $images));
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_feeds_processor_targets().
|
||||
*/
|
||||
function feeds_tests_feeds_processor_targets($entity_type, $bundle) {
|
||||
$targets = array();
|
||||
|
||||
// Tests that old keys still work.
|
||||
$targets['test_target_compat'] = array(
|
||||
'name' => t('Old style target'),
|
||||
'callback' => 'feeds_tests_mapper_set_target',
|
||||
'summary_callback' => 'feeds_tests_mapper_summary',
|
||||
'form_callback' => 'feeds_tests_mapper_form',
|
||||
);
|
||||
|
||||
$targets['test_target'] = array(
|
||||
'name' => t('Test Target'),
|
||||
'description' => t('This is a test target.'),
|
||||
'callback' => 'feeds_tests_mapper_set_target',
|
||||
'summary_callbacks' => array('feeds_tests_mapper_summary', 'feeds_tests_mapper_summary_2'),
|
||||
'form_callbacks' => array('feeds_tests_mapper_form', 'feeds_tests_mapper_form_2'),
|
||||
'preprocess_callbacks' => array(array(new FeedsTestsPreprocess(), 'callback')),
|
||||
);
|
||||
|
||||
$targets['test_unique_target'] = array(
|
||||
'name' => t('Test unique target'),
|
||||
'description' => t('This is a unique test target.'),
|
||||
'callback' => 'feeds_tests_mapper_set_target',
|
||||
'optional_unique' => TRUE,
|
||||
'unique_callbacks' => array('feeds_tests_mapper_unique'),
|
||||
'preprocess_callbacks' => array(
|
||||
array('FeedsTestsPreprocess', 'callback'),
|
||||
// Make sure that invalid callbacks are filtered.
|
||||
'__feeds_tests_invalid_callback',
|
||||
),
|
||||
);
|
||||
|
||||
return $targets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_feeds_processor_targets_alter().
|
||||
*/
|
||||
function feeds_tests_feeds_processor_targets_alter(array &$targets, $entity_type, $bundle) {
|
||||
if (!isset($targets['test_target'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$targets['test_target']['description'] = t('The target description was altered.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Preprocess callback for test_target.
|
||||
*
|
||||
* @see feeds_tests_feeds_processor_targets()
|
||||
*/
|
||||
function feeds_tests_preprocess_callback(array $target, array &$mapping) {
|
||||
$mapping['required_value'] = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,8 +218,12 @@ function feeds_tests_feeds_processor_targets_alter(&$targets, $entity_type, $bun
|
||||
*
|
||||
* @see my_module_set_target()
|
||||
*/
|
||||
function feeds_tests_mapper_set_target($source, $entity, $target, $value, $mapping) {
|
||||
$entity->body['und'][0]['value'] = serialize($mapping);
|
||||
function feeds_tests_mapper_set_target(FeedsSource $source, $entity, $target, array $values, array $mapping) {
|
||||
if (empty($mapping['required_value'])) {
|
||||
trigger_error('The required value was not set.', E_USER_ERROR);
|
||||
}
|
||||
|
||||
$entity->body['und'][0]['value'] = serialize($mapping);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,12 +231,12 @@ function feeds_tests_mapper_set_target($source, $entity, $target, $value, $mappi
|
||||
*
|
||||
* @see my_module_summary_callback()
|
||||
*/
|
||||
function feeds_tests_mapper_summary($mapping, $target, $form, $form_state) {
|
||||
function feeds_tests_mapper_summary(array $mapping, $target, array $form, array $form_state) {
|
||||
$options = array(
|
||||
'option1' => t('Option 1'),
|
||||
'option1' => t('Option 1'),
|
||||
'option2' => t('Another Option'),
|
||||
'option3' => t('Option for select'),
|
||||
'option4' => t('Another One')
|
||||
'option3' => t('Option for select'),
|
||||
'option4' => t('Another One'),
|
||||
);
|
||||
|
||||
$items = array();
|
||||
@@ -139,10 +266,20 @@ function feeds_tests_mapper_summary($mapping, $target, $form, $form_state) {
|
||||
return drupal_render($list);
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Provides a second summary callback.
|
||||
*
|
||||
* @see my_module_summary_callback()
|
||||
*/
|
||||
function feeds_tests_mapper_summary_2(array $mapping, $target, array $form, array $form_state) {
|
||||
$mapping += array('second_value' => '');
|
||||
return t('Second summary: @value', array('@value' => $mapping['second_value']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the form with mapper settings.
|
||||
*/
|
||||
function feeds_tests_mapper_form($mapping, $target, $form, $form_state) {
|
||||
function feeds_tests_mapper_form(array $mapping, $target, array $form, array $form_state) {
|
||||
$mapping += array(
|
||||
'checkbox' => FALSE,
|
||||
'textfield' => '',
|
||||
@@ -182,3 +319,67 @@ function feeds_tests_mapper_form($mapping, $target, $form, $form_state) {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a second settings form.
|
||||
*/
|
||||
function feeds_tests_mapper_form_2(array $mapping, $target, array $form, array $form_state) {
|
||||
return array(
|
||||
'second_value' => array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('The second callback value'),
|
||||
'#default_value' => !empty($mapping['second_value']) ? $mapping['second_value'] : '',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for unique_callbacks for test_target mapper.
|
||||
*
|
||||
* @see feeds_tests_feeds_processor_targets()
|
||||
*/
|
||||
function feeds_tests_mapper_unique(FeedsSource $source, $entity_type, $bundle, $target, array $values) {
|
||||
$query = new EntityFieldQuery();
|
||||
$result = $query
|
||||
->entityCondition('entity_type', $entity_type)
|
||||
->entityCondition('bundle', $bundle)
|
||||
->fieldCondition('field_alpha', 'value', $values)
|
||||
->execute();
|
||||
|
||||
if (!empty($result[$entity_type])) {
|
||||
return key($result[$entity_type]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_feeds_after_parse().
|
||||
*
|
||||
* Empties the list of items to import in case the test says that there are
|
||||
* items in there with encoding issues. These items can not be processed during
|
||||
* tests without having a test failure because in < PHP 5.4 that would produce
|
||||
* the following warning:
|
||||
* htmlspecialchars(): Invalid multibyte sequence in argument
|
||||
*
|
||||
* @see FeedsCSVParserTestCase::testMbstringExtensionDisabled()
|
||||
*/
|
||||
function feeds_tests_feeds_after_parse(FeedsSource $source, FeedsParserResult $result) {
|
||||
if (variable_get('feeds_tests_feeds_after_parse_empty_items', FALSE)) {
|
||||
// Remove all items. No items will be processed.
|
||||
$result->items = array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper class to ensure callbacks can be objects.
|
||||
*/
|
||||
class FeedsTestsPreprocess {
|
||||
|
||||
/**
|
||||
* Preprocess callback for test_target.
|
||||
*
|
||||
* @see feeds_tests_feeds_processor_targets()
|
||||
*/
|
||||
public static function callback(array $target, array &$mapping) {
|
||||
$mapping['required_value'] = TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user