Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
project
drupal
Merge requests
!12377
#3530149
: Add tests from private issue for SA-
CORE-2025
-004.
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
#3530149
: Add tests from private issue for SA-
CORE-2025
-004.
issue/drupal-3530149:3530149-anemone
into
11.x
Overview
5
Commits
5
Pipelines
5
Changes
3
All threads resolved!
Show all comments
Open
Jess
requested to merge
issue/drupal-3530149:3530149-anemone
into
11.x
6 days ago
Overview
5
Commits
5
Pipelines
5
Changes
3
All threads resolved!
Show all comments
Expand
Closes
#3530149
0
0
Merge request reports
Compare
11.x
version 4
48f32f72
6 days ago
version 3
6025840e
6 days ago
version 2
46bf9e88
6 days ago
version 1
67c31a7b
6 days ago
11.x (HEAD)
and
latest version
latest version
59f2971d
5 commits,
6 days ago
version 4
48f32f72
4 commits,
6 days ago
version 3
6025840e
3 commits,
6 days ago
version 2
46bf9e88
2 commits,
6 days ago
version 1
67c31a7b
1 commit,
6 days ago
3 files
+
287
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
Search (e.g. *.vue) (Ctrl+P)
core/modules/link/tests/src/Kernel/LinkFormatterTest.php
0 → 100644
+
132
−
0
Options
<?php
declare
(
strict_types
=
1
);
namespace
Drupal\Tests\link\Kernel
;
use
Drupal\field\Entity\FieldConfig
;
use
Drupal\field\Entity\FieldStorageConfig
;
use
Drupal\KernelTests\Core\Entity\EntityKernelTestBase
;
use
Drupal\user\Entity\Role
;
use
Drupal\user\RoleInterface
;
/**
* Tests the Field Formatter for the link field type.
*
* @group link
*/
class
LinkFormatterTest
extends
EntityKernelTestBase
{
/**
* Modules to enable.
*
* @var array
*/
protected
static
$modules
=
[
'link'
];
/**
* The entity type used in this test.
*
* @var string
*/
protected
string
$entityType
=
'entity_test'
;
/**
* The bundle used in this test.
*
* @var string
*/
protected
string
$bundle
=
'entity_test'
;
/**
* The name of the field used in this test.
*
* @var string
*/
protected
string
$fieldName
=
'field_test'
;
/**
* The entity to be tested.
*
* @var \Drupal\Core\Entity\EntityInterface
*/
protected
$entity
;
/**
* {@inheritdoc}
*/
protected
function
setUp
():
void
{
parent
::
setUp
();
// Use Stark theme for testing markup output.
\Drupal
::
service
(
'theme_installer'
)
->
install
([
'stark'
]);
$this
->
config
(
'system.theme'
)
->
set
(
'default'
,
'stark'
)
->
save
();
$this
->
installEntitySchema
(
'entity_test'
);
// Grant the 'view test entity' permission.
$this
->
installConfig
([
'user'
]);
Role
::
load
(
RoleInterface
::
ANONYMOUS_ID
)
->
grantPermission
(
'view test entity'
)
->
save
();
FieldStorageConfig
::
create
([
'field_name'
=>
$this
->
fieldName
,
'type'
=>
'link'
,
'entity_type'
=>
$this
->
entityType
,
'cardinality'
=>
1
,
])
->
save
();
FieldConfig
::
create
([
'field_name'
=>
$this
->
fieldName
,
'entity_type'
=>
$this
->
entityType
,
'bundle'
=>
$this
->
bundle
,
'label'
=>
'Field test'
,
])
->
save
();
}
/**
* Tests the link formatters.
*
* @param string $formatter
* The name of the link formatter to test.
*
* @dataProvider providerLinkFormatter
*/
public
function
testLinkFormatter
(
string
$formatter
):
void
{
$entity
=
$this
->
container
->
get
(
'entity_type.manager'
)
->
getStorage
(
$this
->
entityType
)
->
create
([
'name'
=>
$this
->
randomMachineName
(),
$this
->
fieldName
=>
[
'uri'
=>
'https://www.drupal.org/'
,
'title'
=>
'Hello world'
,
'options'
=>
[
'attributes'
=>
[
'class'
=>
'classy'
,
'onmouseover'
=>
'alert(document.cookie)'
,
],
],
],
]);
$entity
->
save
();
$build
=
$entity
->
get
(
$this
->
fieldName
)
->
view
([
'type'
=>
$formatter
]);
$renderer
=
$this
->
container
->
get
(
'renderer'
);
$renderer
->
renderRoot
(
$build
[
0
]);
$output
=
(
string
)
$build
[
0
][
'#markup'
];
$this
->
assertStringContainsString
(
'<a href="https://www.drupal.org/" class="classy">'
,
$output
);
$this
->
assertStringNotContainsString
(
'onmouseover='
,
$output
);
}
/**
* Data provider for ::testLinkFormatter.
*/
public
static
function
providerLinkFormatter
():
array
{
return
[
'default formatter'
=>
[
'link'
],
'separate link text and URL'
=>
[
'link_separate'
],
];
}
}
Loading