diff --git a/core/includes/theme.inc b/core/includes/theme.inc
index e49bb76..0042af4 100644
--- a/core/includes/theme.inc
+++ b/core/includes/theme.inc
@@ -1741,10 +1741,12 @@ function theme_links($variables) {
}
/**
- * Returns HTML for an image.
+ * Prepares variables for image templates.
*
- * @param $variables
- * An associative array containing:
+ * Default template: image.html.twig.
+ *
+ * @param array $variables
+ * 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).
@@ -1763,17 +1765,14 @@ function theme_links($variables) {
* popular browsers.
* - attributes: Associative array of attributes to be placed in the img tag.
*/
-function theme_image($variables) {
- $attributes = $variables['attributes'];
- $attributes['src'] = file_create_url($variables['uri']);
+function template_preprocess_image(&$variables) {
+ $variables['attributes']['src'] = file_create_url($variables['uri']);
foreach (array('width', 'height', 'alt', 'title') as $key) {
if (isset($variables[$key])) {
- $attributes[$key] = $variables[$key];
+ $variables['attributes'][$key] = $variables[$key];
}
}
-
- return '';
}
/**
@@ -3043,6 +3042,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 c136fa6..52d2a46 100644
--- a/core/modules/image/lib/Drupal/image/Tests/ImageDimensionsTest.php
+++ b/core/modules/image/lib/Drupal/image/Tests/ImageDimensionsTest.php
@@ -71,7 +71,7 @@ function testImageDimensions() {
$style->saveImageEffect($effect);
$img_tag = theme_image_style($variables);
- $this->assertEqual($img_tag, '');
+ $this->assertEqual($img_tag, ''."\n");
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->drupalGet($url);
$this->assertResponse(200, 'Image was generated at the URL.');
@@ -92,7 +92,7 @@ function testImageDimensions() {
$style->saveImageEffect($effect);
$img_tag = theme_image_style($variables);
- $this->assertEqual($img_tag, '');
+ $this->assertEqual($img_tag, ''."\n");
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->drupalGet($url);
$this->assertResponse(200, 'Image was generated at the URL.');
@@ -114,7 +114,7 @@ function testImageDimensions() {
$style->saveImageEffect($effect);
$img_tag = theme_image_style($variables);
- $this->assertEqual($img_tag, '');
+ $this->assertEqual($img_tag, ''."\n");
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->drupalGet($url);
$this->assertResponse(200, 'Image was generated at the URL.');
@@ -136,7 +136,7 @@ function testImageDimensions() {
$style->saveImageEffect($effect);
$img_tag = theme_image_style($variables);
- $this->assertEqual($img_tag, '');
+ $this->assertEqual($img_tag, ''."\n");
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->drupalGet($url);
$this->assertResponse(200, 'Image was generated at the URL.');
@@ -154,7 +154,7 @@ function testImageDimensions() {
$style->saveImageEffect($effect);
$img_tag = theme_image_style($variables);
- $this->assertEqual($img_tag, '');
+ $this->assertEqual($img_tag, ''."\n");
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->drupalGet($url);
$this->assertResponse(200, 'Image was generated at the URL.');
@@ -175,7 +175,7 @@ function testImageDimensions() {
$style->saveImageEffect($effect);
$img_tag = theme_image_style($variables);
- $this->assertEqual($img_tag, '');
+ $this->assertEqual($img_tag, ''."\n");
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->drupalGet($url);
$this->assertResponse(200, 'Image was generated at the URL.');
@@ -195,7 +195,7 @@ function testImageDimensions() {
$style->saveImageEffect($effect);
$img_tag = theme_image_style($variables);
- $this->assertEqual($img_tag, '');
+ $this->assertEqual($img_tag, ''."\n");
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->drupalGet($url);
$this->assertResponse(200, 'Image was generated at the URL.');
@@ -216,7 +216,7 @@ function testImageDimensions() {
$effect_id = $style->saveImageEffect($effect);
$img_tag = theme_image_style($variables);
- $this->assertEqual($img_tag, '');
+ $this->assertEqual($img_tag, ''."\n");
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->drupalGet($url);
$this->assertResponse(200, 'Image was generated at the URL.');
@@ -235,6 +235,6 @@ function testImageDimensions() {
$style->saveImageEffect($effect);
$img_tag = theme_image_style($variables);
- $this->assertEqual($img_tag, '');
+ $this->assertEqual($img_tag, ''."\n");
}
}
diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageThemeFunctionTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageThemeFunctionTest.php
index 1f00c21..6185f15 100644
--- a/core/modules/image/lib/Drupal/image/Tests/ImageThemeFunctionTest.php
+++ b/core/modules/image/lib/Drupal/image/Tests/ImageThemeFunctionTest.php
@@ -56,16 +56,16 @@ function testImageFormatterTheme() {
'path' => $path,
),
);
- $rendered_element = render($element);
- $expected_result = '';
- $this->assertEqual($expected_result, $rendered_element, 'theme_image_formatter() correctly renders with a NULL value for the alt option.');
+ $this->drupalSetContent(render($element));
+ $elements = $this->xpath('//a[@href=:path]/img[@class="image-style-test" and @src=:url]', array(':path' => base_path() . $path, ':url' => $url));
+ $this->assertEqual(count($elements), 1, 'theme_image_formatter() correctly renders with a NULL value for the alt option.');
// Test using theme_image_formatter() without an image title, alt text, or
// link options.
unset($element['#item']['alt']);
- $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();
@@ -74,9 +74,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.');
}
/**
@@ -99,15 +100,15 @@ 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.');
// Test using theme_image_style() with a NULL value for the alt option.
$element['#alt'] = NULL;
- $rendered_element = render($element);
- $expected_result = '';
- $this->assertEqual($expected_result, $rendered_element, 'theme_image_style() renders an image correctly with a NULL value for the alt option.');
+ $this->drupalSetContent(render($element));
+ $elements = $this->xpath('//img[@class="image-style-image-test" and @src=:url]', array(':url' => $url));
+ $this->assertEqual(count($elements), 1, 'theme_image_style() renders an image correctly with a NULL value for the alt option.');
}
}
diff --git a/core/modules/system/templates/image.html.twig b/core/modules/system/templates/image.html.twig
new file mode 100644
index 0000000..b6b238a
--- /dev/null
+++ b/core/modules/system/templates/image.html.twig
@@ -0,0 +1,14 @@
+{#
+/**
+ * @file
+ * Default theme implementation of an image.
+ *
+ * Available variables:
+ * - attributes: HTML attributes for the img tag.
+ *
+ * @see template_preprocess_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 fcae023..8c24b08 100644
--- a/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php
+++ b/core/modules/tour/lib/Drupal/tour/Tests/TourTest.php
@@ -88,8 +88,9 @@ 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.');
+ // Ensure that plugins work.
+ $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');