Commit 6d8e333e authored by alexpott's avatar alexpott

Issue #999338 by lauriii, joelpittet, Sir-Arturio, mgifford, mlncn, alarcombe,...

Issue #999338 by lauriii, joelpittet, Sir-Arturio, mgifford, mlncn, alarcombe, sun | Eric_A: Fixed theme_image() alt attribute cannot be passed in $variables['attributes'] .
parent b29ad669
......@@ -1122,6 +1122,11 @@ function template_preprocess_image(&$variables) {
foreach (array('width', 'height', 'alt', 'title') as $key) {
if (isset($variables[$key])) {
// If the property has already been defined in the attributes,
// do not override, including NULL.
if (array_key_exists($key, $variables['attributes'])) {
continue;
}
$variables['attributes'][$key] = $variables[$key];
}
}
......
......@@ -152,4 +152,60 @@ function testImageStyleTheme() {
$this->assertEqual(count($elements), 1, 'theme_image_style() renders an image correctly with a NULL value for the alt option.');
}
/**
* Tests image alt attribute functionality.
*/
function testImageAltFunctionality() {
// Test using alt directly with alt attribute.
$image_with_alt_property = array(
'#theme' => 'image',
'#uri' => '/core/themes/bartik/logo.png',
'#alt' => 'Regular alt',
'#title' => 'Test title',
'#width' => '50%',
'#height' => '50%',
'#attributes' => array('class' => 'image-with-regular-alt', 'id' => 'my-img'),
);
$this->drupalSetContent(drupal_render($image_with_alt_property));
$elements = $this->xpath('//img[contains(@class, class) and contains(@alt, :alt)]', array(":class" => "image-with-regular-alt", ":alt" => "Regular alt"));
$this->assertEqual(count($elements), 1, 'Regular alt displays correctly');
// Test using alt attribute inside attributes.
$image_with_alt_attribute_alt_attribute = array(
'#theme' => 'image',
'#uri' => '/core/themes/bartik/logo.png',
'#width' => '50%',
'#height' => '50%',
'#attributes' => array(
'class' => 'image-with-attribute-alt',
'id' => 'my-img',
'title' => 'New test title',
'alt' => 'Attribute alt',
),
);
$this->drupalSetContent(drupal_render($image_with_alt_attribute_alt_attribute));
$elements = $this->xpath('//img[contains(@class, class) and contains(@alt, :alt)]', array(":class" => "image-with-attribute-alt", ":alt" => "Attribute alt"));
$this->assertEqual(count($elements), 1, 'Attribute alt displays correctly');
// Test using alt attribute as property and inside attributes.
$image_with_alt_attribute_both = array(
'#theme' => 'image',
'#uri' => '/core/themes/bartik/logo.png',
'#width' => '50%',
'#height' => '50%',
'#alt' => 'Kitten sustainable',
'#attributes' => array(
'class' => 'image-with-attribute-alt',
'id' => 'my-img',
'title' => 'New test title',
'alt' => 'Attribute alt',
),
);
$this->drupalSetContent(drupal_render($image_with_alt_attribute_both));
$elements = $this->xpath('//img[contains(@class, class) and contains(@alt, :alt)]', array(":class" => "image-with-attribute-alt", ":alt" => "Attribute alt"));
$this->assertEqual(count($elements), 1, 'Attribute alt overrides alt property if both set.');
}
}
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