diff --git a/core/includes/theme.inc b/core/includes/theme.inc
index 4c0e580..a005cfe 100644
--- a/core/includes/theme.inc
+++ b/core/includes/theme.inc
@@ -1851,29 +1851,32 @@ function theme_dropbutton_wrapper($variables) {
}
/**
- * Returns HTML for an image.
+ * Prepares variables for image templates.
+ *
+ * Default template: image.html.twig.
*
* @param $variables
- * An associative array containing:
- * - uri: Either the path of the image file (relative to base_path()) or a
- * full URL.
- * - width: The width of the image (if known).
- * - height: The height of the image (if known).
- * - alt: The alternative text for text-based browsers. HTML 4 and XHTML 1.0
- * always require an alt attribute. The HTML 5 draft allows the alt
- * attribute to be omitted in some cases. Therefore, this variable defaults
- * to an empty string, but can be set to NULL for the attribute to be
- * omitted. Usually, neither omission nor an empty string satisfies
- * accessibility requirements, so it is strongly encouraged for code
- * calling theme('image') to pass a meaningful value for this variable.
- * - http://www.w3.org/TR/REC-html40/struct/objects.html#h-13.8
- * - http://www.w3.org/TR/xhtml1/dtds.html
- * - http://dev.w3.org/html5/spec/Overview.html#alt
- * - title: The title text is displayed when the image is hovered in some
- * popular browsers.
- * - attributes: Associative array of attributes to be placed in the img tag.
+ * Available variables:
+ * - uri: Either the path of the image file (relative to base_path()) or a
+ * full URL.
+ * - width: The width of the image (if known).
+ * - height: The height of the image (if known).
+ * - alt: The alternative text for text-based browsers. HTML 4 and XHTML 1.0
+ * always require an alt attribute. The HTML 5 draft allows the alt
+ * attribute to be omitted in some cases. Therefore, this variable defaults
+ * to an empty string, but can be set to NULL for the attribute to be
+ * omitted. Usually, neither omission nor an empty string satisfies
+ * accessibility requirements, so it is strongly encouraged for code
+ * calling theme('image') to pass a meaningful value for this variable.
+ * - http://www.w3.org/TR/REC-html40/struct/objects.html#h-13.8
+ * - http://www.w3.org/TR/xhtml1/dtds.html
+ * - http://dev.w3.org/html5/spec/Overview.html#alt
+ * - title: The title text is displayed when the image is hovered in some
+ * popular browsers.
+ * - attributes: Associative array of attributes to be placed in the img tag.
+ * @param $variables
*/
-function theme_image($variables) {
+function template_preprocess_image(&$variables) {
$attributes = $variables['attributes'];
$attributes['src'] = file_create_url($variables['uri']);
@@ -1882,8 +1885,11 @@ function theme_image($variables) {
$attributes[$key] = $variables[$key];
}
}
+ // Remove 'image' from the class array. This is added through
+ // template_preprocess() but we do not need it.
+ $attributes['class'] = array_diff($attributes['class'], array('image'));
- return '';
+ $variables['attributes'] = new Attribute($attributes);
}
/**
@@ -3173,6 +3179,7 @@ function drupal_common_theme() {
// The title attribute is optional in all cases, so it is omitted by
// default.
'variables' => array('uri' => NULL, 'width' => NULL, 'height' => NULL, 'alt' => '', 'title' => NULL, 'attributes' => array()),
+ 'template' => 'image',
),
'breadcrumb' => array(
'variables' => array('breadcrumb' => NULL),
diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageDimensionsTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageDimensionsTest.php
index e7552d2..b4be34b 100644
--- a/core/modules/image/lib/Drupal/image/Tests/ImageDimensionsTest.php
+++ b/core/modules/image/lib/Drupal/image/Tests/ImageDimensionsTest.php
@@ -70,7 +70,7 @@ function testImageDimensions() {
image_effect_save($style, $effect);
$img_tag = theme_image_style($variables);
- $this->assertEqual($img_tag, '');
+ $this->assertEqual(trim($img_tag), '');
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->drupalGet($url);
$this->assertResponse(200, 'Image was generated at the URL.');
@@ -91,7 +91,7 @@ function testImageDimensions() {
image_effect_save($style, $effect);
$img_tag = theme_image_style($variables);
- $this->assertEqual($img_tag, '');
+ $this->assertEqual(trim($img_tag), '');
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->drupalGet($url);
$this->assertResponse(200, 'Image was generated at the URL.');
@@ -113,7 +113,7 @@ function testImageDimensions() {
image_effect_save($style, $effect);
$img_tag = theme_image_style($variables);
- $this->assertEqual($img_tag, '');
+ $this->assertEqual(trim($img_tag), '');
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->drupalGet($url);
$this->assertResponse(200, 'Image was generated at the URL.');
@@ -135,7 +135,7 @@ function testImageDimensions() {
image_effect_save($style, $effect);
$img_tag = theme_image_style($variables);
- $this->assertEqual($img_tag, '');
+ $this->assertEqual(trim($img_tag), '');
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->drupalGet($url);
$this->assertResponse(200, 'Image was generated at the URL.');
@@ -153,7 +153,7 @@ function testImageDimensions() {
image_effect_save($style, $effect);
$img_tag = theme_image_style($variables);
- $this->assertEqual($img_tag, '');
+ $this->assertEqual(trim($img_tag), '');
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->drupalGet($url);
$this->assertResponse(200, 'Image was generated at the URL.');
@@ -174,7 +174,7 @@ function testImageDimensions() {
image_effect_save($style, $effect);
$img_tag = theme_image_style($variables);
- $this->assertEqual($img_tag, '');
+ $this->assertEqual(trim($img_tag), '');
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->drupalGet($url);
$this->assertResponse(200, 'Image was generated at the URL.');
@@ -194,7 +194,7 @@ function testImageDimensions() {
image_effect_save($style, $effect);
$img_tag = theme_image_style($variables);
- $this->assertEqual($img_tag, '');
+ $this->assertEqual(trim($img_tag), '');
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->drupalGet($url);
$this->assertResponse(200, 'Image was generated at the URL.');
@@ -215,7 +215,7 @@ function testImageDimensions() {
image_effect_save($style, $effect);
$img_tag = theme_image_style($variables);
- $this->assertEqual($img_tag, '');
+ $this->assertEqual(trim($img_tag), '');
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->drupalGet($url);
$this->assertResponse(200, 'Image was generated at the URL.');
@@ -233,6 +233,6 @@ function testImageDimensions() {
image_effect_save($style, $effect);
$img_tag = theme_image_style($variables);
- $this->assertEqual($img_tag, '');
+ $this->assertEqual(trim($img_tag), '');
}
}
diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageThemeFunctionTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageThemeFunctionTest.php
index cd00cb1..80f17c8 100644
--- a/core/modules/image/lib/Drupal/image/Tests/ImageThemeFunctionTest.php
+++ b/core/modules/image/lib/Drupal/image/Tests/ImageThemeFunctionTest.php
@@ -56,9 +56,10 @@ function testImageFormatterTheme() {
'path' => $path,
),
);
- $rendered_element = render($element);
- $expected_result = '';
- $this->assertEqual($expected_result, $rendered_element, 'theme_image_formatter() correctly renders without title, alt, or path options.');
+
+ $this->drupalSetContent(render($element));
+ $elements = $this->xpath('//a[@href=:path]/img[@class="image-style-test" and @src=:url and @alt=""]', array(':path' => base_path() . $path, ':url' => $url));
+ $this->assertEqual(count($elements), 1, '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();
@@ -67,9 +68,10 @@ function testImageFormatterTheme() {
'external' => TRUE,
'fragment' => $fragment,
);
- $rendered_element = render($element);
- $expected_result = '';
- $this->assertEqual($expected_result, $rendered_element, 'theme_image_formatter() correctly renders a link fragment.');
+
+ $this->drupalSetContent(render($element));
+ $elements = $this->xpath('//a[@href=:fragment]/img[@class="image-style-test" and @src=:url and @alt=""]', array(':fragment' => '#' . $fragment, ':url' => $url));
+ $this->assertEqual(count($elements), 1, 'theme_image_formatter() correctly renders a link fragment.');
}
/**
@@ -92,9 +94,10 @@ function testImageStyleTheme() {
'#style_name' => 'image_test',
'#uri' => $original_uri,
);
- $rendered_element = render($element);
- $expected_result = '';
- $this->assertEqual($expected_result, $rendered_element, 'theme_image_style() renders an image correctly.');
+
+ $this->drupalSetContent(render($element));
+ $elements = $this->xpath('//img[@class="image-style-image-test" and @src=:url and @alt=""]', array(':url' => $url));
+ $this->assertEqual(count($elements), 1, 'theme_image_style() renders an image correctly.');
}
}
diff --git a/core/modules/system/templates/image.html.twig b/core/modules/system/templates/image.html.twig
new file mode 100644
index 0000000..8221c99
--- /dev/null
+++ b/core/modules/system/templates/image.html.twig
@@ -0,0 +1,15 @@
+{#
+/**
+ * @file
+ * Default theme implementation of an image.
+ *
+ * Available variables:
+ * - attributes: HTML attributes for the img tag.
+ *
+ * @see template_preprocess()
+ * @see template_preprcoess_image()
+ *
+ * @ingroup themeable
+ */
+#}
+
diff --git a/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php b/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php
index 6e45d3f..dc1248a 100644
--- a/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php
+++ b/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php
@@ -61,7 +61,8 @@ public function testTourFunctionality() {
$this->assertNotEqual(count($elements), 1, 'Did not find Italian variant of tip 1.');
// Ensure that plugin's work.
- $this->assertRaw('img src="http://local/image.png"', 'Image plugin tip found.');
+ $elements = $this->xpath('//img[@src="http://local/image.png"]');
+ $this->assertEqual(count($elements), 1, 'Image plugin tip found.');
// Navigate to tour-test-2/subpath and verify the tour_test_2 tip is found.
$this->drupalGet('tour-test-2/subpath');