Commit 055716fe authored by Dries's avatar Dries

- Patch #1527988 by Niklas Fiekas: Fixed Missing or legacy number validation.

parent 0ca408e1
......@@ -1353,11 +1353,12 @@ function _filter_url_settings($form, &$form_state, $filter, $format, $defaults)
$filter->settings += $defaults;
$settings['filter_url_length'] = array(
'#type' => 'textfield',
'#type' => 'number',
'#title' => t('Maximum link text length'),
'#default_value' => $filter->settings['filter_url_length'],
'#size' => 5,
'#maxlength' => 4,
'#min' => 1,
'#field_suffix' => t('characters'),
'#description' => t('URLs longer than this number of characters will be truncated to prevent long strings that break formatting. The link itself will be retained; just the text portion of the link will be truncated.'),
);
......
......@@ -401,6 +401,18 @@ class FilterAdminTestCase extends DrupalWebTestCase {
$this->assertFieldByName('filters[' . $second_filter . '][weight]', $edit['filters[' . $second_filter . '][weight]'], t('Changes reverted.'));
$this->assertFieldByName('filters[' . $first_filter . '][weight]', $edit['filters[' . $first_filter . '][weight]'], t('Changes reverted.'));
}
/**
* Tests the URL filter settings form is properly validated.
*/
function testUrlFilterAdmin() {
// The form does not save with an invalid filter URL length.
$edit = array(
'filters[filter_url][settings][filter_url_length]' => $this->randomName(4),
);
$this->drupalPost('admin/config/content/formats/filtered_html', $edit, t('Save configuration'));
$this->assertNoRaw(t('The text format %format has been updated.', array('%format' => 'Filtered HTML')));
}
}
class FilterFormatAccessTestCase extends DrupalWebTestCase {
......
......@@ -411,23 +411,6 @@ function image_effect_delete_form_submit($form, &$form_state) {
$form_state['redirect'] = 'admin/config/media/image-styles/edit/' . $style['name'];
}
/**
* Element validate handler to ensure an integer pixel value.
*
* The property #allow_negative = TRUE may be set to allow negative integers.
*/
function image_effect_integer_validate($element, &$form_state) {
$value = empty($element['#allow_negative']) ? $element['#value'] : preg_replace('/^-/', '', $element['#value']);
if ($element['#value'] != '' && (!is_numeric($value) || intval($value) <= 0)) {
if (empty($element['#allow_negative'])) {
form_error($element, t('!name must be an integer.', array('!name' => $element['#title'])));
}
else {
form_error($element, t('!name must be a positive integer.', array('!name' => $element['#title'])));
}
}
}
/**
* Element validate handler to ensure a hexadecimal color value.
*/
......@@ -462,24 +445,22 @@ function image_effect_scale_validate($element, &$form_state) {
*/
function image_resize_form($data) {
$form['width'] = array(
'#type' => 'textfield',
'#type' => 'number',
'#title' => t('Width'),
'#default_value' => isset($data['width']) ? $data['width'] : '',
'#field_suffix' => ' ' . t('pixels'),
'#required' => TRUE,
'#size' => 10,
'#element_validate' => array('image_effect_integer_validate'),
'#allow_negative' => FALSE,
'#min' => 1,
);
$form['height'] = array(
'#type' => 'textfield',
'#type' => 'number',
'#title' => t('Height'),
'#default_value' => isset($data['height']) ? $data['height'] : '',
'#field_suffix' => ' ' . t('pixels'),
'#required' => TRUE,
'#size' => 10,
'#element_validate' => array('image_effect_integer_validate'),
'#allow_negative' => FALSE,
'#min' => 1,
);
return $form;
}
......@@ -560,7 +541,7 @@ function image_crop_form($data) {
*/
function image_rotate_form($data) {
$form['degrees'] = array(
'#type' => 'textfield',
'#type' => 'number',
'#default_value' => (isset($data['degrees'])) ? $data['degrees'] : 0,
'#title' => t('Rotation angle'),
'#description' => t('The number of degrees the image should be rotated. Positive numbers are clockwise, negative are counter-clockwise.'),
......@@ -568,8 +549,6 @@ function image_rotate_form($data) {
'#required' => TRUE,
'#size' => 6,
'#maxlength' => 4,
'#element_validate' => array('image_effect_integer_validate'),
'#allow_negative' => TRUE,
);
$form['bgcolor'] = array(
'#type' => 'textfield',
......
......@@ -86,21 +86,23 @@ function image_field_instance_settings_form($field, $instance) {
'#description' => t('The maximum allowed image size expressed as WIDTHxHEIGHT (e.g. 640x480). Leave blank for no restriction. If a larger image is uploaded, it will be resized to reflect the given width and height. Resizing images on upload will cause the loss of <a href="http://en.wikipedia.org/wiki/Exchangeable_image_file_format">EXIF data</a> in the image.'),
);
$form['max_resolution']['x'] = array(
'#type' => 'textfield',
'#type' => 'number',
'#title' => t('Maximum width'),
'#title_display' => 'invisible',
'#default_value' => $max_resolution[0],
'#size' => 5,
'#maxlength' => 5,
'#min' => 1,
'#field_suffix' => ' x ',
);
$form['max_resolution']['y'] = array(
'#type' => 'textfield',
'#type' => 'number',
'#title' => t('Maximum height'),
'#title_display' => 'invisible',
'#default_value' => $max_resolution[1],
'#size' => 5,
'#maxlength' => 5,
'#min' => 1,
'#field_suffix' => ' ' . t('pixels'),
);
......@@ -115,21 +117,23 @@ function image_field_instance_settings_form($field, $instance) {
'#description' => t('The minimum allowed image size expressed as WIDTHxHEIGHT (e.g. 640x480). Leave blank for no restriction. If a smaller image is uploaded, it will be rejected.'),
);
$form['min_resolution']['x'] = array(
'#type' => 'textfield',
'#type' => 'number',
'#title' => t('Minimum width'),
'#title_display' => 'invisible',
'#default_value' => $min_resolution[0],
'#size' => 5,
'#maxlength' => 5,
'#min' => 1,
'#field_suffix' => ' x ',
);
$form['min_resolution']['y'] = array(
'#type' => 'textfield',
'#type' => 'number',
'#title' => t('Minimum height'),
'#title_display' => 'invisible',
'#default_value' => $min_resolution[1],
'#size' => 5,
'#maxlength' => 5,
'#min' => 1,
'#field_suffix' => ' ' . t('pixels'),
);
......@@ -161,17 +165,12 @@ function image_field_instance_settings_form($field, $instance) {
function _image_field_resolution_validate($element, &$form_state) {
if (!empty($element['x']['#value']) || !empty($element['y']['#value'])) {
foreach (array('x', 'y') as $dimension) {
$value = $element[$dimension]['#value'];
if (!is_numeric($value)) {
form_error($element[$dimension], t('Height and width values must be numeric.'));
return;
}
if (intval($value) == 0) {
if (!$element[$dimension]['#value']) {
form_error($element[$dimension], t('Both a height and width value must be specified in the !name field.', array('!name' => $element['#title'])));
return;
}
}
form_set_value($element, intval($element['x']['#value']) . 'x' . intval($element['y']['#value']), $form_state);
form_set_value($element, $element['x']['#value'] . 'x' . $element['y']['#value'], $form_state);
}
else {
form_set_value($element, '', $form_state);
......
......@@ -90,11 +90,12 @@ function search_admin_settings($form) {
'#markup' => t('<p><em>Changing the settings below will cause the site index to be rebuilt. The search index is not cleared but systematically updated to reflect the new settings. Searching will continue to work but new content won\'t be indexed until all existing content has been re-indexed.</em></p><p><em>The default settings should be appropriate for the majority of sites.</em></p>')
);
$form['indexing_settings']['minimum_word_size'] = array(
'#type' => 'textfield',
'#type' => 'number',
'#title' => t('Minimum word length to index'),
'#default_value' => variable_get('minimum_word_size', 3),
'#size' => 5,
'#maxlength' => 3,
'#min' => 1,
'#description' => t('The number of characters a word has to be to be indexed. A lower setting means better search result ranking, but also a larger database. Each search query must contain at least one keyword that is this size (or longer).')
);
$form['indexing_settings']['overlap_cjk'] = array(
......
......@@ -1477,6 +1477,17 @@ class SearchConfigSettingsForm extends SearchWebTestCase {
$this->assertText(t('The index will be rebuilt'));
$this->drupalGet('admin/config/search/settings');
$this->assertText(t('There is 1 item left to index.'));
// Test that the form saves with the default values.
$this->drupalPost('admin/config/search/settings', array(), t('Save configuration'));
$this->assertText(t('The configuration options have been saved.'), 'Form saves with the default values.');
// Test that the form does not save with an invalid word length.
$edit = array(
'minimum_word_size' => $this->randomName(3),
);
$this->drupalPost('admin/config/search/settings', $edit, t('Save configuration'));
$this->assertNoText(t('The configuration options have been saved.'), 'Form does not save with an invalid word length.');
}
/**
......
......@@ -20,15 +20,16 @@ function image_gd_settings() {
);
$form['image_jpeg_quality'] = array(
'#type' => 'textfield',
'#type' => 'number',
'#title' => t('JPEG quality'),
'#description' => t('Define the image quality for JPEG manipulations. Ranges from 0 to 100. Higher values mean better image quality but bigger files.'),
'#size' => 10,
'#maxlength' => 3,
'#min' => 0,
'#max' => 100,
'#default_value' => variable_get('image_jpeg_quality', 75),
'#field_suffix' => t('%'),
);
$form['#element_validate'] = array('image_gd_settings_validate');
return $form;
}
......@@ -38,17 +39,6 @@ function image_gd_settings() {
}
}
/**
* Validate the submitted GD settings.
*/
function image_gd_settings_validate($form, &$form_state) {
// Validate image quality range.
$value = $form_state['values']['image_jpeg_quality'];
if (!is_numeric($value) || $value < 0 || $value > 100) {
form_set_error('image_jpeg_quality', t('JPEG quality must be a number between 0 and 100.'));
}
}
/**
* Verify GD2 settings (that the right version is actually installed).
*
......
......@@ -401,11 +401,12 @@ function user_admin_settings() {
'#description' => t('Pictures larger than this will be scaled down to this size.'),
);
$form['personalization']['pictures']['user_picture_file_size'] = array(
'#type' => 'textfield',
'#type' => 'number',
'#title' => t('Picture upload file size'),
'#default_value' => variable_get('user_picture_file_size', '30'),
'#size' => 10,
'#maxlength' => 10,
'#min' => 0,
'#field_suffix' => ' ' . t('KB'),
'#description' => t('Maximum allowed file size for uploaded pictures. Upload size is normally limited only by the PHP maximum post and file upload settings, and images are automatically scaled down to the dimensions specified above.'),
);
......
......@@ -1206,6 +1206,24 @@ class UserPictureTestCase extends DrupalWebTestCase {
$account = user_load($this->user->uid, TRUE);
return isset($account->picture) ? $account->picture->uri : NULL;
}
/**
* Tests the admin form validates user picture settings.
*/
function testUserPictureAdminFormValidation() {
$this->drupalLogin($this->drupalCreateUser(array('administer users')));
// The default values are valid.
$this->drupalPost('admin/config/people/accounts', array(), t('Save configuration'));
$this->assertText(t('The configuration options have been saved.'), 'The default values are valid.');
// The form does not save with an invalid file size.
$edit = array(
'user_picture_file_size' => $this->randomName(),
);
$this->drupalPost('admin/config/people/accounts', $edit, t('Save configuration'));
$this->assertNoText(t('The configuration options have been saved.'), 'The form does not save with an invalid file size.');
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment