diff --git a/core/includes/theme.inc b/core/includes/theme.inc
index 8d527df..dbc2593 100644
--- a/core/includes/theme.inc
+++ b/core/includes/theme.inc
@@ -1851,7 +1851,9 @@ 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:
@@ -1873,7 +1875,7 @@ function theme_dropbutton_wrapper($variables) {
* popular browsers.
* - attributes: Associative array of attributes to be placed in the img tag.
*/
-function theme_image($variables) {
+function template_preprocess_image(&$variables) {
$attributes = $variables['attributes'];
$attributes['src'] = file_create_url($variables['uri']);
@@ -1882,8 +1884,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 +3178,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..0cf7be7
--- /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 themable
+ */
+#}
+
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');