Skip to content

Commit fde2351

Browse files
committed
Adding a failing test case for bad figure behavior
1 parent 368ef5a commit fde2351

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

src/Directive/AbstractAdmonitionDirective.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public function __construct(string $name, string $text)
2929

3030
final public function processSub(Parser $parser, ?Node $document, string $variable, string $data, array $options): ?Node
3131
{
32+
if (null === $document) {
33+
throw new \RuntimeException('Content expected, none found.');
34+
}
35+
3236
$wrapperDiv = $parser->renderTemplate(
3337
'directives/admonition.html.twig',
3438
[

tests/IntegrationTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,13 @@ public function testParseUnitBlock(string $blockName)
103103
$expectedCrawler = new Crawler($expectedHtml);
104104
$indenter = $this->createIndenter();
105105

106+
$expected = trim($expectedCrawler->filter('body')->html())
107+
// you can add notes to a test file via <!-- REMOVE the notes here -->
108+
// we remove them here for comparing
109+
$expected = preg_replace('/<\!\-\- REMOVE(.)+\-\->/', '', $expected);
110+
106111
$this->assertSame(
107-
$indenter->indent(trim($expectedCrawler->filter('body')->html())),
112+
$indenter->indent($expected),
108113
$indenter->indent(trim($actualCrawler->filter('body')->html()))
109114
);
110115
}
@@ -123,6 +128,10 @@ public function parserUnitBlockProvider()
123128
'blockName' => 'nodes/list',
124129
];
125130

131+
yield 'figure' => [
132+
'blockName' => 'nodes/figure',
133+
];
134+
126135
yield 'caution' => [
127136
'blockName' => 'directives/caution',
128137
];
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
</head>
6+
<body>
7+
8+
<figure>
9+
<!-- REMOVE: src is empty just because the test doesn't utilize the full stack, with CopyImagesListener -->
10+
<img src="" alt="Symfony Logo" width="200px" />
11+
</figure>
12+
<p>I am a paragraph AFTER the figure. I should not be included as the
13+
caption for the above figure.</p>
14+
15+
<figure>
16+
<img src="" />
17+
18+
<figcaption><p>But I am a caption <em>for</em> the figure above.</p></figcaption>
19+
</figure>
20+
21+
</body>
22+
</html>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.. figure:: images/logo.png
2+
:alt: Symfony Logo
3+
:width: 200px
4+
5+
I am a paragraph AFTER the figure. I should not be included as the
6+
caption for the above figure.
7+
8+
.. figure:: images/logo.png
9+
10+
But I am a caption *for* the figure above.

0 commit comments

Comments
 (0)