Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal-3495531
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
drupal-3495531
Commits
3db26fd1
Verified
Commit
3db26fd1
authored
6 years ago
by
Lee Rowlands
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3008109
by Lendude, andypost: Convert ResponsiveImageFieldDisplayTest to BrowserTestBase
parent
550e914c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/modules/responsive_image/tests/src/Functional/ResponsiveImageFieldDisplayTest.php
+13
-13
13 additions, 13 deletions
.../tests/src/Functional/ResponsiveImageFieldDisplayTest.php
with
13 additions
and
13 deletions
core/modules/responsive_image/
src/Tests
/ResponsiveImageFieldDisplayTest.php
→
core/modules/responsive_image/
tests/src/Functional
/ResponsiveImageFieldDisplayTest.php
+
13
−
13
View file @
3db26fd1
<?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
->
drupalG
etTestFiles
(
'image'
,
39325
));
$test_image
=
current
(
$this
->
g
etTestFiles
(
'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
->
drupalG
etTestFiles
(
'image'
));
$test_image
=
current
(
$this
->
g
etTestFiles
(
'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
->
assert
NoPattern
(
'@srcset="data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== 1x".+?media=".+?/><source@'
);
$this
->
assert
Session
()
->
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
->
drupalG
etTestFiles
(
'image'
));
$test_image
=
current
(
$this
->
g
etTestFiles
(
'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
->
drupalG
etTestFiles
(
'image'
));
$test_image
=
current
(
$this
->
g
etTestFiles
(
'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
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment