Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Drupal.org issue queue
Drupal.org issue queue
Security & Compliance
Security & Compliance
Dependency List
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
project
drupal
Commits
01f76ced
Unverified
Commit
01f76ced
authored
Apr 16, 2019
by
larowlan
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#3046171
by claudiu.cristea, Lendude: Convert FilterCaptionTwigDebugTest into a Kernel test
parent
45cf0448
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
0 deletions
+62
-0
core/modules/filter/tests/src/Kernel/FilterCaptionTwigDebugTest.php
...es/filter/tests/src/Kernel/FilterCaptionTwigDebugTest.php
+62
-0
No files found.
core/modules/filter/tests/src/
Functiona
l/FilterCaptionTwigDebugTest.php
→
core/modules/filter/tests/src/
Kerne
l/FilterCaptionTwigDebugTest.php
View file @
01f76ced
<?php
<?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\Core\Render\RenderContext
;
use
Drupal\Tests\BrowserTestBase
;
use
Drupal\filter\FilterPluginCollection
;
use
Drupal\filter\FilterPluginCollection
;
use
Drupal\KernelTests\KernelTestBase
;
/**
/**
* Tests the caption filter with Twig debugging on.
* Tests the caption filter with Twig debugging on.
*
*
* @group filter
* @group filter
*/
*/
class
FilterCaptionTwigDebugTest
extends
BrowserTestBase
{
class
FilterCaptionTwigDebugTest
extends
KernelTestBase
{
/**
* 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
();
}
}
/**
/**
* {@inheritdoc}
* {@inheritdoc}
*/
*/
protected
function
setUp
()
{
protected
static
$modules
=
[
'filter'
];
parent
::
setUp
();
$this
->
debugOn
();
$manager
=
$this
->
container
->
get
(
'plugin.manager.filter'
);
$bag
=
new
FilterPluginCollection
(
$manager
,
[]);
$this
->
filters
=
$bag
->
getAll
();
}
/**
/**
* {@inheritdoc}
* {@inheritdoc}
*/
*/
protected
function
tearDown
()
{
public
function
register
(
ContainerBuilder
$container
)
{
$this
->
debugOff
();
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.
* Test the caption filter with Twig debugging on.
*/
*/
public
function
testCaptionFilter
()
{
public
function
testCaptionFilter
()
{
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$manager
=
$this
->
container
->
get
(
'plugin.manager.filter'
);
$renderer
=
\Drupal
::
service
(
'renderer'
);
$bag
=
new
FilterPluginCollection
(
$manager
,
[]);
$filter
=
$this
->
filters
[
'filter_caption'
];
$filter
=
$bag
->
get
(
'filter_caption'
);
$renderer
=
$this
->
container
->
get
(
'renderer'
);
$test
=
function
(
$input
)
use
(
$filter
,
$renderer
)
{
$test
=
function
(
$input
)
use
(
$filter
,
$renderer
)
{
return
$renderer
->
executeInRenderContext
(
new
RenderContext
(),
function
()
use
(
$input
,
$filter
)
{
return
$renderer
->
executeInRenderContext
(
new
RenderContext
(),
function
()
use
(
$input
,
$filter
)
{
...
@@ -90,15 +49,14 @@ public function testCaptionFilter() {
...
@@ -90,15 +49,14 @@ public function testCaptionFilter() {
// No data-caption attribute.
// No data-caption attribute.
$input
=
'<img src="llama.jpg" />'
;
$input
=
'<img src="llama.jpg" />'
;
$expected
=
$input
;
$expected
=
$input
;
$this
->
assert
Identical
(
$expected
,
$test
(
$input
)
->
getProcessedText
());
$this
->
assert
Equals
(
$expected
,
$test
(
$input
)
->
getProcessedText
());
// Data-caption attribute.
// Data-caption attribute.
$input
=
'<img src="llama.jpg" data-caption="Loquacious llama!" />'
;
$input
=
'<img src="llama.jpg" data-caption="Loquacious llama!" />'
;
$expected
=
'<img src="llama.jpg" /><figcaption>Loquacious llama!</figcaption>'
;
$expected
=
'<img src="llama.jpg" /><figcaption>Loquacious llama!</figcaption>'
;
$output
=
$test
(
$input
);
$output
=
$test
(
$input
)
->
getProcessedText
();
$output
=
$output
->
getProcessedText
();
$this
->
assertContains
(
$expected
,
$output
);
$this
->
assertTrue
(
strpos
(
$output
,
$expected
)
!==
FALSE
,
"
\"
$output
\"
contains
\"
$expected
\"
"
);
$this
->
assertContains
(
"<!-- THEME HOOK: 'filter_caption' -->"
,
$output
);
$this
->
assertTrue
(
strpos
(
$output
,
'<!-- THEME HOOK: \'filter_caption\' -->'
)
!==
FALSE
,
'filter_caption theme hook debug comment is present.'
);
}
}
}
}
larowlan
@larowlan
mentioned in commit
2791e249
·
Apr 15, 2019
mentioned in commit
2791e249
mentioned in commit 2791e2495aa25bed640c22a97400368a9a0b4a34
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment