diff --git a/core/modules/picture/lib/Drupal/picture/Tests/PictureThemeFunctionsTest.php b/core/modules/picture/lib/Drupal/picture/Tests/PictureThemeFunctionsTest.php
index f923e6c..1578153 100644
--- a/core/modules/picture/lib/Drupal/picture/Tests/PictureThemeFunctionsTest.php
+++ b/core/modules/picture/lib/Drupal/picture/Tests/PictureThemeFunctionsTest.php
@@ -7,6 +7,7 @@
namespace Drupal\picture\Tests;
+use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\simpletest\WebTestBase;
/**
@@ -19,7 +20,14 @@ class PictureThemeFunctionsTest extends WebTestBase {
*
* @var array
*/
- public static $modules = array('picture');
+ public static $modules = array('picture', 'entity_test');
+
+ /**
+ * Created file entity.
+ *
+ * @var \Drupal\file\Entity\File
+ */
+ protected $image;
public static function getInfo() {
return array(
@@ -29,6 +37,28 @@ public static function getInfo() {
);
}
+ public function setUp() {
+ parent::setUp();
+
+ entity_create('field_entity', array(
+ 'name' => 'image_test',
+ 'entity_type' => 'entity_test',
+ 'type' => 'image',
+ 'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED,
+ ))->save();
+ entity_create('field_instance', array(
+ 'entity_type' => 'entity_test',
+ 'field_name' => 'image_test',
+ 'bundle' => 'entity_test',
+ ))->save();
+ file_unmanaged_copy(DRUPAL_ROOT . '/core/misc/druplicon.png', 'public://example.jpg');
+ $this->image = entity_create('file', array(
+ 'uri' => 'public://example.jpg',
+ ));
+ $this->image->save();
+ $this->imageFactory = $this->container->get('image.factory');
+ }
+
/**
* Tests usage of the theme_picture() function.
*/
@@ -78,28 +108,35 @@ function testPictureFormatterThemeFunction() {
$style->save();
$url = $style->buildUrl($original_uri);
- // Test using theme_picture_formatter() without breakpoints and with a NULL value for the alt option.
+ // Create a test entity with the image field set.
+ $entity = entity_create('entity_test', array());
+ $entity->image_test->target_id = $this->image->id();
+ $entity->image_test->alt = NULL;
+ $entity->image_test->uri = $original_uri;
+ $image = $this->imageFactory->get('public://example.jpg');
+ $entity->save();
+
$path = $this->randomName();
$element = array(
'#theme' => 'picture_formatter',
- '#item' => array(
- 'uri' => $original_uri,
- 'alt' => NULL,
- ),
+ '#item' => $entity->image_test,
'#image_style' => 'test',
'#path' => array(
'path' => $path,
),
);
+
+ // Test using theme_picture_formatter() without breakpoints and with a NULL
+ // value for the alt option.
$rendered_element = render($element);
- $expected_result = '
';
+ $expected_result = '
';
$this->assertEqual($expected_result, $rendered_element, 'theme_picture_formatter() correctly renders without breakpoints and with a NULL value for the alt option.');
// Test using theme_picture_formatter() without an image title, alt text, or
// link options.
- unset($element['#item']['alt']);
+ $element['#item']->alt = '';
$rendered_element = render($element);
- $expected_result = '
';
+ $expected_result = '
';
$this->assertEqual($expected_result, $rendered_element, 'theme_picture_formatter() correctly renders without title, alt, or path options.');
// Link the image to a fragment on the page, and not a full URL.
@@ -110,7 +147,7 @@ function testPictureFormatterThemeFunction() {
'fragment' => $fragment,
);
$rendered_element = render($element);
- $expected_result = '
';
+ $expected_result = '
';
$this->assertEqual($expected_result, $rendered_element, 'theme_picture_formatter() correctly renders a link fragment.');
}
}
diff --git a/core/modules/picture/picture.module b/core/modules/picture/picture.module
index 9232189..73aa053 100644
--- a/core/modules/picture/picture.module
+++ b/core/modules/picture/picture.module
@@ -290,7 +290,7 @@ function theme_picture($variables) {
if (!empty($sources)) {
$attributes = array();
foreach (array('alt', 'title') as $key) {
- if (isset($variables[$key])) {
+ if (isset($variables[$key]) || array_key_exists($key, $variables)) {
$attributes[$key] = $variables[$key];
}
}