diff --git a/core/modules/responsive_image/lib/Drupal/responsive_image/Tests/ResponsiveImageThemeFunctionsTest.php b/core/modules/responsive_image/lib/Drupal/responsive_image/Tests/ResponsiveImageThemeFunctionsTest.php index 494e6f4..7b17827 100644 --- a/core/modules/responsive_image/lib/Drupal/responsive_image/Tests/ResponsiveImageThemeFunctionsTest.php +++ b/core/modules/responsive_image/lib/Drupal/responsive_image/Tests/ResponsiveImageThemeFunctionsTest.php @@ -2,37 +2,37 @@ /** * @file - * Contains \Drupal\picture\Tests\PictureThemeFunctionsTest. + * Contains \Drupal\responsive_image\Tests\ResponsiveImageThemeFunctionsTest. */ -namespace Drupal\picture\Tests; +namespace Drupal\responsive_image\Tests; use Drupal\simpletest\WebTestBase; /** - * Tests picture theme functions. + * Tests responsive image theme functions. */ -class PictureThemeFunctionsTest extends WebTestBase { +class ResponsiveImageThemeFunctionsTest extends WebTestBase { /** * Modules to enable. * * @var array */ - public static $modules = array('picture'); + public static $modules = array('responsive_image'); public static function getInfo() { return array( - 'name' => 'Picture theme functions', - 'description' => 'Tests the picture theme functions.', - 'group' => 'Picture', + 'name' => 'Responsive Image theme functions', + 'description' => 'Tests the responsive_image theme functions.', + 'group' => 'Responsive Image', ); } /** - * Tests usage of the theme_picture() function. + * Tests usage of the template_preprocess_responsive_image() function. */ - function testPictureTheme() { + function testResponsiveImageTheme() { // Create an image. $files = $this->drupalGetTestFiles('image'); $file = reset($files); @@ -43,73 +43,23 @@ function testPictureTheme() { $style->save(); $url = $style->buildUrl($original_uri); - // Test using theme_picture() with a NULL value for the alt option. + // Test using template_preprocess_responsive_image() with a NULL value for the alt option. $path = $this->randomName(); $element = array( - '#theme' => 'picture', + '#theme' => 'responsive_image', '#uri' => $original_uri, '#alt' => NULL, '#style_name' => 'test', + '#breakpoints' => 'test', ); $rendered_element = render($element); - $expected_result = ''; - $this->assertTrue(strpos($rendered_element, '') !== FALSE, 'picture element in theme_picture() correctly renders with a NULL value for the alt option.'); + $this->assertTrue(strpos($rendered_element, '') !== FALSE, 'picture element in template_preprocess_responsive_image() renders correctly.'); - // Test using theme_picture() without passing a value for the alt option. + // Test using template_preprocess_responsive_image() without passing a value for the alt option. unset($element['#alt']); $rendered_element = render($element); $expected_result = ''; - $this->assertTrue(strpos($rendered_element, $expected_result) !== FALSE, 'img element in theme_picture() correctly renders the alt option.'); - $this->assertTrue(strpos($rendered_element, '') !== FALSE, 'picture element in theme_picture() correctly renders the alt option.'); + $this->assertTrue(strpos($rendered_element, $expected_result) !== FALSE, 'img element in template_preprocess_responsive_image() correctly renders the alt option.'); } - /** - * Tests usage of the theme_picture_formatter() function. - */ - function testPictureFormatterTheme() { - // Create an image. - $files = $this->drupalGetTestFiles('image'); - $file = reset($files); - $original_uri = file_unmanaged_copy($file->uri, 'public://', FILE_EXISTS_RENAME); - - // Create a style. - $style = entity_create('image_style', array('name' => 'test', 'label' => 'Test')); - $style->save(); - $url = $style->buildUrl($original_uri); - - // Test using theme_picture_formatter() without breakpoints and with a NULL value for the alt option. - $path = $this->randomName(); - $element = array( - '#theme' => 'picture_formatter', - '#item' => array( - 'uri' => $original_uri, - 'alt' => NULL, - ), - '#image_style' => 'test', - '#path' => array( - 'path' => $path, - ), - ); - $rendered_element = render($element); - $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']); - $rendered_element = render($element); - $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. - $fragment = $this->randomName(); - $element['#path']['path'] = ''; - $element['#path']['options'] = array( - 'external' => TRUE, - 'fragment' => $fragment, - ); - $rendered_element = render($element); - $expected_result = ''; - $this->assertEqual($expected_result, $rendered_element, 'theme_picture_formatter() correctly renders a link fragment.'); - } } diff --git a/core/modules/responsive_image/responsive_image.module b/core/modules/responsive_image/responsive_image.module index d58a580..98c9096 100644 --- a/core/modules/responsive_image/responsive_image.module +++ b/core/modules/responsive_image/responsive_image.module @@ -117,7 +117,7 @@ function responsive_image_theme() { 'attributes' => array(), 'breakpoints' => array(), ), - 'template' => 'picture', + 'template' => 'responsive-image', ), ); } @@ -157,9 +157,6 @@ function template_preprocess_responsive_image(&$variables) { // Prepare picture tag attributes. $attributes = array(); - if (isset($variables['alt']) || array_key_exists('alt', $variables)) { - $attributes['alt'] = $variables['alt']; - } if (isset($variables['title'])) { $attributes['title'] = $variables['title']; } diff --git a/core/modules/responsive_image/templates/picture.html.twig b/core/modules/responsive_image/templates/picture.html.twig deleted file mode 100644 index bbd8ef9..0000000 --- a/core/modules/responsive_image/templates/picture.html.twig +++ /dev/null @@ -1,26 +0,0 @@ -{# -/** - * @file - * Default theme implementation to display a picture tag. - * - * Available variables: - * - attributes: HTML attributes for the picture tag. - * - sources: A set of source data. - * - source.attributes: HTML attributes for each source tag. - * - fallback: Fallback image tag for non-JS browsers. - * - * @see template_preprocess_picture() - * - * @ingroup themeable - */ -#} -{% if sources %} - - {% for source in sources %} - - {% endfor %} - - -{% else %} - {{- fallback -}} -{% endif %} diff --git a/core/modules/responsive_image/templates/responsive-image.html.twig b/core/modules/responsive_image/templates/responsive-image.html.twig new file mode 100644 index 0000000..89b5f24 --- /dev/null +++ b/core/modules/responsive_image/templates/responsive-image.html.twig @@ -0,0 +1,26 @@ +{# +/** + * @file + * Default theme implementation to display a picture tag. + * + * Available variables: + * - attributes: HTML attributes for the picture tag. + * - sources: A set of source data. + * - source.attributes: HTML attributes for each source tag. + * - fallback: Fallback image tag for non-JS browsers. + * + * @see template_preprocess_responsive_image() + * + * @ingroup themeable + */ +#} +{% if sources %} + + {% for source in sources %} + + {% endfor %} + + +{% else %} + {{- fallback -}} +{% endif %}