Skip to content

Commit 5e28a03

Browse files
committed
Adding a failing test case for bad figure behavior
1 parent 82a2fa3 commit 5e28a03

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
@@ -137,8 +137,13 @@ public function testParseUnitBlock(string $blockName)
137137
$indenter = $this->createIndenter();
138138

139139
$expectedFile = sprintf('%s/fixtures/expected/blocks/%s.html', __DIR__, $blockName);
140+
$expected = file_get_contents($expectedFile);
141+
// you can add notes to a test file via <!-- REMOVE the notes here -->
142+
// we remove them here for comparing
143+
$expected = preg_replace('/<\!\-\- REMOVE(.)+\-\->/', '', $expected);
144+
140145
$this->assertSame(
141-
str_replace(" \n", "\n", $indenter->indent(file_get_contents($expectedFile))),
146+
str_replace(" \n", "\n", $indenter->indent($expected)),
142147
str_replace(" \n", "\n", $indenter->indent($document))
143148
);
144149
}
@@ -157,6 +162,10 @@ public function parserUnitBlockProvider()
157162
'blockName' => 'nodes/list',
158163
];
159164

165+
yield 'figure' => [
166+
'blockName' => 'nodes/figure',
167+
];
168+
160169
yield 'caution' => [
161170
'blockName' => 'directives/caution',
162171
];
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)