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
Commits
01f76ced
Verified
Commit
01f76ced
authored
5 years ago
by
Lee Rowlands
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3046171
by claudiu.cristea, Lendude: Convert FilterCaptionTwigDebugTest into a Kernel test
parent
45cf0448
No related branches found
No related tags found
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/modules/filter/tests/src/Kernel/FilterCaptionTwigDebugTest.php
+62
-0
62 additions, 0 deletions
...es/filter/tests/src/Kernel/FilterCaptionTwigDebugTest.php
with
62 additions
and
0 deletions
core/modules/filter/tests/src/
Functiona
l/FilterCaptionTwigDebugTest.php
→
core/modules/filter/tests/src/
Kerne
l/FilterCaptionTwigDebugTest.php
+
62
−
0
View file @
01f76ced
<?php
namespace
Drupal\Tests\filter\
Functiona
l
;
namespace
Drupal\Tests\filter\
Kerne
l
;
use
Drupal\Core\DependencyInjection\ContainerBuilder
;
use
Drupal\Core\Render\RenderContext
;
use
Drupal\Tests\BrowserTestBase
;
use
Drupal\filter\FilterPluginCollection
;
use
Drupal\KernelTests\KernelTestBase
;
/**
* Tests the caption filter with Twig debugging on.
*
* @group filter
*/
class
FilterCaptionTwigDebugTest
extends
BrowserTestBase
{
/**
* Modules to enable.
*
* @var array
*/
public
static
$modules
=
[
'system'
,
'filter'
];
/**
* @var \Drupal\filter\Plugin\FilterInterface[]
*/
protected
$filters
;
/**
* Enables Twig debugging.
*/
protected
function
debugOn
()
{
// Enable debug, rebuild the service container, and clear all caches.
$parameters
=
$this
->
container
->
getParameter
(
'twig.config'
);
if
(
!
$parameters
[
'debug'
])
{
$parameters
[
'debug'
]
=
TRUE
;
$this
->
setContainerParameter
(
'twig.config'
,
$parameters
);
$this
->
rebuildContainer
();
$this
->
resetAll
();
}
}
/**
* Disables Twig debugging.
*/
protected
function
debugOff
()
{
// Disable debug, rebuild the service container, and clear all caches.
$parameters
=
$this
->
container
->
getParameter
(
'twig.config'
);
if
(
$parameters
[
'debug'
])
{
$parameters
[
'debug'
]
=
FALSE
;
$this
->
setContainerParameter
(
'twig.config'
,
$parameters
);
$this
->
rebuildContainer
();
$this
->
resetAll
();
}
}
class
FilterCaptionTwigDebugTest
extends
KernelTestBase
{
/**
* {@inheritdoc}
*/
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
debugOn
();
$manager
=
$this
->
container
->
get
(
'plugin.manager.filter'
);
$bag
=
new
FilterPluginCollection
(
$manager
,
[]);
$this
->
filters
=
$bag
->
getAll
();
}
protected
static
$modules
=
[
'filter'
];
/**
* {@inheritdoc}
*/
protected
function
tearDown
()
{
$this
->
debugOff
();
public
function
register
(
ContainerBuilder
$container
)
{
parent
::
register
(
$container
);
// Enable Twig debugging.
$parameters
=
$container
->
getParameter
(
'twig.config'
);
$parameters
[
'debug'
]
=
TRUE
;
$container
->
setParameter
(
'twig.config'
,
$parameters
);
}
/**
* Test the caption filter with Twig debugging on.
*/
public
function
testCaptionFilter
()
{
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer
=
\Drupal
::
service
(
'renderer'
);
$filter
=
$this
->
filters
[
'filter_caption'
];
$manager
=
$this
->
container
->
get
(
'plugin.manager.filter'
);
$bag
=
new
FilterPluginCollection
(
$manager
,
[]);
$filter
=
$bag
->
get
(
'filter_caption'
);
$renderer
=
$this
->
container
->
get
(
'renderer'
);
$test
=
function
(
$input
)
use
(
$filter
,
$renderer
)
{
return
$renderer
->
executeInRenderContext
(
new
RenderContext
(),
function
()
use
(
$input
,
$filter
)
{
...
...
@@ -90,15 +49,14 @@ public function testCaptionFilter() {
// No data-caption attribute.
$input
=
'<img src="llama.jpg" />'
;
$expected
=
$input
;
$this
->
assert
Identic
al
(
$expected
,
$test
(
$input
)
->
getProcessedText
());
$this
->
assert
Equ
al
s
(
$expected
,
$test
(
$input
)
->
getProcessedText
());
// Data-caption attribute.
$input
=
'<img src="llama.jpg" data-caption="Loquacious llama!" />'
;
$expected
=
'<img src="llama.jpg" /><figcaption>Loquacious llama!</figcaption>'
;
$output
=
$test
(
$input
);
$output
=
$output
->
getProcessedText
();
$this
->
assertTrue
(
strpos
(
$output
,
$expected
)
!==
FALSE
,
"
\"
$output
\"
contains
\"
$expected
\"
"
);
$this
->
assertTrue
(
strpos
(
$output
,
'<!-- THEME HOOK: \'filter_caption\' -->'
)
!==
FALSE
,
'filter_caption theme hook debug comment is present.'
);
$output
=
$test
(
$input
)
->
getProcessedText
();
$this
->
assertContains
(
$expected
,
$output
);
$this
->
assertContains
(
"<!-- THEME HOOK: 'filter_caption' -->"
,
$output
);
}
}
This diff is collapsed.
Click to expand it.
Lee Rowlands
@larowlan
mentioned in commit
2791e249
·
5 years ago
mentioned in commit
2791e249
mentioned in commit 2791e2495aa25bed640c22a97400368a9a0b4a34
Toggle commit list
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