summaryrefslogtreecommitdiff
path: root/modules/image
diff options
context:
space:
mode:
authorwebchick <webchick@24967.no-reply.drupal.org>2012-10-06 10:24:32 -0700
committerwebchick <webchick@24967.no-reply.drupal.org>2012-10-06 10:24:32 -0700
commit762235d18917536aad7e8dc5ddcf23027247a104 (patch)
tree5d49445f837b0be7fbf260f7fff23b5aa8e5c13b /modules/image
parent506d8c47b01e8ac99b1e60706bc09f833c285ec6 (diff)
downloadbrdo-762235d18917536aad7e8dc5ddcf23027247a104.tar.gz
brdo-762235d18917536aad7e8dc5ddcf23027247a104.tar.bz2
Issue #1038932 by tim.plunkett, Chris Gillis: Theme_image_formatter() assumes that title, alt, and options are always set.
Diffstat (limited to 'modules/image')
-rw-r--r--modules/image/image.field.inc13
-rw-r--r--modules/image/image.test61
2 files changed, 70 insertions, 4 deletions
diff --git a/modules/image/image.field.inc b/modules/image/image.field.inc
index 1be15839c..60c0f5ac0 100644
--- a/modules/image/image.field.inc
+++ b/modules/image/image.field.inc
@@ -600,9 +600,12 @@ function theme_image_formatter($variables) {
$item = $variables['item'];
$image = array(
'path' => $item['uri'],
- 'alt' => $item['alt'],
);
+ if (array_key_exists('alt', $item)) {
+ $image['alt'] = $item['alt'];
+ }
+
if (isset($item['attributes'])) {
$image['attributes'] = $item['attributes'];
}
@@ -613,7 +616,7 @@ function theme_image_formatter($variables) {
}
// Do not output an empty 'title' attribute.
- if (drupal_strlen($item['title']) > 0) {
+ if (isset($item['title']) && drupal_strlen($item['title']) > 0) {
$image['title'] = $item['title'];
}
@@ -625,9 +628,11 @@ function theme_image_formatter($variables) {
$output = theme('image', $image);
}
- if (!empty($variables['path']['path'])) {
+ // The link path and link options are both optional, but for the options to be
+ // processed, the link path must at least be an empty string.
+ if (isset($variables['path']['path'])) {
$path = $variables['path']['path'];
- $options = $variables['path']['options'];
+ $options = isset($variables['path']['options']) ? $variables['path']['options'] : array();
// When displaying an image inside a link, the html option must be TRUE.
$options['html'] = TRUE;
$output = l($output, $path, $options);
diff --git a/modules/image/image.test b/modules/image/image.test
index 2a3559981..1ca846506 100644
--- a/modules/image/image.test
+++ b/modules/image/image.test
@@ -1597,3 +1597,64 @@ class ImageFieldDefaultImagesTestCase extends ImageFieldTestCase {
}
}
+
+/**
+ * Tests image theme functions.
+ */
+class ImageThemeFunctionWebTestCase extends DrupalWebTestCase {
+
+ public static function getInfo() {
+ return array(
+ 'name' => 'Image theme functions',
+ 'description' => 'Test that the image theme functions work correctly.',
+ 'group' => 'Image',
+ );
+ }
+
+ function setUp() {
+ parent::setUp(array('image'));
+ }
+
+ /**
+ * Tests usage of the image field formatters.
+ */
+ function testImageFormatterTheme() {
+ // Create an image.
+ $files = $this->drupalGetTestFiles('image');
+ $file = reset($files);
+ $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);
+
+ // Test using theme_image_formatter() without an image title, alt text, or
+ // link options.
+ $path = $this->randomName();
+ $element = array(
+ '#theme' => 'image_formatter',
+ '#image_style' => 'test',
+ '#item' => array(
+ 'uri' => $original_uri,
+ ),
+ '#path' => array(
+ 'path' => $path,
+ ),
+ );
+ $rendered_element = render($element);
+ $expected_result = '<a href="' . url($path) . '"><img typeof="foaf:Image" 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.
+ $fragment = $this->randomName();
+ $element['#path']['path'] = '';
+ $element['#path']['options'] = array(
+ 'external' => TRUE,
+ 'fragment' => $fragment,
+ );
+ $rendered_element = render($element);
+ $expected_result = '<a href="#' . $fragment . '"><img typeof="foaf:Image" src="' . $url . '" alt="" /></a>';
+ $this->assertEqual($expected_result, $rendered_element, 'theme_image_formatter() correctly renders a link fragment.');
+ }
+
+}