Skip to content

Adding a failing test case for bad figure behavior #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"require": {
"ext-json": "*",
"ext-curl": "*",
"doctrine/rst-parser": "0.3.x-dev",
"doctrine/rst-parser": "0.4.x-dev",
"scrivo/highlight.php": "^9.12.0",
"symfony/filesystem": "^5.2",
"symfony/finder": "^5.2",
Expand Down
19 changes: 10 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/Directive/AbstractAdmonitionDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public function __construct(string $name, string $text)

final public function processSub(Parser $parser, ?Node $document, string $variable, string $data, array $options): ?Node
{
if (null === $document) {
throw new \RuntimeException('Content expected, none found.');
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little extra thing - admonitions (notes, etc) MUST have content. For example, this is illegal:

.. note::

I forgot to indent a message on my note! I'm *note* having a good day ;)

$wrapperDiv = $parser->renderTemplate(
'directives/admonition.html.twig',
[
Expand Down
11 changes: 10 additions & 1 deletion tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,13 @@ public function testParseUnitBlock(string $blockName)
$expectedCrawler = new Crawler($expectedHtml);
$indenter = $this->createIndenter();

$expected = trim($expectedCrawler->filter('body')->html());
// you can add notes to a test file via <!-- REMOVE the notes here -->
// we remove them here for comparing
$expected = preg_replace('/<\!\-\- REMOVE(.)+\-\->/', '', $expected);

$this->assertSame(
$indenter->indent(trim($expectedCrawler->filter('body')->html())),
$indenter->indent($expected),
$indenter->indent(trim($actualCrawler->filter('body')->html()))
);
}
Expand All @@ -123,6 +128,10 @@ public function parserUnitBlockProvider()
'blockName' => 'nodes/list',
];

yield 'figure' => [
'blockName' => 'nodes/figure',
];

yield 'caution' => [
'blockName' => 'directives/caution',
];
Expand Down
22 changes: 22 additions & 0 deletions tests/fixtures/expected/blocks/nodes/figure.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>

<figure>
<!-- REMOVE: src is empty just because the test doesn't utilize the full stack, with CopyImagesListener -->
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really wanted to document why the src= is empty. Making it ACTUALLY work would be a lot more work to make the test much more complex, and I don't think it's worth it (I'm pretty sure the images and image paths are tested elsewhere).

<img src="" alt="Symfony Logo" width="200px" />
</figure>
<p>I am a paragraph AFTER the figure. I should not be included as the
caption for the above figure.</p>

<figure>
<img src="" />

<figcaption><p>But I am a caption <em>for</em> the figure above.</p></figcaption>
</figure>

</body>
</html>
4 changes: 2 additions & 2 deletions tests/fixtures/expected/toctree/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ <h1 id="toctree"><a class="headerlink" href="#toctree" title="Permalink to this
<div class="toctree-wrapper"><ul class="toctree toctree-level-1 toctree-length-1"><li><a href="file.html">Title</a><ul class="toctree toctree-level-2 toctree-length-1"><li><a href="file.html#sub-title">Sub title</a></li></ul></li></ul></div>
<div class="toctree-wrapper"><ul class="toctree toctree-level-1 toctree-length-1"><li><a href="file.html">Title</a></li></ul></div>
<div class="toctree-wrapper"><ul class="toctree toctree-level-1 toctree-length-1"><li><a href="directory/another_file.html">Another file</a></li></ul></div>
<div class="toctree-wrapper"><ul class="toctree toctree-level-1 toctree-length-3"><li><a href="index.html#toctree">Toctree</a></li><li><a href="directory/another_file.html">Another file</a></li><li><a href="file.html">Title</a><ul class="toctree toctree-level-2 toctree-length-1"><li><a href="file.html#sub-title">Sub title</a></li></ul></li></ul></div>
<div class="toctree-wrapper"><ul class="toctree toctree-level-1 toctree-length-3"><li><a href="file.html">Title</a><ul class="toctree toctree-level-2 toctree-length-1"><li><a href="file.html#sub-title">Sub title</a></li></ul></li><li><a href="index.html#toctree">Toctree</a></li><li><a href="directory/another_file.html">Another file</a></li></ul></div>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

caused by fixes upstream

<div class="toctree-wrapper"><ul class="toctree toctree-level-1 toctree-length-2"><li><a href="directory/another_file.html">Another file</a></li><li><a href="file.html">Title</a><ul class="toctree toctree-level-2 toctree-length-1"><li><a href="file.html#sub-title">Sub title</a></li></ul></li></ul></div>
<div class="toctree-wrapper"><ul class="toctree toctree-level-1 toctree-length-2"><li><a href="file.html">Title</a><ul class="toctree toctree-level-2 toctree-length-1"><li><a href="file.html#sub-title">Sub title</a></li></ul></li><li><a href="directory/another_file.html">Another file</a></li></ul></div>

</div>

Expand Down
10 changes: 10 additions & 0 deletions tests/fixtures/source/blocks/nodes/figure.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.. figure:: images/logo.png
:alt: Symfony Logo
:width: 200px

I am a paragraph AFTER the figure. I should not be included as the
caption for the above figure.

.. figure:: images/logo.png

But I am a caption *for* the figure above.