Commit e75f8906 authored by webchick's avatar webchick

Issue #1175764 by tim.plunkett, Rob Loach, eojthebrave: Added Have...

Issue #1175764 by tim.plunkett, Rob Loach, eojthebrave: Added Have theme('image_style()') inject the style name as a class.
parent 2952d3e2
......@@ -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);
......
......@@ -69,7 +69,7 @@ function testImageDimensions() {
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 @@ function testImageDimensions() {
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 @@ function testImageDimensions() {
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 @@ function testImageDimensions() {
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 @@ function testImageDimensions() {
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 @@ function testImageDimensions() {
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 @@ function testImageDimensions() {
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 @@ function testImageDimensions() {
$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 @@ function testImageDimensions() {
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="" />');
}
}
......@@ -104,10 +104,11 @@ function _testImageFieldFormatters($scheme) {
// 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 @@ function testImageFieldSettings() {
// 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.
......
......@@ -56,7 +56,7 @@ function testImageFormatterTheme() {
),
);
$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 @@ function testImageFormatterTheme() {
'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 @@ function testImageStyleTheme() {
$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.');
}
......
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