Commit 91479f42 authored by webchick's avatar webchick

Issue #1885644 by andypost, tim.plunkett: Fixed ImageStyle::uri() is broken and has no coverage.

parent 34453e5e
......@@ -87,12 +87,12 @@ function image_style_form($form, &$form_state, $style) {
if (isset($effect['form callback'])) {
$links['edit'] = array(
'title' => t('edit'),
'href' => 'admin/config/media/image-styles/edit/' . $style->id() . '/effects/' . $key,
'href' => 'admin/config/media/image-styles/manage/' . $style->id() . '/effects/' . $key,
);
}
$links['delete'] = array(
'title' => t('delete'),
'href' => 'admin/config/media/image-styles/edit/' . $style->id() . '/effects/' . $key . '/delete',
'href' => 'admin/config/media/image-styles/manage/' . $style->id() . '/effects/' . $key . '/delete',
);
$form['effects'][$key]['operations'] = array(
'#type' => 'operations',
......@@ -101,13 +101,13 @@ function image_style_form($form, &$form_state, $style) {
$form['effects'][$key]['configure'] = array(
'#type' => 'link',
'#title' => t('edit'),
'#href' => 'admin/config/media/image-styles/edit/' . $style->id() . '/effects/' . $key,
'#href' => 'admin/config/media/image-styles/manage/' . $style->id() . '/effects/' . $key,
'#access' => isset($effect['form callback']),
);
$form['effects'][$key]['remove'] = array(
'#type' => 'link',
'#title' => t('delete'),
'#href' => 'admin/config/media/image-styles/edit/' . $style->id() . '/effects/' . $key . '/delete',
'#href' => 'admin/config/media/image-styles/manage/' . $style->id() . '/effects/' . $key . '/delete',
);
}
}
......@@ -170,7 +170,7 @@ function image_style_form_add_submit($form, &$form_state) {
// Load the configuration form for this option.
if (isset($effect['form callback'])) {
$path = 'admin/config/media/image-styles/edit/' . $style->id() . '/add/' . $form_state['values']['new'];
$path = 'admin/config/media/image-styles/manage/' . $style->id() . '/add/' . $form_state['values']['new'];
$form_state['redirect'] = array($path, array('query' => array('weight' => $form_state['values']['weight'])));
}
// If there's no form, immediately add the image effect.
......@@ -213,7 +213,7 @@ function image_style_form_submit($form, &$form_state) {
if ($status == SAVED_UPDATED) {
drupal_set_message(t('Changes to the style have been saved.'));
}
$form_state['redirect'] = 'admin/config/media/image-styles/edit/' . $style->id();
$form_state['redirect'] = 'admin/config/media/image-styles/manage/' . $style->id();
}
/**
......@@ -256,7 +256,7 @@ function image_style_add_form_submit($form, &$form_state) {
));
$style->save();
drupal_set_message(t('Style %name was created.', array('%name' => $style->label())));
$form_state['redirect'] = 'admin/config/media/image-styles/edit/' . $style->id();
$form_state['redirect'] = 'admin/config/media/image-styles/manage/' . $style->id();
}
/**
......@@ -324,7 +324,7 @@ function image_effect_form($form, &$form_state, $style, $effect) {
// If there's no configuration for this image effect, return to
// the image style page.
if (!isset($effect['form callback'])) {
drupal_goto('admin/config/media/image-styles/edit/' . $style->id());
drupal_goto('admin/config/media/image-styles/manage/' . $style->id());
}
$form_state['image_style'] = $style;
$form_state['image_effect'] = $effect;
......@@ -365,7 +365,7 @@ function image_effect_form($form, &$form_state, $style, $effect) {
$form['actions']['cancel'] = array(
'#type' => 'link',
'#title' => t('Cancel'),
'#href' => 'admin/config/media/image-styles/edit/' . $style->id(),
'#href' => 'admin/config/media/image-styles/manage/' . $style->id(),
);
return $form;
......@@ -382,7 +382,7 @@ function image_effect_form_submit($form, &$form_state) {
image_effect_save($style, $effect);
drupal_set_message(t('The image effect was successfully applied.'));
$form_state['redirect'] = 'admin/config/media/image-styles/edit/' . $style->id();
$form_state['redirect'] = 'admin/config/media/image-styles/manage/' . $style->id();
}
/**
......@@ -400,7 +400,7 @@ function image_effect_delete_form($form, &$form_state, $style, $effect) {
$form_state['image_effect'] = $effect;
$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->id(), '', t('Delete'));
return confirm_form($form, $question, 'admin/config/media/image-styles/manage/' . $style->id(), '', t('Delete'));
}
/**
......@@ -412,7 +412,7 @@ function image_effect_delete_form_submit($form, &$form_state) {
image_effect_delete($style, $effect);
drupal_set_message(t('The image effect %name has been deleted.', array('%name' => $effect['label'])));
$form_state['redirect'] = 'admin/config/media/image-styles/edit/' . $style->id();
$form_state['redirect'] = 'admin/config/media/image-styles/manage/' . $style->id();
}
/**
......@@ -586,16 +586,16 @@ function theme_image_style_list($variables) {
foreach ($styles as $style) {
$row = array();
$row[] = l($style->label(), 'admin/config/media/image-styles/edit/' . $style->id());
$row[] = l($style->label(), 'admin/config/media/image-styles/manage/' . $style->id());
$links = array();
$links['edit'] = array(
'title' => t('edit'),
'href' => 'admin/config/media/image-styles/edit/' . $style->id(),
'href' => 'admin/config/media/image-styles/manage/' . $style->id(),
'class' => array('image-style-link'),
);
$links['delete'] = array(
'title' => t('delete'),
'href' => 'admin/config/media/image-styles/delete/' . $style->id(),
'href' => 'admin/config/media/image-styles/manage/' . $style->id() . '/delete',
'class' => array('image-style-link'),
);
$row[] = array(
......
......@@ -62,10 +62,10 @@ function image_help($path, $arg) {
return $output;
case 'admin/config/media/image-styles':
return '<p>' . t('Image styles commonly provide thumbnail sizes by scaling and cropping images, but can also add various effects before an image is displayed. When an image is displayed with a style, a new file is created and the original image is left unchanged.') . '</p>';
case 'admin/config/media/image-styles/edit/%/add/%':
case 'admin/config/media/image-styles/manage/%/add/%':
$effect = image_effect_definition_load($arg[7]);
return isset($effect['help']) ? ('<p>' . $effect['help'] . '</p>') : NULL;
case 'admin/config/media/image-styles/edit/%/effects/%':
case 'admin/config/media/image-styles/manage/%/effects/%':
$effect = ($arg[5] == 'add') ? image_effect_definition_load($arg[6]) : image_effect_load($arg[6], $arg[4]);
return isset($effect['help']) ? ('<p>' . $effect['help'] . '</p>') : NULL;
}
......@@ -134,24 +134,33 @@ function image_menu() {
'weight' => 2,
'file' => 'image.admin.inc',
);
$items['admin/config/media/image-styles/edit/%image_style'] = array(
$items['admin/config/media/image-styles/manage/%image_style'] = array(
'title' => 'Edit style',
'title callback' => 'entity_page_label',
'title arguments' => array(5),
'description' => 'Configure an image style.',
'page callback' => 'drupal_get_form',
'page arguments' => array('image_style_form', 5),
'access arguments' => array('administer image styles'),
'file' => 'image.admin.inc',
);
$items['admin/config/media/image-styles/delete/%image_style'] = array(
'title' => 'Delete style',
$items['admin/config/media/image-styles/manage/%image_style/edit'] = array(
'title' => 'Edit',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items['admin/config/media/image-styles/manage/%image_style/delete'] = array(
'title' => 'Delete',
'description' => 'Delete an image style.',
'load arguments' => array(NULL, (string) IMAGE_STORAGE_NORMAL),
'page callback' => 'drupal_get_form',
'page arguments' => array('image_style_delete_form', 5),
'access arguments' => array('administer image styles'),
'type' => MENU_LOCAL_TASK,
'weight' => 10,
'file' => 'image.admin.inc',
);
$items['admin/config/media/image-styles/edit/%image_style/effects/%image_effect'] = array(
$items['admin/config/media/image-styles/manage/%image_style/effects/%image_effect'] = array(
'title' => 'Edit image effect',
'description' => 'Edit an existing effect within a style.',
'load arguments' => array(5, (string) IMAGE_STORAGE_EDITABLE),
......@@ -160,7 +169,7 @@ function image_menu() {
'access arguments' => array('administer image styles'),
'file' => 'image.admin.inc',
);
$items['admin/config/media/image-styles/edit/%image_style/effects/%image_effect/delete'] = array(
$items['admin/config/media/image-styles/manage/%image_style/effects/%image_effect/delete'] = array(
'title' => 'Delete image effect',
'description' => 'Delete an existing effect from a style.',
'load arguments' => array(5, (string) IMAGE_STORAGE_EDITABLE),
......@@ -169,7 +178,7 @@ function image_menu() {
'access arguments' => array('administer image styles'),
'file' => 'image.admin.inc',
);
$items['admin/config/media/image-styles/edit/%image_style/add/%image_effect_definition'] = array(
$items['admin/config/media/image-styles/manage/%image_style/add/%image_effect_definition'] = array(
'title' => 'Add image effect',
'description' => 'Add a new effect to a style.',
'load arguments' => array(5),
......
......@@ -2,7 +2,7 @@
/**
* @file
* Definition of Drupal\image\Plugin\Core\Entity\ImageStyle.
* Contains \Drupal\image\Plugin\Core\Entity\ImageStyle.
*/
namespace Drupal\image\Plugin\Core\Entity;
......
......@@ -68,7 +68,7 @@ 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;
$style_path = 'admin/config/media/image-styles/manage/' . $style_name;
$effect_edits = array(
'image_resize' => array(
'data[width]' => 100,
......@@ -120,6 +120,10 @@ function testStyle() {
// Load the saved image style.
$style = entity_load('image_style', $style_name);
// Ensure that the image style URI matches our expected path.
$style_uri = $style->uri();
$style_uri_path = url($style_uri['path'], $style_uri['options']);
$this->assertTrue(strpos($style_uri_path, $style_path) !== FALSE, 'The image style URI is correct.');
// Confirm that all effects on the image style have settings on the effect
// edit form that match what was saved.
......@@ -178,7 +182,7 @@ function testStyle() {
$this->drupalPost($style_path, $edit, t('Update style'));
// Note that after changing the style name, the style path is changed.
$style_path = 'admin/config/media/image-styles/edit/' . $style_name;
$style_path = 'admin/config/media/image-styles/manage/' . $style_name;
// Check that the URL was updated.
$this->drupalGet($style_path);
......@@ -229,7 +233,7 @@ function testStyle() {
// Style deletion form.
// Delete the style.
$this->drupalPost('admin/config/media/image-styles/delete/' . $style_name, array(), t('Delete'));
$this->drupalPost($style_path . '/delete', array(), t('Delete'));
// Confirm the style directory has been removed.
$directory = file_default_scheme() . '://styles/' . $style_name;
......@@ -248,7 +252,7 @@ function testStyleReplacement() {
$style_label = $this->randomString();
$style = entity_create('image_style', array('name' => $style_name, 'label' => $style_label));
$style->save();
$style_path = 'admin/config/media/image-styles/edit/' . $style_name;
$style_path = 'admin/config/media/image-styles/manage/';
// Create an image field that uses the new style.
$field_name = strtolower($this->randomName(10));
......@@ -276,7 +280,7 @@ function testStyleReplacement() {
'name' => $new_style_name,
'label' => $new_style_label,
);
$this->drupalPost('admin/config/media/image-styles/edit/' . $style_name, $edit, t('Update style'));
$this->drupalPost($style_path . $style_name, $edit, t('Update style'));
$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(image_style_url($new_style_name, file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri), 'Image displayed using style replacement style.');
......@@ -285,7 +289,7 @@ function testStyleReplacement() {
$edit = array(
'replacement' => 'thumbnail',
);
$this->drupalPost('admin/config/media/image-styles/delete/' . $new_style_name, $edit, t('Delete'));
$this->drupalPost($style_path . $new_style_name . '/delete', $edit, t('Delete'));
$message = t('Style %name was deleted.', array('%name' => $new_style_label));
$this->assertRaw($message);
......
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