update to drupal 7.23

This commit is contained in:
Bachir Soussi Chiadmi
2013-09-24 09:05:59 +02:00
parent db5f70501a
commit e539e701f8
247 changed files with 4921 additions and 4058 deletions

View File

@@ -32,10 +32,9 @@ function image_style_list() {
* An image style array.
* @ingroup forms
* @see image_style_form_submit()
* @see image_style_name_validate()
*/
function image_style_form($form, &$form_state, $style) {
$title = t('Edit %name style', array('%name' => $style['name']));
$title = t('Edit %name style', array('%name' => $style['label']));
drupal_set_title($title, PASS_THROUGH);
// Adjust this form for styles that must be overridden to edit.
@@ -56,27 +55,31 @@ function image_style_form($form, &$form_state, $style) {
'#markup' => theme('image_style_preview', array('style' => $style)),
);
// Show the Image Style label.
$form['label'] = array(
'#type' => 'textfield',
'#title' => t('Image style name'),
'#default_value' => $style['label'],
'#disabled' => !$editable,
'#required' => TRUE,
);
// Allow the name of the style to be changed, unless this style is
// provided by a module's hook_default_image_styles().
if ($style['storage'] & IMAGE_STORAGE_MODULE) {
$form['name'] = array(
'#type' => 'item',
'#title' => t('Image style name'),
'#markup' => $style['name'],
'#description' => t('This image style is being provided by %module module and may not be renamed.', array('%module' => $style['module'])),
);
}
else {
$form['name'] = array(
'#type' => 'textfield',
'#size' => '64',
'#title' => t('Image style name'),
'#default_value' => $style['name'],
'#description' => t('The name is used in URLs for generated images. Use only lowercase alphanumeric characters, underscores (_), and hyphens (-).'),
'#element_validate' => array('image_style_name_validate'),
'#required' => TRUE,
);
}
$form['name'] = array(
'#type' => 'machine_name',
'#size' => '64',
'#default_value' => $style['name'],
'#disabled' => !$editable,
'#description' => t('The name is used in URLs for generated images. Use only lowercase alphanumeric characters, underscores (_), and hyphens (-).'),
'#required' => TRUE,
'#machine_name' => array(
'exists' => 'image_style_load',
'source' => array('label'),
'replace_pattern' => '[^0-9a-z_\-]',
'error' => t('Please only use lowercase alphanumeric characters, underscores (_), and hyphens (-) for style names.'),
),
);
// Build the list of existing image effects for this image style.
$form['effects'] = array(
@@ -199,7 +202,7 @@ function image_style_form_add_submit($form, &$form_state) {
* Submit handler for overriding a module-defined style.
*/
function image_style_form_override_submit($form, &$form_state) {
drupal_set_message(t('The %style style has been overridden, allowing you to change its settings.', array('%style' => $form_state['image_style']['name'])));
drupal_set_message(t('The %style style has been overridden, allowing you to change its settings.', array('%style' => $form_state['image_style']['label'])));
image_default_style_save($form_state['image_style']);
}
@@ -207,11 +210,10 @@ function image_style_form_override_submit($form, &$form_state) {
* Submit handler for saving an image style.
*/
function image_style_form_submit($form, &$form_state) {
// Update the image style name if it has changed.
// Update the image style.
$style = $form_state['image_style'];
if (isset($form_state['values']['name']) && $style['name'] != $form_state['values']['name']) {
$style['name'] = $form_state['values']['name'];
}
$style['name'] = $form_state['values']['name'];
$style['label'] = $form_state['values']['label'];
// Update image effect weights.
if (!empty($form_state['values']['effects'])) {
@@ -236,18 +238,26 @@ function image_style_form_submit($form, &$form_state) {
*
* @ingroup forms
* @see image_style_add_form_submit()
* @see image_style_name_validate()
*/
function image_style_add_form($form, &$form_state) {
$form['name'] = array(
$form['label'] = array(
'#type' => 'textfield',
'#size' => '64',
'#title' => t('Style name'),
'#default_value' => '',
'#description' => t('The name is used in URLs for generated images. Use only lowercase alphanumeric characters, underscores (_), and hyphens (-).'),
'#element_validate' => array('image_style_name_validate'),
'#required' => TRUE,
);
$form['name'] = array(
'#type' => 'machine_name',
'#description' => t('The name is used in URLs for generated images. Use only lowercase alphanumeric characters, underscores (_), and hyphens (-).'),
'#size' => '64',
'#required' => TRUE,
'#machine_name' => array(
'exists' => 'image_style_load',
'source' => array('label'),
'replace_pattern' => '[^0-9a-z_\-]',
'error' => t('Please only use lowercase alphanumeric characters, underscores (_), and hyphens (-) for style names.'),
),
);
$form['submit'] = array(
'#type' => 'submit',
@@ -261,14 +271,22 @@ function image_style_add_form($form, &$form_state) {
* Submit handler for adding a new image style.
*/
function image_style_add_form_submit($form, &$form_state) {
$style = array('name' => $form_state['values']['name']);
$style = array(
'name' => $form_state['values']['name'],
'label' => $form_state['values']['label'],
);
$style = image_style_save($style);
drupal_set_message(t('Style %name was created.', array('%name' => $style['name'])));
drupal_set_message(t('Style %name was created.', array('%name' => $style['label'])));
$form_state['redirect'] = 'admin/config/media/image-styles/edit/' . $style['name'];
}
/**
* Element validate function to ensure unique, URL safe style names.
*
* This function is no longer used in Drupal core since image style names are
* now validated using #machine_name functionality. It is kept for backwards
* compatibility (since non-core modules may be using it) and will be removed
* in Drupal 8.
*/
function image_style_name_validate($element, $form_state) {
// Check for duplicates.
@@ -295,7 +313,7 @@ function image_style_name_validate($element, $form_state) {
function image_style_delete_form($form, &$form_state, $style) {
$form_state['image_style'] = $style;
$replacement_styles = array_diff_key(image_style_options(), array($style['name'] => ''));
$replacement_styles = array_diff_key(image_style_options(TRUE, PASS_THROUGH), array($style['name'] => ''));
$form['replacement'] = array(
'#title' => t('Replacement style'),
'#type' => 'select',
@@ -305,7 +323,7 @@ function image_style_delete_form($form, &$form_state, $style) {
return confirm_form(
$form,
t('Optionally select a style before deleting %style', array('%style' => $style['name'])),
t('Optionally select a style before deleting %style', array('%style' => $style['label'])),
'admin/config/media/image-styles',
t('If this style is in use on the site, you may select another style to replace it. All images that have been generated for this style will be permanently deleted.'),
t('Delete'), t('Cancel')
@@ -319,7 +337,7 @@ function image_style_delete_form_submit($form, &$form_state) {
$style = $form_state['image_style'];
image_style_delete($style, $form_state['values']['replacement']);
drupal_set_message(t('Style %name was deleted.', array('%name' => $style['name'])));
drupal_set_message(t('Style %name was deleted.', array('%name' => $style['label'])));
$form_state['redirect'] = 'admin/config/media/image-styles';
}
@@ -331,7 +349,7 @@ function image_style_revert_form($form, &$form_state, $style) {
return confirm_form(
$form,
t('Revert the %style style?', array('%style' => $style['name'])),
t('Revert the %style style?', array('%style' => $style['label'])),
'admin/config/media/image-styles',
t('Reverting this style will delete the customized settings and restore the defaults provided by the @module module.', array('@module' => $style['module'])),
t('Revert'), t('Cancel')
@@ -342,7 +360,7 @@ function image_style_revert_form($form, &$form_state, $style) {
* Submit handler to convert an overridden style to its default.
*/
function image_style_revert_form_submit($form, &$form_state) {
drupal_set_message(t('The %style style has been reverted to its defaults.', array('%style' => $form_state['image_style']['name'])));
drupal_set_message(t('The %style style has been reverted to its defaults.', array('%style' => $form_state['image_style']['label'])));
image_default_style_revert($form_state['image_style']);
$form_state['redirect'] = 'admin/config/media/image-styles';
}
@@ -439,7 +457,7 @@ function image_effect_delete_form($form, &$form_state, $style, $effect) {
$form_state['image_style'] = $style;
$form_state['image_effect'] = $effect;
$question = t('Are you sure you want to delete the @effect effect from the %style style?', array('%style' => $style['name'], '@effect' => $effect['label']));
$question = t('Are you sure you want to delete the @effect effect from the %style style?', array('%style' => $style['label'], '@effect' => $effect['label']));
return confirm_form($form, $question, 'admin/config/media/image-styles/edit/' . $style['name'], '', t('Delete'));
}
@@ -650,7 +668,7 @@ function theme_image_style_list($variables) {
$rows = array();
foreach ($styles as $style) {
$row = array();
$row[] = l($style['name'], 'admin/config/media/image-styles/edit/' . $style['name']);
$row[] = l($style['label'], 'admin/config/media/image-styles/edit/' . $style['name']);
$link_attributes = array(
'attributes' => array(
'class' => array('image-style-link'),
@@ -805,7 +823,7 @@ function theme_image_style_preview($variables) {
// Build the preview of the image style.
$preview_url = file_create_url($preview_file) . '?cache_bypass=' . REQUEST_TIME;
$output .= '<div class="preview-image-wrapper">';
$output .= check_plain($style['name']) . ' (' . l(t('view actual size'), file_create_url($preview_file) . '?' . time()) . ')';
$output .= check_plain($style['label']) . ' (' . l(t('view actual size'), file_create_url($preview_file) . '?' . time()) . ')';
$output .= '<div class="preview-image modified-image" style="' . $preview_attributes['style'] . '">';
$output .= '<a href="' . file_create_url($preview_file) . '?' . time() . '">' . theme('image', array('path' => $preview_url, 'alt' => t('Sample modified image'), 'title' => '', 'attributes' => $preview_attributes)) . '</a>';
$output .= '<div class="height" style="height: ' . $preview_height . 'px"><span>' . $preview_image['height'] . 'px</span></div>';

View File

@@ -177,6 +177,7 @@ function hook_image_default_styles() {
$styles = array();
$styles['mymodule_preview'] = array(
'label' => 'My module preview',
'effects' => array(
array(
'name' => 'image_scale',

View File

@@ -311,7 +311,7 @@ function image_field_widget_settings_form($field, $instance) {
$form['preview_image_style'] = array(
'#title' => t('Preview image style'),
'#type' => 'select',
'#options' => image_style_options(FALSE),
'#options' => image_style_options(FALSE, PASS_THROUGH),
'#empty_option' => '<' . t('no preview') . '>',
'#default_value' => $settings['preview_image_style'],
'#description' => t('The preview image will be shown while editing the content.'),
@@ -495,7 +495,7 @@ function image_field_formatter_settings_form($field, $instance, $view_mode, $for
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$image_styles = image_style_options(FALSE);
$image_styles = image_style_options(FALSE, PASS_THROUGH);
$element['image_style'] = array(
'#title' => t('Image style'),
'#type' => 'select',
@@ -528,7 +528,7 @@ function image_field_formatter_settings_summary($field, $instance, $view_mode) {
$summary = array();
$image_styles = image_style_options(FALSE);
$image_styles = image_style_options(FALSE, PASS_THROUGH);
// Unset possible 'No defined styles' option.
unset($image_styles['']);
// Styles could be lost because of enabled/disabled modules that defines

View File

@@ -7,8 +7,8 @@ dependencies[] = file
files[] = image.test
configure = admin/config/media/image-styles
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by drupal.org packaging script on 2013-08-08
version = "7.23"
project = "drupal"
datestamp = "1365027012"
datestamp = "1375928238"

View File

@@ -41,11 +41,18 @@ function image_schema() {
'not null' => TRUE,
),
'name' => array(
'description' => 'The style name.',
'description' => 'The style machine name.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'label' => array(
'description' => 'The style administrative name.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
),
'primary key' => array('isid'),
'unique keys' => array(
@@ -448,6 +455,30 @@ function image_update_7004() {
}
}
/**
* Add a column to the 'image_style' table to store administrative labels.
*/
function image_update_7005() {
$field = array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'The style administrative name.',
);
db_add_field('image_styles', 'label', $field);
// Do a direct query here, rather than calling image_styles(),
// in case Image module is disabled.
$styles = db_query('SELECT name FROM {image_styles}')->fetchCol();
foreach ($styles as $style) {
db_update('image_styles')
->fields(array('label' => $style))
->condition('name', $style)
->execute();
}
}
/**
* @} End of "addtogroup updates-7.x-extra".
*/

View File

@@ -347,6 +347,7 @@ function image_image_default_styles() {
$styles = array();
$styles['thumbnail'] = array(
'label' => 'Thumbnail (100x100)',
'effects' => array(
array(
'name' => 'image_scale',
@@ -357,6 +358,7 @@ function image_image_default_styles() {
);
$styles['medium'] = array(
'label' => 'Medium (220x220)',
'effects' => array(
array(
'name' => 'image_scale',
@@ -367,6 +369,7 @@ function image_image_default_styles() {
);
$styles['large'] = array(
'label' => 'Large (480x480)',
'effects' => array(
array(
'name' => 'image_scale',
@@ -575,6 +578,7 @@ function image_styles() {
$module_styles = module_invoke($module, 'image_default_styles');
foreach ($module_styles as $style_name => $style) {
$style['name'] = $style_name;
$style['label'] = empty($style['label']) ? $style_name : $style['label'];
$style['module'] = $module;
$style['storage'] = IMAGE_STORAGE_DEFAULT;
foreach ($style['effects'] as $key => $effect) {
@@ -689,6 +693,10 @@ function image_style_save($style) {
}
}
else {
// Add a default label when not given.
if (empty($style['label'])) {
$style['label'] = $style['name'];
}
drupal_write_record('image_styles', $style);
$style['is_new'] = TRUE;
}
@@ -758,20 +766,28 @@ function image_style_effects($style) {
*
* @param $include_empty
* If TRUE a <none> option will be inserted in the options array.
* @param $output
* Optional flag determining how the options will be sanitized on output.
* Leave this at the default (CHECK_PLAIN) if you are using the output of
* this function directly in an HTML context, such as for checkbox or radio
* button labels, and do not plan to sanitize it on your own. If using the
* output of this function as select list options (its primary use case), you
* should instead set this flag to PASS_THROUGH to avoid double-escaping of
* the output (the form API sanitizes select list options by default).
*
* @return
* Array of image styles both key and value are set to style name.
* Array of image styles with the machine name as key and the label as value.
*/
function image_style_options($include_empty = TRUE) {
function image_style_options($include_empty = TRUE, $output = CHECK_PLAIN) {
$styles = image_styles();
$options = array();
if ($include_empty && !empty($styles)) {
$options[''] = t('<none>');
}
// Use the array concatenation operator '+' here instead of array_merge(),
// because the latter loses the datatype of the array keys, turning
// associative string keys into numeric ones without warning.
$options = $options + drupal_map_assoc(array_keys($styles));
foreach ($styles as $name => $style) {
$options[$name] = ($output == PASS_THROUGH) ? $style['label'] : check_plain($style['label']);
}
if (empty($options)) {
$options[''] = t('No defined styles');
}
@@ -953,9 +969,10 @@ function image_style_transform_dimensions($style_name, array &$dimensions) {
* An image style array.
*/
function image_style_flush($style) {
$style_directory = drupal_realpath(file_default_scheme() . '://styles/' . $style['name']);
if (is_dir($style_directory)) {
file_unmanaged_delete_recursive($style_directory);
// Delete the style directory in each registered wrapper.
$wrappers = file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE);
foreach ($wrappers as $wrapper => $wrapper_data) {
file_unmanaged_delete_recursive($wrapper . '://styles/' . $style['name']);
}
// Let other modules update as necessary on flush.

View File

@@ -17,7 +17,6 @@
* image_style_save()
* image_style_delete()
* image_style_options()
* image_style_flush()
* image_effect_definition_load()
* image_effect_load()
* image_effect_save()
@@ -122,7 +121,7 @@ class ImageStylesPathAndUrlTestCase extends DrupalWebTestCase {
parent::setUp('image_module_test');
$this->style_name = 'style_foo';
image_style_save(array('name' => $this->style_name));
image_style_save(array('name' => $this->style_name, 'label' => $this->randomString()));
}
/**
@@ -132,11 +131,11 @@ class ImageStylesPathAndUrlTestCase extends DrupalWebTestCase {
$scheme = 'public';
$actual = image_style_path($this->style_name, "$scheme://foo/bar.gif");
$expected = "$scheme://styles/" . $this->style_name . "/$scheme/foo/bar.gif";
$this->assertEqual($actual, $expected, t('Got the path for a file URI.'));
$this->assertEqual($actual, $expected, 'Got the path for a file URI.');
$actual = image_style_path($this->style_name, 'foo/bar.gif');
$expected = "$scheme://styles/" . $this->style_name . "/$scheme/foo/bar.gif";
$this->assertEqual($actual, $expected, t('Got the path for a relative file path.'));
$this->assertEqual($actual, $expected, 'Got the path for a relative file path.');
}
/**
@@ -186,7 +185,7 @@ class ImageStylesPathAndUrlTestCase extends DrupalWebTestCase {
// Create the directories for the styles.
$directory = $scheme . '://styles/' . $this->style_name;
$status = file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
$this->assertNotIdentical(FALSE, $status, t('Created the directory for the generated images for the test style.'));
$this->assertNotIdentical(FALSE, $status, 'Created the directory for the generated images for the test style.');
// Create a working copy of the file.
$files = $this->drupalGetTestFiles('image');
@@ -196,11 +195,11 @@ class ImageStylesPathAndUrlTestCase extends DrupalWebTestCase {
// Let the image_module_test module know about this file, so it can claim
// ownership in hook_file_download().
variable_set('image_module_test_file_download', $original_uri);
$this->assertNotIdentical(FALSE, $original_uri, t('Created the generated image file.'));
$this->assertNotIdentical(FALSE, $original_uri, 'Created the generated image file.');
// Get the URL of a file that has not been generated and try to create it.
$generated_uri = image_style_path($this->style_name, $original_uri);
$this->assertFalse(file_exists($generated_uri), t('Generated file does not exist.'));
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$generate_url = image_style_url($this->style_name, $original_uri);
// Ensure that the tests still pass when the file is generated by accessing
@@ -224,21 +223,21 @@ class ImageStylesPathAndUrlTestCase extends DrupalWebTestCase {
// Fetch the URL that generates the file.
$this->drupalGet($generate_url);
$this->assertResponse(200, t('Image was generated at the URL.'));
$this->assertTrue(file_exists($generated_uri), t('Generated file does exist after we accessed it.'));
$this->assertRaw(file_get_contents($generated_uri), t('URL returns expected file.'));
$this->assertResponse(200, 'Image was generated at the URL.');
$this->assertTrue(file_exists($generated_uri), 'Generated file does exist after we accessed it.');
$this->assertRaw(file_get_contents($generated_uri), 'URL returns expected file.');
$generated_image_info = image_get_info($generated_uri);
$this->assertEqual($this->drupalGetHeader('Content-Type'), $generated_image_info['mime_type'], t('Expected Content-Type was reported.'));
$this->assertEqual($this->drupalGetHeader('Content-Length'), $generated_image_info['file_size'], t('Expected Content-Length was reported.'));
$this->assertEqual($this->drupalGetHeader('Content-Type'), $generated_image_info['mime_type'], 'Expected Content-Type was reported.');
$this->assertEqual($this->drupalGetHeader('Content-Length'), $generated_image_info['file_size'], 'Expected Content-Length was reported.');
if ($scheme == 'private') {
$this->assertEqual($this->drupalGetHeader('Expires'), 'Sun, 19 Nov 1978 05:00:00 GMT', t('Expires header was sent.'));
$this->assertEqual($this->drupalGetHeader('Cache-Control'), 'no-cache, must-revalidate, post-check=0, pre-check=0', t('Cache-Control header was set to prevent caching.'));
$this->assertEqual($this->drupalGetHeader('X-Image-Owned-By'), 'image_module_test', t('Expected custom header has been added.'));
$this->assertEqual($this->drupalGetHeader('Expires'), 'Sun, 19 Nov 1978 05:00:00 GMT', 'Expires header was sent.');
$this->assertEqual($this->drupalGetHeader('Cache-Control'), 'no-cache, must-revalidate, post-check=0, pre-check=0', 'Cache-Control header was set to prevent caching.');
$this->assertEqual($this->drupalGetHeader('X-Image-Owned-By'), 'image_module_test', 'Expected custom header has been added.');
// Make sure that a second request to the already existing derivate works
// too.
$this->drupalGet($generate_url);
$this->assertResponse(200, t('Image was generated at the URL.'));
$this->assertResponse(200, 'Image was generated at the URL.');
// Make sure that access is denied for existing style files if we do not
// have access.
@@ -251,11 +250,11 @@ class ImageStylesPathAndUrlTestCase extends DrupalWebTestCase {
$file_noaccess = array_shift($files);
$original_uri_noaccess = file_unmanaged_copy($file_noaccess->uri, $scheme . '://', FILE_EXISTS_RENAME);
$generated_uri_noaccess = $scheme . '://styles/' . $this->style_name . '/' . $scheme . '/'. drupal_basename($original_uri_noaccess);
$this->assertFalse(file_exists($generated_uri_noaccess), t('Generated file does not exist.'));
$this->assertFalse(file_exists($generated_uri_noaccess), 'Generated file does not exist.');
$generate_url_noaccess = image_style_url($this->style_name, $original_uri_noaccess);
$this->drupalGet($generate_url_noaccess);
$this->assertResponse(403, t('Confirmed that access is denied for the private image style.') );
$this->assertResponse(403, 'Confirmed that access is denied for the private image style.');
// Verify that images are not appended to the response. Currently this test only uses PNG images.
if (strpos($generate_url, '.png') === FALSE ) {
$this->fail('Confirming that private image styles are not appended require PNG file.');
@@ -341,13 +340,13 @@ class ImageEffectsUnitTest extends ImageToolkitTestCase {
* Test the image_resize_effect() function.
*/
function testResizeEffect() {
$this->assertTrue(image_resize_effect($this->image, array('width' => 1, 'height' => 2)), t('Function returned the expected value.'));
$this->assertTrue(image_resize_effect($this->image, array('width' => 1, 'height' => 2)), 'Function returned the expected value.');
$this->assertToolkitOperationsCalled(array('resize'));
// Check the parameters.
$calls = image_test_get_all_calls();
$this->assertEqual($calls['resize'][0][1], 1, t('Width was passed correctly'));
$this->assertEqual($calls['resize'][0][2], 2, t('Height was passed correctly'));
$this->assertEqual($calls['resize'][0][1], 1, 'Width was passed correctly');
$this->assertEqual($calls['resize'][0][2], 2, 'Height was passed correctly');
}
/**
@@ -355,13 +354,13 @@ class ImageEffectsUnitTest extends ImageToolkitTestCase {
*/
function testScaleEffect() {
// @todo: need to test upscaling.
$this->assertTrue(image_scale_effect($this->image, array('width' => 10, 'height' => 10)), t('Function returned the expected value.'));
$this->assertTrue(image_scale_effect($this->image, array('width' => 10, 'height' => 10)), 'Function returned the expected value.');
$this->assertToolkitOperationsCalled(array('resize'));
// Check the parameters.
$calls = image_test_get_all_calls();
$this->assertEqual($calls['resize'][0][1], 10, t('Width was passed correctly'));
$this->assertEqual($calls['resize'][0][2], 5, t('Height was based off aspect ratio and passed correctly'));
$this->assertEqual($calls['resize'][0][1], 10, 'Width was passed correctly');
$this->assertEqual($calls['resize'][0][2], 5, 'Height was based off aspect ratio and passed correctly');
}
/**
@@ -369,42 +368,42 @@ class ImageEffectsUnitTest extends ImageToolkitTestCase {
*/
function testCropEffect() {
// @todo should test the keyword offsets.
$this->assertTrue(image_crop_effect($this->image, array('anchor' => 'top-1', 'width' => 3, 'height' => 4)), t('Function returned the expected value.'));
$this->assertTrue(image_crop_effect($this->image, array('anchor' => 'top-1', 'width' => 3, 'height' => 4)), 'Function returned the expected value.');
$this->assertToolkitOperationsCalled(array('crop'));
// Check the parameters.
$calls = image_test_get_all_calls();
$this->assertEqual($calls['crop'][0][1], 0, t('X was passed correctly'));
$this->assertEqual($calls['crop'][0][2], 1, t('Y was passed correctly'));
$this->assertEqual($calls['crop'][0][3], 3, t('Width was passed correctly'));
$this->assertEqual($calls['crop'][0][4], 4, t('Height was passed correctly'));
$this->assertEqual($calls['crop'][0][1], 0, 'X was passed correctly');
$this->assertEqual($calls['crop'][0][2], 1, 'Y was passed correctly');
$this->assertEqual($calls['crop'][0][3], 3, 'Width was passed correctly');
$this->assertEqual($calls['crop'][0][4], 4, 'Height was passed correctly');
}
/**
* Test the image_scale_and_crop_effect() function.
*/
function testScaleAndCropEffect() {
$this->assertTrue(image_scale_and_crop_effect($this->image, array('width' => 5, 'height' => 10)), t('Function returned the expected value.'));
$this->assertTrue(image_scale_and_crop_effect($this->image, array('width' => 5, 'height' => 10)), 'Function returned the expected value.');
$this->assertToolkitOperationsCalled(array('resize', 'crop'));
// Check the parameters.
$calls = image_test_get_all_calls();
$this->assertEqual($calls['crop'][0][1], 7.5, t('X was computed and passed correctly'));
$this->assertEqual($calls['crop'][0][2], 0, t('Y was computed and passed correctly'));
$this->assertEqual($calls['crop'][0][3], 5, t('Width was computed and passed correctly'));
$this->assertEqual($calls['crop'][0][4], 10, t('Height was computed and passed correctly'));
$this->assertEqual($calls['crop'][0][1], 7.5, 'X was computed and passed correctly');
$this->assertEqual($calls['crop'][0][2], 0, 'Y was computed and passed correctly');
$this->assertEqual($calls['crop'][0][3], 5, 'Width was computed and passed correctly');
$this->assertEqual($calls['crop'][0][4], 10, 'Height was computed and passed correctly');
}
/**
* Test the image_desaturate_effect() function.
*/
function testDesaturateEffect() {
$this->assertTrue(image_desaturate_effect($this->image, array()), t('Function returned the expected value.'));
$this->assertTrue(image_desaturate_effect($this->image, array()), 'Function returned the expected value.');
$this->assertToolkitOperationsCalled(array('desaturate'));
// Check the parameters.
$calls = image_test_get_all_calls();
$this->assertEqual(count($calls['desaturate'][0]), 1, t('Only the image was passed.'));
$this->assertEqual(count($calls['desaturate'][0]), 1, 'Only the image was passed.');
}
/**
@@ -412,13 +411,13 @@ class ImageEffectsUnitTest extends ImageToolkitTestCase {
*/
function testRotateEffect() {
// @todo: need to test with 'random' => TRUE
$this->assertTrue(image_rotate_effect($this->image, array('degrees' => 90, 'bgcolor' => '#fff')), t('Function returned the expected value.'));
$this->assertTrue(image_rotate_effect($this->image, array('degrees' => 90, 'bgcolor' => '#fff')), 'Function returned the expected value.');
$this->assertToolkitOperationsCalled(array('rotate'));
// Check the parameters.
$calls = image_test_get_all_calls();
$this->assertEqual($calls['rotate'][0][1], 90, t('Degrees were passed correctly'));
$this->assertEqual($calls['rotate'][0][2], 0xffffff, t('Background color was passed correctly'));
$this->assertEqual($calls['rotate'][0][1], 90, 'Degrees were passed correctly');
$this->assertEqual($calls['rotate'][0][2], 0xffffff, 'Background color was passed correctly');
}
/**
@@ -484,13 +483,15 @@ class ImageAdminStylesUnitTest extends ImageFieldTestCase {
*/
function testNumericStyleName() {
$style_name = rand();
$style_label = $this->randomString();
$edit = array(
'name' => $style_name,
'label' => $style_label,
);
$this->drupalPost('admin/config/media/image-styles/add', $edit, t('Create new style'));
$this->assertRaw(t('Style %name was created.', array('%name' => $style_name)), t('Image style successfully created.'));
$this->assertRaw(t('Style %name was created.', array('%name' => $style_label)), 'Image style successfully created.');
$options = image_style_options();
$this->assertTrue(array_key_exists($style_name, $options), t('Array key %key exists.', array('%key' => $style_name)));
$this->assertTrue(array_key_exists($style_name, $options), format_string('Array key %key exists.', array('%key' => $style_name)));
}
/**
@@ -499,6 +500,7 @@ class ImageAdminStylesUnitTest extends ImageFieldTestCase {
function testStyle() {
// Setup a style to be created and effects to add to it.
$style_name = strtolower($this->randomName(10));
$style_label = $this->randomString();
$style_path = 'admin/config/media/image-styles/edit/' . $style_name;
$effect_edits = array(
'image_resize' => array(
@@ -533,9 +535,10 @@ class ImageAdminStylesUnitTest extends ImageFieldTestCase {
$edit = array(
'name' => $style_name,
'label' => $style_label,
);
$this->drupalPost('admin/config/media/image-styles/add', $edit, t('Create new style'));
$this->assertRaw(t('Style %name was created.', array('%name' => $style_name)), t('Image style successfully created.'));
$this->assertRaw(t('Style %name was created.', array('%name' => $style_label)), 'Image style successfully created.');
// Add effect form.
@@ -557,7 +560,7 @@ class ImageAdminStylesUnitTest extends ImageFieldTestCase {
foreach ($style['effects'] as $ieid => $effect) {
$this->drupalGet($style_path . '/effects/' . $ieid);
foreach ($effect_edits[$effect['name']] as $field => $value) {
$this->assertFieldByName($field, $value, t('The %field field in the %effect effect has the correct value of %value.', array('%field' => $field, '%effect' => $effect['name'], '%value' => $value)));
$this->assertFieldByName($field, $value, format_string('The %field field in the %effect effect has the correct value of %value.', array('%field' => $field, '%effect' => $effect['name'], '%value' => $value)));
}
}
@@ -573,14 +576,16 @@ class ImageAdminStylesUnitTest extends ImageFieldTestCase {
$order_correct = FALSE;
}
}
$this->assertTrue($order_correct, t('The order of the effects is correctly set by default.'));
$this->assertTrue($order_correct, 'The order of the effects is correctly set by default.');
// Test the style overview form.
// Change the name of the style and adjust the weights of effects.
$style_name = strtolower($this->randomName(10));
$style_label = $this->randomString();
$weight = count($effect_edits);
$edit = array(
'name' => $style_name,
'label' => $style_label,
);
foreach ($style['effects'] as $ieid => $effect) {
$edit['effects[' . $ieid . '][weight]'] = $weight;
@@ -589,7 +594,7 @@ class ImageAdminStylesUnitTest extends ImageFieldTestCase {
// Create an image to make sure it gets flushed after saving.
$image_path = $this->createSampleImage($style);
$this->assertEqual($this->getImageCount($style), 1, t('Image style %style image %file successfully generated.', array('%style' => $style['name'], '%file' => $image_path)));
$this->assertEqual($this->getImageCount($style), 1, format_string('Image style %style image %file successfully generated.', array('%style' => $style['label'], '%file' => $image_path)));
$this->drupalPost($style_path, $edit, t('Update style'));
@@ -598,12 +603,12 @@ class ImageAdminStylesUnitTest extends ImageFieldTestCase {
// Check that the URL was updated.
$this->drupalGet($style_path);
$this->assertResponse(200, t('Image style %original renamed to %new', array('%original' => $style['name'], '%new' => $style_name)));
$this->assertResponse(200, format_string('Image style %original renamed to %new', array('%original' => $style['label'], '%new' => $style_label)));
// Check that the image was flushed after updating the style.
// This is especially important when renaming the style. Make sure that
// the old image directory has been deleted.
$this->assertEqual($this->getImageCount($style), 0, t('Image style %style was flushed after renaming the style and updating the order of effects.', array('%style' => $style['name'])));
$this->assertEqual($this->getImageCount($style), 0, format_string('Image style %style was flushed after renaming the style and updating the order of effects.', array('%style' => $style['label'])));
// Load the style by the new name with the new weights.
drupal_static_reset('image_styles');
@@ -618,18 +623,18 @@ class ImageAdminStylesUnitTest extends ImageFieldTestCase {
$order_correct = FALSE;
}
}
$this->assertTrue($order_correct, t('The order of the effects is correctly set by default.'));
$this->assertTrue($order_correct, 'The order of the effects is correctly set by default.');
// Image effect deletion form.
// Create an image to make sure it gets flushed after deleting an effect.
$image_path = $this->createSampleImage($style);
$this->assertEqual($this->getImageCount($style), 1, t('Image style %style image %file successfully generated.', array('%style' => $style['name'], '%file' => $image_path)));
$this->assertEqual($this->getImageCount($style), 1, format_string('Image style %style image %file successfully generated.', array('%style' => $style['label'], '%file' => $image_path)));
// Test effect deletion form.
$effect = array_pop($style['effects']);
$this->drupalPost($style_path . '/effects/' . $effect['ieid'] . '/delete', array(), t('Delete'));
$this->assertRaw(t('The image effect %name has been deleted.', array('%name' => $effect['label'])), t('Image effect deleted.'));
$this->assertRaw(t('The image effect %name has been deleted.', array('%name' => $effect['label'])), 'Image effect deleted.');
// Style deletion form.
@@ -638,10 +643,10 @@ class ImageAdminStylesUnitTest extends ImageFieldTestCase {
// Confirm the style directory has been removed.
$directory = file_default_scheme() . '://styles/' . $style_name;
$this->assertFalse(is_dir($directory), t('Image style %style directory removed on style deletion.', array('%style' => $style['name'])));
$this->assertFalse(is_dir($directory), format_string('Image style %style directory removed on style deletion.', array('%style' => $style['label'])));
drupal_static_reset('image_styles');
$this->assertFalse(image_style_load($style_name), t('Image style %style successfully deleted.', array('%style' => $style['name'])));
$this->assertFalse(image_style_load($style_name), format_string('Image style %style successfully deleted.', array('%style' => $style['label'])));
}
@@ -651,34 +656,36 @@ class ImageAdminStylesUnitTest extends ImageFieldTestCase {
function testDefaultStyle() {
// Setup a style to be created and effects to add to it.
$style_name = 'thumbnail';
$style_label = 'Thumbnail (100x100)';
$edit_path = 'admin/config/media/image-styles/edit/' . $style_name;
$delete_path = 'admin/config/media/image-styles/delete/' . $style_name;
$revert_path = 'admin/config/media/image-styles/revert/' . $style_name;
// Ensure deleting a default is not possible.
$this->drupalGet($delete_path);
$this->assertText(t('Page not found'), t('Default styles may not be deleted.'));
$this->assertText(t('Page not found'), 'Default styles may not be deleted.');
// Ensure that editing a default is not possible (without overriding).
$this->drupalGet($edit_path);
$this->assertNoField('edit-name', t('Default styles may not be renamed.'));
$this->assertNoField('edit-submit', t('Default styles may not be edited.'));
$this->assertNoField('edit-add', t('Default styles may not have new effects added.'));
$disabled_field = $this->xpath('//input[@id=:id and @disabled="disabled"]', array(':id' => 'edit-name'));
$this->assertTrue($disabled_field, 'Default styles may not be renamed.');
$this->assertNoField('edit-submit', 'Default styles may not be edited.');
$this->assertNoField('edit-add', 'Default styles may not have new effects added.');
// Create an image to make sure the default works before overriding.
drupal_static_reset('image_styles');
$style = image_style_load($style_name);
$image_path = $this->createSampleImage($style);
$this->assertEqual($this->getImageCount($style), 1, t('Image style %style image %file successfully generated.', array('%style' => $style['name'], '%file' => $image_path)));
$this->assertEqual($this->getImageCount($style), 1, format_string('Image style %style image %file successfully generated.', array('%style' => $style['name'], '%file' => $image_path)));
// Verify that effects attached to a default style do not have an ieid key.
foreach ($style['effects'] as $effect) {
$this->assertFalse(isset($effect['ieid']), t('The %effect effect does not have an ieid.', array('%effect' => $effect['name'])));
$this->assertFalse(isset($effect['ieid']), format_string('The %effect effect does not have an ieid.', array('%effect' => $effect['name'])));
}
// Override the default.
$this->drupalPost($edit_path, array(), t('Override defaults'));
$this->assertRaw(t('The %style style has been overridden, allowing you to change its settings.', array('%style' => $style_name)), t('Default image style may be overridden.'));
$this->assertRaw(t('The %style style has been overridden, allowing you to change its settings.', array('%style' => $style_label)), 'Default image style may be overridden.');
// Add sample effect to the overridden style.
$this->drupalPost($edit_path, array('new' => 'image_desaturate'), t('Add'));
@@ -687,22 +694,23 @@ class ImageAdminStylesUnitTest extends ImageFieldTestCase {
// Verify that effects attached to the style have an ieid now.
foreach ($style['effects'] as $effect) {
$this->assertTrue(isset($effect['ieid']), t('The %effect effect has an ieid.', array('%effect' => $effect['name'])));
$this->assertTrue(isset($effect['ieid']), format_string('The %effect effect has an ieid.', array('%effect' => $effect['name'])));
}
// The style should now have 2 effect, the original scale provided by core
// and the desaturate effect we added in the override.
$effects = array_values($style['effects']);
$this->assertEqual($effects[0]['name'], 'image_scale', t('The default effect still exists in the overridden style.'));
$this->assertEqual($effects[1]['name'], 'image_desaturate', t('The added effect exists in the overridden style.'));
$this->assertEqual($effects[0]['name'], 'image_scale', 'The default effect still exists in the overridden style.');
$this->assertEqual($effects[1]['name'], 'image_desaturate', 'The added effect exists in the overridden style.');
// Check that we are unable to rename an overridden style.
// Check that we are able to rename an overridden style.
$this->drupalGet($edit_path);
$this->assertNoField('edit-name', t('Overridden styles may not be renamed.'));
$disabled_field = $this->xpath('//input[@id=:id and @disabled="disabled"]', array(':id' => 'edit-name'));
$this->assertFalse($disabled_field, 'Overridden styles may be renamed.');
// Create an image to ensure the override works properly.
$image_path = $this->createSampleImage($style);
$this->assertEqual($this->getImageCount($style), 1, t('Image style %style image %file successfully generated.', array('%style' => $style['name'], '%file' => $image_path)));
$this->assertEqual($this->getImageCount($style), 1, format_string('Image style %style image %file successfully generated.', array('%style' => $style['label'], '%file' => $image_path)));
// Revert the image style.
$this->drupalPost($revert_path, array(), t('Revert'));
@@ -711,8 +719,8 @@ class ImageAdminStylesUnitTest extends ImageFieldTestCase {
// The style should now have the single effect for scale.
$effects = array_values($style['effects']);
$this->assertEqual($effects[0]['name'], 'image_scale', t('The default effect still exists in the reverted style.'));
$this->assertFalse(array_key_exists(1, $effects), t('The added effect has been removed in the reverted style.'));
$this->assertEqual($effects[0]['name'], 'image_scale', 'The default effect still exists in the reverted style.');
$this->assertFalse(array_key_exists(1, $effects), 'The added effect has been removed in the reverted style.');
}
/**
@@ -721,7 +729,8 @@ class ImageAdminStylesUnitTest extends ImageFieldTestCase {
function testStyleReplacement() {
// Create a new style.
$style_name = strtolower($this->randomName(10));
image_style_save(array('name' => $style_name));
$style_label = $this->randomString();
image_style_save(array('name' => $style_name, 'label' => $style_label));
$style_path = 'admin/config/media/image-styles/edit/' . $style_name;
// Create an image field that uses the new style.
@@ -739,28 +748,30 @@ class ImageAdminStylesUnitTest extends ImageFieldTestCase {
// Test that image is displayed using newly created style.
$this->drupalGet('node/' . $nid);
$this->assertRaw(check_plain(image_style_url($style_name, $node->{$field_name}[LANGUAGE_NONE][0]['uri'])), t('Image displayed using style @style.', array('@style' => $style_name)));
$this->assertRaw(check_plain(image_style_url($style_name, $node->{$field_name}[LANGUAGE_NONE][0]['uri'])), format_string('Image displayed using style @style.', array('@style' => $style_name)));
// Rename the style and make sure the image field is updated.
$new_style_name = strtolower($this->randomName(10));
$new_style_label = $this->randomString();
$edit = array(
'name' => $new_style_name,
'label' => $new_style_label,
);
$this->drupalPost('admin/config/media/image-styles/edit/' . $style_name, $edit, t('Update style'));
$this->assertText(t('Changes to the style have been saved.'), t('Style %name was renamed to %new_name.', array('%name' => $style_name, '%new_name' => $new_style_name)));
$this->assertText(t('Changes to the style have been saved.'), format_string('Style %name was renamed to %new_name.', array('%name' => $style_name, '%new_name' => $new_style_name)));
$this->drupalGet('node/' . $nid);
$this->assertRaw(check_plain(image_style_url($new_style_name, $node->{$field_name}[LANGUAGE_NONE][0]['uri'])), t('Image displayed using style replacement style.'));
$this->assertRaw(check_plain(image_style_url($new_style_name, $node->{$field_name}[LANGUAGE_NONE][0]['uri'])), format_string('Image displayed using style replacement style.'));
// Delete the style and choose a replacement style.
$edit = array(
'replacement' => 'thumbnail',
);
$this->drupalPost('admin/config/media/image-styles/delete/' . $new_style_name, $edit, t('Delete'));
$message = t('Style %name was deleted.', array('%name' => $new_style_name));
$message = t('Style %name was deleted.', array('%name' => $new_style_label));
$this->assertRaw($message, $message);
$this->drupalGet('node/' . $nid);
$this->assertRaw(check_plain(image_style_url('thumbnail', $node->{$field_name}[LANGUAGE_NONE][0]['uri'])), t('Image displayed using style replacement style.'));
$this->assertRaw(check_plain(image_style_url('thumbnail', $node->{$field_name}[LANGUAGE_NONE][0]['uri'])), format_string('Image displayed using style replacement style.'));
}
}
@@ -811,7 +822,7 @@ class ImageFieldDisplayTestCase extends ImageFieldTestCase {
'height' => 20,
);
$default_output = theme('image', $image_info);
$this->assertRaw($default_output, t('Default formatter displaying correctly on full node view.'));
$this->assertRaw($default_output, 'Default formatter displaying correctly on full node view.');
// Test the image linked to file formatter.
$instance = field_info_instance('node', $field_name, 'article');
@@ -820,19 +831,19 @@ class ImageFieldDisplayTestCase extends ImageFieldTestCase {
field_update_instance($instance);
$default_output = l(theme('image', $image_info), file_create_url($image_uri), array('html' => TRUE));
$this->drupalGet('node/' . $nid);
$this->assertRaw($default_output, t('Image linked to file formatter displaying correctly on full node view.'));
$this->assertRaw($default_output, 'Image linked to file formatter displaying correctly on full node view.');
// Verify that the image can be downloaded.
$this->assertEqual(file_get_contents($test_image->uri), $this->drupalGet(file_create_url($image_uri)), t('File was downloaded successfully.'));
$this->assertEqual(file_get_contents($test_image->uri), $this->drupalGet(file_create_url($image_uri)), 'File was downloaded successfully.');
if ($scheme == 'private') {
// Only verify HTTP headers when using private scheme and the headers are
// sent by Drupal.
$this->assertEqual($this->drupalGetHeader('Content-Type'), 'image/png', t('Content-Type header was sent.'));
$this->assertEqual($this->drupalGetHeader('Cache-Control'), 'private', t('Cache-Control header was sent.'));
$this->assertEqual($this->drupalGetHeader('Content-Type'), 'image/png', 'Content-Type header was sent.');
$this->assertEqual($this->drupalGetHeader('Cache-Control'), 'private', 'Cache-Control header was sent.');
// Log out and try to access the file.
$this->drupalLogout();
$this->drupalGet(file_create_url($image_uri));
$this->assertResponse('403', t('Access denied to original image as anonymous user.'));
$this->assertResponse('403', 'Access denied to original image as anonymous user.');
// Log in again.
$this->drupalLogin($this->admin_user);
@@ -843,7 +854,7 @@ class ImageFieldDisplayTestCase extends ImageFieldTestCase {
field_update_instance($instance);
$default_output = l(theme('image', $image_info), 'node/' . $nid, array('html' => TRUE, 'attributes' => array('class' => 'active')));
$this->drupalGet('node/' . $nid);
$this->assertRaw($default_output, t('Image linked to content formatter displaying correctly on full node view.'));
$this->assertRaw($default_output, 'Image linked to content formatter displaying correctly on full node view.');
// Test the image style 'thumbnail' formatter.
$instance['display']['default']['settings']['image_link'] = '';
@@ -859,13 +870,13 @@ class ImageFieldDisplayTestCase extends ImageFieldTestCase {
$image_info['height'] = 50;
$default_output = theme('image', $image_info);
$this->drupalGet('node/' . $nid);
$this->assertRaw($default_output, t('Image style thumbnail formatter displaying correctly on full node view.'));
$this->assertRaw($default_output, 'Image style thumbnail formatter displaying correctly on full node view.');
if ($scheme == 'private') {
// Log out and try to access the file.
$this->drupalLogout();
$this->drupalGet(image_style_url('thumbnail', $image_uri));
$this->assertResponse('403', t('Access denied to image style thumbnail as anonymous user.'));
$this->assertResponse('403', 'Access denied to image style thumbnail as anonymous user.');
}
}
@@ -894,16 +905,16 @@ class ImageFieldDisplayTestCase extends ImageFieldTestCase {
$instance = field_info_instance('node', $field_name, 'article');
$this->drupalGet('node/add/article');
$this->assertText(t('Files must be less than 50 KB.'), t('Image widget max file size is displayed on article form.'));
$this->assertText(t('Allowed file types: ' . $test_image_extension . '.'), t('Image widget allowed file types displayed on article form.'));
$this->assertText(t('Images must be between 10x10 and 100x100 pixels.'), t('Image widget allowed resolution displayed on article form.'));
$this->assertText(t('Files must be less than 50 KB.'), 'Image widget max file size is displayed on article form.');
$this->assertText(t('Allowed file types: ' . $test_image_extension . '.'), 'Image widget allowed file types displayed on article form.');
$this->assertText(t('Images must be between 10x10 and 100x100 pixels.'), 'Image widget allowed resolution displayed on article form.');
// We have to create the article first and then edit it because the alt
// and title fields do not display until the image has been attached.
$nid = $this->uploadNodeImage($test_image, $field_name, 'article');
$this->drupalGet('node/' . $nid . '/edit');
$this->assertFieldByName($field_name . '[' . LANGUAGE_NONE . '][0][alt]', '', t('Alt field displayed on article form.'));
$this->assertFieldByName($field_name . '[' . LANGUAGE_NONE . '][0][title]', '', t('Title field displayed on article form.'));
$this->assertFieldByName($field_name . '[' . LANGUAGE_NONE . '][0][alt]', '', 'Alt field displayed on article form.');
$this->assertFieldByName($field_name . '[' . LANGUAGE_NONE . '][0][title]', '', 'Title field displayed on article form.');
// Verify that the attached image is being previewed using the 'medium'
// style.
$node = node_load($nid, NULL, TRUE);
@@ -913,7 +924,7 @@ class ImageFieldDisplayTestCase extends ImageFieldTestCase {
'height' => 110,
);
$default_output = theme('image', $image_info);
$this->assertRaw($default_output, t("Preview image is displayed using 'medium' style."));
$this->assertRaw($default_output, "Preview image is displayed using 'medium' style.");
// Add alt/title fields to the image and verify that they are displayed.
$image_info = array(
@@ -929,7 +940,7 @@ class ImageFieldDisplayTestCase extends ImageFieldTestCase {
);
$this->drupalPost('node/' . $nid . '/edit', $edit, t('Save'));
$default_output = theme('image', $image_info);
$this->assertRaw($default_output, t('Image displayed using user supplied alt and title attributes.'));
$this->assertRaw($default_output, 'Image displayed using user supplied alt and title attributes.');
// Verify that alt/title longer than allowed results in a validation error.
$test_size = 2000;
@@ -962,7 +973,7 @@ class ImageFieldDisplayTestCase extends ImageFieldTestCase {
'title' => t('Image field formatter'),
),
));
$this->assertTrue(stripos($image, 'testFound') > 0, t('Image field formatters can have attributes.'));
$this->assertTrue(stripos($image, 'testFound') > 0, 'Image field formatters can have attributes.');
}
/**
@@ -979,7 +990,7 @@ class ImageFieldDisplayTestCase extends ImageFieldTestCase {
$this->drupalGet('node/' . $node->nid);
// Verify that no image is displayed on the page by checking for the class
// that would be used on the image field.
$this->assertNoPattern('<div class="(.*?)field-name-' . strtr($field_name, '_', '-') . '(.*?)">', t('No image displayed when no image is attached and no default image specified.'));
$this->assertNoPattern('<div class="(.*?)field-name-' . strtr($field_name, '_', '-') . '(.*?)">', 'No image displayed when no image is attached and no default image specified.');
// Add a default image to the public imagefield instance.
$images = $this->drupalGetTestFiles('image');
@@ -991,10 +1002,10 @@ class ImageFieldDisplayTestCase extends ImageFieldTestCase {
field_info_cache_clear();
$field = field_info_field($field_name);
$image = file_load($field['settings']['default_image']);
$this->assertTrue($image->status == FILE_STATUS_PERMANENT, t('The default image status is permanent.'));
$this->assertTrue($image->status == FILE_STATUS_PERMANENT, 'The default image status is permanent.');
$default_output = theme('image', array('path' => $image->uri));
$this->drupalGet('node/' . $node->nid);
$this->assertRaw($default_output, t('Default image displayed when no user supplied image is present.'));
$this->assertRaw($default_output, 'Default image displayed when no user supplied image is present.');
// Create a node with an image attached and ensure that the default image
// is not displayed.
@@ -1007,8 +1018,8 @@ class ImageFieldDisplayTestCase extends ImageFieldTestCase {
);
$image_output = theme('image', $image_info);
$this->drupalGet('node/' . $nid);
$this->assertNoRaw($default_output, t('Default image is not displayed when user supplied image is present.'));
$this->assertRaw($image_output, t('User supplied image is displayed.'));
$this->assertNoRaw($default_output, 'Default image is not displayed when user supplied image is present.');
$this->assertRaw($image_output, 'User supplied image is displayed.');
// Remove default image from the field and make sure it is no longer used.
$edit = array(
@@ -1018,7 +1029,7 @@ class ImageFieldDisplayTestCase extends ImageFieldTestCase {
// Clear field info cache so the new default image is detected.
field_info_cache_clear();
$field = field_info_field($field_name);
$this->assertFalse($field['settings']['default_image'], t('Default image removed from field.'));
$this->assertFalse($field['settings']['default_image'], 'Default image removed from field.');
// Create an image field that uses the private:// scheme and test that the
// default image works as expected.
$private_field_name = strtolower($this->randomName());
@@ -1030,14 +1041,14 @@ class ImageFieldDisplayTestCase extends ImageFieldTestCase {
$this->drupalPost('admin/structure/types/manage/article/fields/' . $private_field_name, $edit, t('Save settings'));
$private_field = field_info_field($private_field_name);
$image = file_load($private_field['settings']['default_image']);
$this->assertEqual('private', file_uri_scheme($image->uri), t('Default image uses private:// scheme.'));
$this->assertTrue($image->status == FILE_STATUS_PERMANENT, t('The default image status is permanent.'));
$this->assertEqual('private', file_uri_scheme($image->uri), 'Default image uses private:// scheme.');
$this->assertTrue($image->status == FILE_STATUS_PERMANENT, 'The default image status is permanent.');
// Create a new node with no image attached and ensure that default private
// image is displayed.
$node = $this->drupalCreateNode(array('type' => 'article'));
$default_output = theme('image', array('path' => $image->uri));
$this->drupalGet('node/' . $node->nid);
$this->assertRaw($default_output, t('Default private image displayed when no user supplied image is present.'));
$this->assertRaw($default_output, 'Default private image displayed when no user supplied image is present.');
}
}
@@ -1083,9 +1094,9 @@ class ImageFieldValidateTestCase extends ImageFieldTestCase {
}
}
$nid = $this->uploadNodeImage($image_that_is_too_small, $field_name, 'article');
$this->assertText(t('The specified file ' . $image_that_is_too_small->filename . ' could not be uploaded. The image is too small; the minimum dimensions are 50x50 pixels.'), t('Node save failed when minimum image resolution was not met.'));
$this->assertText(t('The specified file ' . $image_that_is_too_small->filename . ' could not be uploaded. The image is too small; the minimum dimensions are 50x50 pixels.'), 'Node save failed when minimum image resolution was not met.');
$nid = $this->uploadNodeImage($image_that_is_too_big, $field_name, 'article');
$this->assertText(t('The image was resized to fit within the maximum allowed dimensions of 100x100 pixels.'), t('Image exceeding max resolution was properly resized.'));
$this->assertText(t('The image was resized to fit within the maximum allowed dimensions of 100x100 pixels.'), 'Image exceeding max resolution was properly resized.');
}
}
@@ -1116,7 +1127,7 @@ class ImageDimensionsTestCase extends DrupalWebTestCase {
$original_uri = file_unmanaged_copy($file->uri, 'public://', FILE_EXISTS_RENAME);
// Create a style.
$style = image_style_save(array('name' => 'test'));
$style = image_style_save(array('name' => 'test', 'label' => 'Test'));
$generated_uri = 'public://styles/test/public/'. drupal_basename($original_uri);
$url = image_style_url('test', $original_uri);
@@ -1140,14 +1151,14 @@ class ImageDimensionsTestCase extends DrupalWebTestCase {
image_effect_save($effect);
$img_tag = theme_image_style($variables);
$this->assertEqual($img_tag, '<img typeof="foaf:Image" src="' . check_plain($url) . '" width="120" height="60" alt="" />', t('Expected img tag was found.'));
$this->assertFalse(file_exists($generated_uri), t('Generated file does not exist.'));
$this->assertEqual($img_tag, '<img typeof="foaf:Image" src="' . check_plain($url) . '" width="120" height="60" alt="" />', 'Expected img tag was found.');
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->drupalGet($url);
$this->assertResponse(200, t('Image was generated at the URL.'));
$this->assertTrue(file_exists($generated_uri), t('Generated file does exist after we accessed it.'));
$this->assertResponse(200, 'Image was generated at the URL.');
$this->assertTrue(file_exists($generated_uri), 'Generated file does exist after we accessed it.');
$image_info = image_get_info($generated_uri);
$this->assertEqual($image_info['width'], 120, t('Expected width was found.'));
$this->assertEqual($image_info['height'], 60, t('Expected height was found.'));
$this->assertEqual($image_info['width'], 120, 'Expected width was found.');
$this->assertEqual($image_info['height'], 60, 'Expected height was found.');
// Rotate 90 degrees anticlockwise.
$effect = array(
@@ -1161,14 +1172,14 @@ class ImageDimensionsTestCase extends DrupalWebTestCase {
image_effect_save($effect);
$img_tag = theme_image_style($variables);
$this->assertEqual($img_tag, '<img typeof="foaf:Image" src="' . check_plain($url) . '" width="60" height="120" alt="" />', t('Expected img tag was found.'));
$this->assertFalse(file_exists($generated_uri), t('Generated file does not exist.'));
$this->assertEqual($img_tag, '<img typeof="foaf:Image" src="' . check_plain($url) . '" width="60" height="120" alt="" />', 'Expected img tag was found.');
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->drupalGet($url);
$this->assertResponse(200, t('Image was generated at the URL.'));
$this->assertTrue(file_exists($generated_uri), t('Generated file does exist after we accessed it.'));
$this->assertResponse(200, 'Image was generated at the URL.');
$this->assertTrue(file_exists($generated_uri), 'Generated file does exist after we accessed it.');
$image_info = image_get_info($generated_uri);
$this->assertEqual($image_info['width'], 60, t('Expected width was found.'));
$this->assertEqual($image_info['height'], 120, t('Expected height was found.'));
$this->assertEqual($image_info['width'], 60, 'Expected width was found.');
$this->assertEqual($image_info['height'], 120, 'Expected height was found.');
// Scale an image that is higher than it is wide (rotated by previous effect).
$effect = array(
@@ -1183,14 +1194,14 @@ class ImageDimensionsTestCase extends DrupalWebTestCase {
image_effect_save($effect);
$img_tag = theme_image_style($variables);
$this->assertEqual($img_tag, '<img typeof="foaf:Image" src="' . check_plain($url) . '" width="45" height="90" alt="" />', t('Expected img tag was found.'));
$this->assertFalse(file_exists($generated_uri), t('Generated file does not exist.'));
$this->assertEqual($img_tag, '<img typeof="foaf:Image" src="' . check_plain($url) . '" width="45" height="90" alt="" />', 'Expected img tag was found.');
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->drupalGet($url);
$this->assertResponse(200, t('Image was generated at the URL.'));
$this->assertTrue(file_exists($generated_uri), t('Generated file does exist after we accessed it.'));
$this->assertResponse(200, 'Image was generated at the URL.');
$this->assertTrue(file_exists($generated_uri), 'Generated file does exist after we accessed it.');
$image_info = image_get_info($generated_uri);
$this->assertEqual($image_info['width'], 45, t('Expected width was found.'));
$this->assertEqual($image_info['height'], 90, t('Expected height was found.'));
$this->assertEqual($image_info['width'], 45, 'Expected width was found.');
$this->assertEqual($image_info['height'], 90, 'Expected height was found.');
// Test upscale disabled.
$effect = array(
@@ -1205,14 +1216,14 @@ class ImageDimensionsTestCase extends DrupalWebTestCase {
image_effect_save($effect);
$img_tag = theme_image_style($variables);
$this->assertEqual($img_tag, '<img typeof="foaf:Image" src="' . check_plain($url) . '" width="45" height="90" alt="" />', t('Expected img tag was found.'));
$this->assertFalse(file_exists($generated_uri), t('Generated file does not exist.'));
$this->assertEqual($img_tag, '<img typeof="foaf:Image" src="' . check_plain($url) . '" width="45" height="90" alt="" />', 'Expected img tag was found.');
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->drupalGet($url);
$this->assertResponse(200, t('Image was generated at the URL.'));
$this->assertTrue(file_exists($generated_uri), t('Generated file does exist after we accessed it.'));
$this->assertResponse(200, 'Image was generated at the URL.');
$this->assertTrue(file_exists($generated_uri), 'Generated file does exist after we accessed it.');
$image_info = image_get_info($generated_uri);
$this->assertEqual($image_info['width'], 45, t('Expected width was found.'));
$this->assertEqual($image_info['height'], 90, t('Expected height was found.'));
$this->assertEqual($image_info['width'], 45, 'Expected width was found.');
$this->assertEqual($image_info['height'], 90, 'Expected height was found.');
// Add a desaturate effect.
$effect = array(
@@ -1223,14 +1234,14 @@ class ImageDimensionsTestCase extends DrupalWebTestCase {
image_effect_save($effect);
$img_tag = theme_image_style($variables);
$this->assertEqual($img_tag, '<img typeof="foaf:Image" src="' . check_plain($url) . '" width="45" height="90" alt="" />', t('Expected img tag was found.'));
$this->assertFalse(file_exists($generated_uri), t('Generated file does not exist.'));
$this->assertEqual($img_tag, '<img typeof="foaf:Image" src="' . check_plain($url) . '" width="45" height="90" alt="" />', 'Expected img tag was found.');
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->drupalGet($url);
$this->assertResponse(200, t('Image was generated at the URL.'));
$this->assertTrue(file_exists($generated_uri), t('Generated file does exist after we accessed it.'));
$this->assertResponse(200, 'Image was generated at the URL.');
$this->assertTrue(file_exists($generated_uri), 'Generated file does exist after we accessed it.');
$image_info = image_get_info($generated_uri);
$this->assertEqual($image_info['width'], 45, t('Expected width was found.'));
$this->assertEqual($image_info['height'], 90, t('Expected height was found.'));
$this->assertEqual($image_info['width'], 45, 'Expected width was found.');
$this->assertEqual($image_info['height'], 90, 'Expected height was found.');
// Add a random rotate effect.
$effect = array(
@@ -1244,11 +1255,11 @@ class ImageDimensionsTestCase extends DrupalWebTestCase {
image_effect_save($effect);
$img_tag = theme_image_style($variables);
$this->assertEqual($img_tag, '<img typeof="foaf:Image" src="' . check_plain($url) . '" alt="" />', t('Expected img tag was found.'));
$this->assertFalse(file_exists($generated_uri), t('Generated file does not exist.'));
$this->assertEqual($img_tag, '<img typeof="foaf:Image" src="' . check_plain($url) . '" alt="" />', 'Expected img tag was found.');
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->drupalGet($url);
$this->assertResponse(200, t('Image was generated at the URL.'));
$this->assertTrue(file_exists($generated_uri), t('Generated file does exist after we accessed it.'));
$this->assertResponse(200, 'Image was generated at the URL.');
$this->assertTrue(file_exists($generated_uri), 'Generated file does exist after we accessed it.');
// Add a crop effect.
@@ -1264,14 +1275,14 @@ class ImageDimensionsTestCase extends DrupalWebTestCase {
image_effect_save($effect);
$img_tag = theme_image_style($variables);
$this->assertEqual($img_tag, '<img typeof="foaf:Image" src="' . check_plain($url) . '" width="30" height="30" alt="" />', t('Expected img tag was found.'));
$this->assertFalse(file_exists($generated_uri), t('Generated file does not exist.'));
$this->assertEqual($img_tag, '<img typeof="foaf:Image" src="' . check_plain($url) . '" width="30" height="30" alt="" />', 'Expected img tag was found.');
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->drupalGet($url);
$this->assertResponse(200, t('Image was generated at the URL.'));
$this->assertTrue(file_exists($generated_uri), t('Generated file does exist after we accessed it.'));
$this->assertResponse(200, 'Image was generated at the URL.');
$this->assertTrue(file_exists($generated_uri), 'Generated file does exist after we accessed it.');
$image_info = image_get_info($generated_uri);
$this->assertEqual($image_info['width'], 30, t('Expected width was found.'));
$this->assertEqual($image_info['height'], 30, t('Expected height was found.'));
$this->assertEqual($image_info['width'], 30, 'Expected width was found.');
$this->assertEqual($image_info['height'], 30, 'Expected height was found.');
// Rotate to a non-multiple of 90 degrees.
$effect = array(
@@ -1285,11 +1296,11 @@ class ImageDimensionsTestCase extends DrupalWebTestCase {
$effect = image_effect_save($effect);
$img_tag = theme_image_style($variables);
$this->assertEqual($img_tag, '<img typeof="foaf:Image" src="' . check_plain($url) . '" alt="" />', t('Expected img tag was found.'));
$this->assertFalse(file_exists($generated_uri), t('Generated file does not exist.'));
$this->assertEqual($img_tag, '<img typeof="foaf:Image" src="' . check_plain($url) . '" alt="" />', 'Expected img tag was found.');
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->drupalGet($url);
$this->assertResponse(200, t('Image was generated at the URL.'));
$this->assertTrue(file_exists($generated_uri), t('Generated file does exist after we accessed it.'));
$this->assertResponse(200, 'Image was generated at the URL.');
$this->assertTrue(file_exists($generated_uri), 'Generated file does exist after we accessed it.');
image_effect_delete($effect);
@@ -1303,7 +1314,7 @@ class ImageDimensionsTestCase extends DrupalWebTestCase {
image_effect_save($effect);
$img_tag = theme_image_style($variables);
$this->assertEqual($img_tag, '<img typeof="foaf:Image" src="' . check_plain($url) . '" alt="" />', t('Expected img tag was found.'));
$this->assertEqual($img_tag, '<img typeof="foaf:Image" src="' . check_plain($url) . '" alt="" />', 'Expected img tag was found.');
}
}
@@ -1437,13 +1448,13 @@ class ImageDimensionsScaleTestCase extends DrupalUnitTestCase {
$return_value = image_dimensions_scale($test['input']['dimensions'], $test['input']['width'], $test['input']['height'], $test['input']['upscale']);
// Check the width.
$this->assertEqual($test['output']['dimensions']['width'], $test['input']['dimensions']['width'], t('Computed width (@computed_width) equals expected width (@expected_width)', array('@computed_width' => $test['output']['dimensions']['width'], '@expected_width' => $test['input']['dimensions']['width'])));
$this->assertEqual($test['output']['dimensions']['width'], $test['input']['dimensions']['width'], format_string('Computed width (@computed_width) equals expected width (@expected_width)', array('@computed_width' => $test['output']['dimensions']['width'], '@expected_width' => $test['input']['dimensions']['width'])));
// Check the height.
$this->assertEqual($test['output']['dimensions']['height'], $test['input']['dimensions']['height'], t('Computed height (@computed_height) equals expected height (@expected_height)', array('@computed_height' => $test['output']['dimensions']['height'], '@expected_height' => $test['input']['dimensions']['height'])));
$this->assertEqual($test['output']['dimensions']['height'], $test['input']['dimensions']['height'], format_string('Computed height (@computed_height) equals expected height (@expected_height)', array('@computed_height' => $test['output']['dimensions']['height'], '@expected_height' => $test['input']['dimensions']['height'])));
// Check the return value.
$this->assertEqual($test['output']['return_value'], $return_value, t('Correct return value.'));
$this->assertEqual($test['output']['return_value'], $return_value, 'Correct return value.');
}
}
}
@@ -1704,7 +1715,7 @@ class ImageThemeFunctionWebTestCase extends DrupalWebTestCase {
$original_uri = file_unmanaged_copy($file->uri, 'public://', FILE_EXISTS_RENAME);
// Create a style.
image_style_save(array('name' => 'test'));
image_style_save(array('name' => 'test', 'label' => 'Test'));
$url = image_style_url('test', $original_uri);
// Test using theme_image_formatter() without an image title, alt text, or
@@ -1737,3 +1748,108 @@ class ImageThemeFunctionWebTestCase extends DrupalWebTestCase {
}
}
/**
* Tests flushing of image styles.
*/
class ImageStyleFlushTest extends ImageFieldTestCase {
public static function getInfo() {
return array(
'name' => 'Image style flushing',
'description' => 'Tests flushing of image styles.',
'group' => 'Image',
);
}
/**
* Given an image style and a wrapper, generate an image.
*/
function createSampleImage($style, $wrapper) {
static $file;
if (!isset($file)) {
$files = $this->drupalGetTestFiles('image');
$file = reset($files);
}
// Make sure we have an image in our wrapper testing file directory.
$source_uri = file_unmanaged_copy($file->uri, $wrapper . '://');
// Build the derivative image.
$derivative_uri = image_style_path($style['name'], $source_uri);
$derivative = image_style_create_derivative($style, $source_uri, $derivative_uri);
return $derivative ? $derivative_uri : FALSE;
}
/**
* Count the number of images currently created for a style in a wrapper.
*/
function getImageCount($style, $wrapper) {
return count(file_scan_directory($wrapper . '://styles/' . $style['name'], '/.*/'));
}
/**
* General test to flush a style.
*/
function testFlush() {
// Setup a style to be created and effects to add to it.
$style_name = strtolower($this->randomName(10));
$style_label = $this->randomString();
$style_path = 'admin/config/media/image-styles/edit/' . $style_name;
$effect_edits = array(
'image_resize' => array(
'data[width]' => 100,
'data[height]' => 101,
),
'image_scale' => array(
'data[width]' => 110,
'data[height]' => 111,
'data[upscale]' => 1,
),
);
// Add style form.
$edit = array(
'name' => $style_name,
'label' => $style_label,
);
$this->drupalPost('admin/config/media/image-styles/add', $edit, t('Create new style'));
// Add each sample effect to the style.
foreach ($effect_edits as $effect => $edit) {
// Add the effect.
$this->drupalPost($style_path, array('new' => $effect), t('Add'));
if (!empty($edit)) {
$this->drupalPost(NULL, $edit, t('Add effect'));
}
}
// Load the saved image style.
$style = image_style_load($style_name);
// Create an image for the 'public' wrapper.
$image_path = $this->createSampleImage($style, 'public');
// Expecting to find 2 images, one is the sample.png image shown in
// image style preview.
$this->assertEqual($this->getImageCount($style, 'public'), 2, format_string('Image style %style image %file successfully generated.', array('%style' => $style['name'], '%file' => $image_path)));
// Create an image for the 'private' wrapper.
$image_path = $this->createSampleImage($style, 'private');
$this->assertEqual($this->getImageCount($style, 'private'), 1, format_string('Image style %style image %file successfully generated.', array('%style' => $style['name'], '%file' => $image_path)));
// Remove the 'image_scale' effect and updates the style, which in turn
// forces an image style flush.
$effect = array_pop($style['effects']);
$this->drupalPost($style_path . '/effects/' . $effect['ieid'] . '/delete', array(), t('Delete'));
$this->assertResponse(200);
$this->drupalPost($style_path, array(), t('Update style'));
$this->assertResponse(200);
// Post flush, expected 1 image in the 'public' wrapper (sample.png).
$this->assertEqual($this->getImageCount($style, 'public'), 1, format_string('Image style %style flushed correctly for %wrapper wrapper.', array('%style' => $style['name'], '%wrapper' => 'public')));
// Post flush, expected no image in the 'private' wrapper.
$this->assertEqual($this->getImageCount($style, 'private'), 0, format_string('Image style %style flushed correctly for %wrapper wrapper.', array('%style' => $style['name'], '%wrapper' => 'private')));
}
}

View File

@@ -6,8 +6,8 @@ core = 7.x
files[] = image_module_test.module
hidden = TRUE
; Information added by drupal.org packaging script on 2013-04-03
version = "7.22"
; Information added by drupal.org packaging script on 2013-08-08
version = "7.23"
project = "drupal"
datestamp = "1365027012"
datestamp = "1375928238"