summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwebchick2012-09-13 09:27:57 (GMT)
committerwebchick2012-09-13 09:27:57 (GMT)
commite75f8906af4415c66509241e56c2cf0ea8567ecb (patch)
tree60f2227ab71f937afa5ca2fd17c0fa622457e059
parent2952d3e232601c9a34b09457ed6e62d97121045f (diff)
Issue #1175764 by tim.plunkett, Rob Loach, eojthebrave: Added Have theme('image_style()') inject the style name as a class.
-rw-r--r--core/modules/image/image.module3
-rw-r--r--core/modules/image/lib/Drupal/image/Tests/ImageDimensionsTest.php18
-rw-r--r--core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php10
-rw-r--r--core/modules/image/lib/Drupal/image/Tests/ImageThemeFunctionTest.php12
4 files changed, 24 insertions, 19 deletions
diff --git a/core/modules/image/image.module b/core/modules/image/image.module
index ccdc879..775de2d 100644
--- a/core/modules/image/image.module
+++ b/core/modules/image/image.module
@@ -1205,6 +1205,9 @@ function theme_image_style($variables) {
$variables['width'] = $dimensions['width'];
$variables['height'] = $dimensions['height'];
+ // Add in the image style name as an HTML class.
+ $variables['attributes']['class'][] = 'image-style-' . drupal_html_class($variables['style_name']);
+
// Determine the URL for the styled image.
$variables['uri'] = image_style_url($variables['style_name'], $variables['uri']);
return theme('image', $variables);
diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageDimensionsTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageDimensionsTest.php
index d2554cf..76110cf 100644
--- a/core/modules/image/lib/Drupal/image/Tests/ImageDimensionsTest.php
+++ b/core/modules/image/lib/Drupal/image/Tests/ImageDimensionsTest.php
@@ -69,7 +69,7 @@ class ImageDimensionsTest extends WebTestBase {
image_effect_save('test', $effect);
$img_tag = theme_image_style($variables);
- $this->assertEqual($img_tag, '<img src="' . $url . '" width="120" height="60" alt="" />');
+ $this->assertEqual($img_tag, '<img class="image-style-test" src="' . $url . '" width="120" height="60" alt="" />');
$this->assertFalse(file_exists($generated_uri), t('Generated file does not exist.'));
$this->drupalGet($url);
$this->assertResponse(200, t('Image was generated at the URL.'));
@@ -90,7 +90,7 @@ class ImageDimensionsTest extends WebTestBase {
image_effect_save('test', $effect);
$img_tag = theme_image_style($variables);
- $this->assertEqual($img_tag, '<img src="' . $url . '" width="60" height="120" alt="" />');
+ $this->assertEqual($img_tag, '<img class="image-style-test" src="' . $url . '" width="60" height="120" alt="" />');
$this->assertFalse(file_exists($generated_uri), t('Generated file does not exist.'));
$this->drupalGet($url);
$this->assertResponse(200, t('Image was generated at the URL.'));
@@ -112,7 +112,7 @@ class ImageDimensionsTest extends WebTestBase {
image_effect_save('test', $effect);
$img_tag = theme_image_style($variables);
- $this->assertEqual($img_tag, '<img src="' . $url . '" width="45" height="90" alt="" />');
+ $this->assertEqual($img_tag, '<img class="image-style-test" src="' . $url . '" width="45" height="90" alt="" />');
$this->assertFalse(file_exists($generated_uri), t('Generated file does not exist.'));
$this->drupalGet($url);
$this->assertResponse(200, t('Image was generated at the URL.'));
@@ -134,7 +134,7 @@ class ImageDimensionsTest extends WebTestBase {
image_effect_save('test', $effect);
$img_tag = theme_image_style($variables);
- $this->assertEqual($img_tag, '<img src="' . $url . '" width="45" height="90" alt="" />');
+ $this->assertEqual($img_tag, '<img class="image-style-test" src="' . $url . '" width="45" height="90" alt="" />');
$this->assertFalse(file_exists($generated_uri), t('Generated file does not exist.'));
$this->drupalGet($url);
$this->assertResponse(200, t('Image was generated at the URL.'));
@@ -152,7 +152,7 @@ class ImageDimensionsTest extends WebTestBase {
image_effect_save('test', $effect);
$img_tag = theme_image_style($variables);
- $this->assertEqual($img_tag, '<img src="' . $url . '" width="45" height="90" alt="" />');
+ $this->assertEqual($img_tag, '<img class="image-style-test" src="' . $url . '" width="45" height="90" alt="" />');
$this->assertFalse(file_exists($generated_uri), t('Generated file does not exist.'));
$this->drupalGet($url);
$this->assertResponse(200, t('Image was generated at the URL.'));
@@ -173,7 +173,7 @@ class ImageDimensionsTest extends WebTestBase {
image_effect_save('test', $effect);
$img_tag = theme_image_style($variables);
- $this->assertEqual($img_tag, '<img src="' . $url . '" alt="" />');
+ $this->assertEqual($img_tag, '<img class="image-style-test" src="' . $url . '" alt="" />');
$this->assertFalse(file_exists($generated_uri), t('Generated file does not exist.'));
$this->drupalGet($url);
$this->assertResponse(200, t('Image was generated at the URL.'));
@@ -193,7 +193,7 @@ class ImageDimensionsTest extends WebTestBase {
image_effect_save('test', $effect);
$img_tag = theme_image_style($variables);
- $this->assertEqual($img_tag, '<img src="' . $url . '" width="30" height="30" alt="" />');
+ $this->assertEqual($img_tag, '<img class="image-style-test" src="' . $url . '" width="30" height="30" alt="" />');
$this->assertFalse(file_exists($generated_uri), t('Generated file does not exist.'));
$this->drupalGet($url);
$this->assertResponse(200, t('Image was generated at the URL.'));
@@ -214,7 +214,7 @@ class ImageDimensionsTest extends WebTestBase {
$effect = image_effect_save('test', $effect);
$img_tag = theme_image_style($variables);
- $this->assertEqual($img_tag, '<img src="' . $url . '" alt="" />');
+ $this->assertEqual($img_tag, '<img class="image-style-test" src="' . $url . '" alt="" />');
$this->assertFalse(file_exists($generated_uri), t('Generated file does not exist.'));
$this->drupalGet($url);
$this->assertResponse(200, t('Image was generated at the URL.'));
@@ -232,6 +232,6 @@ class ImageDimensionsTest extends WebTestBase {
image_effect_save('test', $effect);
$img_tag = theme_image_style($variables);
- $this->assertEqual($img_tag, '<img src="' . $url . '" alt="" />');
+ $this->assertEqual($img_tag, '<img class="image-style-test" src="' . $url . '" alt="" />');
}
}
diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php
index 601c3c2..9e00434 100644
--- a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php
+++ b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php
@@ -104,10 +104,11 @@ class ImageFieldDisplayTest extends ImageFieldTestBase {
// Ensure the derivative image is generated so we do not have to deal with
// image style callback paths.
$this->drupalGet(image_style_url('thumbnail', $image_uri));
- $image_info['uri'] = image_style_path('thumbnail', $image_uri);
+ $image_info['uri'] = $image_uri;
$image_info['width'] = 100;
$image_info['height'] = 50;
- $default_output = theme('image', $image_info);
+ $image_info['style_name'] = 'thumbnail';
+ $default_output = theme('image_style', $image_info);
$this->drupalGet('node/' . $nid);
$this->assertRaw($default_output, t('Image style thumbnail formatter displaying correctly on full node view.'));
@@ -158,11 +159,12 @@ class ImageFieldDisplayTest extends ImageFieldTestBase {
// style.
$node = node_load($nid, TRUE);
$image_info = array(
- 'uri' => image_style_url('medium', file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri),
+ 'uri' => file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri,
'width' => 220,
'height' => 110,
+ 'style_name' => 'medium',
);
- $default_output = theme('image', $image_info);
+ $default_output = theme('image_style', $image_info);
$this->assertRaw($default_output, t("Preview image is displayed using 'medium' style."));
// Add alt/title fields to the image and verify that they are displayed.
diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageThemeFunctionTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageThemeFunctionTest.php
index 0e026f2..45de98e 100644
--- a/core/modules/image/lib/Drupal/image/Tests/ImageThemeFunctionTest.php
+++ b/core/modules/image/lib/Drupal/image/Tests/ImageThemeFunctionTest.php
@@ -56,7 +56,7 @@ class ImageThemeFunctionTest extends WebTestBase {
),
);
$rendered_element = render($element);
- $expected_result = '<a href="' . base_path() . $path . '"><img src="' . $url . '" alt="" /></a>';
+ $expected_result = '<a href="' . base_path() . $path . '"><img class="image-style-test" src="' . $url . '" alt="" /></a>';
$this->assertEqual($expected_result, $rendered_element, 'theme_image_formatter() correctly renders without title, alt, or path options.');
// Link the image to a fragment on the page, and not a full URL.
@@ -67,7 +67,7 @@ class ImageThemeFunctionTest extends WebTestBase {
'fragment' => $fragment,
);
$rendered_element = render($element);
- $expected_result = '<a href="#' . $fragment . '"><img src="' . $url . '" alt="" /></a>';
+ $expected_result = '<a href="#' . $fragment . '"><img class="image-style-test" src="' . $url . '" alt="" /></a>';
$this->assertEqual($expected_result, $rendered_element, 'theme_image_formatter() correctly renders a link fragment.');
}
@@ -81,17 +81,17 @@ class ImageThemeFunctionTest extends WebTestBase {
$original_uri = file_unmanaged_copy($file->uri, 'public://', FILE_EXISTS_RENAME);
// Create a style.
- image_style_save(array('name' => 'test'));
- $url = image_style_url('test', $original_uri);
+ image_style_save(array('name' => 'image_test'));
+ $url = image_style_url('image_test', $original_uri);
$path = $this->randomName();
$element = array(
'#theme' => 'image_style',
- '#style_name' => 'test',
+ '#style_name' => 'image_test',
'#uri' => $original_uri,
);
$rendered_element = render($element);
- $expected_result = '<img src="' . $url . '" alt="" />';
+ $expected_result = '<img class="image-style-image-test" src="' . $url . '" alt="" />';
$this->assertEqual($expected_result, $rendered_element, 'theme_image_style() renders an image correctly.');
}