Commit d5a218e1 authored by larowlan's avatar larowlan

Issue #3008109 by Lendude, andypost: Convert ResponsiveImageFieldDisplayTest to BrowserTestBase

(cherry picked from commit 3db26fd1)
parent 29aaab08
<?php
namespace Drupal\responsive_image\Tests;
namespace Drupal\Tests\responsive_image\Functional;
use Drupal\image\Tests\ImageFieldTestBase;
use Drupal\image\Entity\ImageStyle;
use Drupal\node\Entity\Node;
use Drupal\file\Entity\File;
use Drupal\responsive_image\Plugin\Field\FieldFormatter\ResponsiveImageFormatter;
use Drupal\responsive_image\Entity\ResponsiveImageStyle;
use Drupal\Tests\image\Functional\ImageFieldTestBase;
use Drupal\Tests\TestFileCreationTrait;
use Drupal\user\RoleInterface;
/**
......@@ -17,6 +18,8 @@
*/
class ResponsiveImageFieldDisplayTest extends ImageFieldTestBase {
use TestFileCreationTrait;
protected $dumpHeaders = TRUE;
/**
......@@ -172,7 +175,7 @@ protected function doTestResponsiveImageFieldFormatters($scheme, $empty_styles =
$this->createImageField($field_name, 'article', ['uri_scheme' => $scheme]);
// Create a new node with an image attached. Make sure we use a large image
// so the scale effects of the image styles always have an effect.
$test_image = current($this->drupalGetTestFiles('image', 39325));
$test_image = current($this->getTestFiles('image', 39325));
// Create alt text for the image.
$alt = $this->randomMachineName();
......@@ -240,13 +243,11 @@ protected function doTestResponsiveImageFieldFormatters($scheme, $empty_styles =
$display->setComponent($field_name, $display_options)
->save();
$default_output = '<a href="' . file_url_transform_relative(file_create_url($image_uri)) . '"><picture';
$this->drupalGet('node/' . $nid);
$cache_tags_header = $this->drupalGetHeader('X-Drupal-Cache-Tags');
$this->assertTrue(!preg_match('/ image_style\:/', $cache_tags_header), 'No image style cache tag found.');
$this->removeWhiteSpace();
$this->assertRaw($default_output, 'Image linked to file formatter displaying correctly on full node view.');
$this->assertPattern('/<a(.*?)href="' . preg_quote(file_url_transform_relative(file_create_url($image_uri)), '/') . '"(.*?)>\s*<picture/');
// Verify that the image can be downloaded.
$this->assertEqual(file_get_contents($test_image->uri), $this->drupalGet(file_create_url($image_uri)), 'File was downloaded successfully.');
if ($scheme == 'private') {
......@@ -369,7 +370,7 @@ public function testResponsiveImageFieldFormattersEmptyMediaQuery() {
$field_name = mb_strtolower($this->randomMachineName());
$this->createImageField($field_name, 'article', ['uri_scheme' => 'public']);
// Create a new node with an image attached.
$test_image = current($this->drupalGetTestFiles('image'));
$test_image = current($this->getTestFiles('image'));
$nid = $this->uploadNodeImage($test_image, $field_name, 'article', $this->randomMachineName());
$node_storage->resetCache([$nid]);
......@@ -389,7 +390,7 @@ public function testResponsiveImageFieldFormattersEmptyMediaQuery() {
$this->drupalGet('node/' . $nid);
// Assert an empty media attribute is not output.
$this->assertNoPattern('@srcset="data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== 1x".+?media=".+?/><source@');
$this->assertSession()->responseNotMatches('@srcset="data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== 1x".+?media=".+?/><source@');
// Assert the media attribute is present if it has a value.
$thumbnail_style = ImageStyle::load('thumbnail');
......@@ -417,7 +418,7 @@ public function testResponsiveImageFieldFormattersOneSource() {
$field_name = mb_strtolower($this->randomMachineName());
$this->createImageField($field_name, 'article', ['uri_scheme' => 'public']);
// Create a new node with an image attached.
$test_image = current($this->drupalGetTestFiles('image'));
$test_image = current($this->getTestFiles('image'));
$nid = $this->uploadNodeImage($test_image, $field_name, 'article', $this->randomMachineName());
$node_storage->resetCache([$nid]);
......@@ -455,7 +456,7 @@ private function assertResponsiveImageFieldFormattersLink($link_type) {
$field_settings = ['alt_field_required' => 0];
$this->createImageField($field_name, 'article', ['uri_scheme' => 'public'], $field_settings);
// Create a new node with an image attached.
$test_image = current($this->drupalGetTestFiles('image'));
$test_image = current($this->getTestFiles('image'));
// Test the image linked to file formatter.
$display_options = [
......@@ -497,16 +498,15 @@ private function assertResponsiveImageFieldFormattersLink($link_type) {
// Output should contain all image styles and all breakpoints.
$this->drupalGet('node/' . $nid);
$this->removeWhiteSpace();
switch ($link_type) {
case 'file':
// Make sure the link to the file is present.
$this->assertPattern('/<a(.*?)href="' . preg_quote(file_url_transform_relative(file_create_url($image_uri)), '/') . '"(.*?)><picture/');
$this->assertPattern('/<a(.*?)href="' . preg_quote(file_url_transform_relative(file_create_url($image_uri)), '/') . '"(.*?)>\s*<picture/');
break;
case 'content':
// Make sure the link to the node is present.
$this->assertPattern('/<a(.*?)href="' . preg_quote($node->url(), '/') . '"(.*?)><picture/');
$this->assertPattern('/<a(.*?)href="' . preg_quote($node->url(), '/') . '"(.*?)>\s*<picture/');
break;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment