Skip to content
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

Add example indexing and rendering test #136

Merged
merged 1 commit into from
Jun 4, 2024
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
31 changes: 31 additions & 0 deletions tests/data/example_numbering_001.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<chapter xml:id="example-numbering">
<section>
<example>
<title>- 1. example without an xml:id</title>
</example>
</section>

<section>
<example>
<title>- 2. example without an xml:id</title>
</example>
</section>

<section>
<example xml:id="third-example-id">
<title>- 3. example with an xml:id</title>
</example>
</section>

<section>
<example>
<title>- 4. example without an xml:id</title>
</example>
</section>

<section>
<example>
<title>- 5. example without an xml:id</title>
</example>
</section>
</chapter>
87 changes: 87 additions & 0 deletions tests/example_numbering_001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
--TEST--
Example numbering 001 - indexing and rendering examples with and without an xml:id
--FILE--
<?php
namespace phpdotnet\phd;

require_once __DIR__ . "/setup.php";

$xml_file = __DIR__ . "/data/example_numbering_001.xml";

Config::init([
"force_index" => true,
"xml_file" => $xml_file,
]);

$indexRepository = new IndexRepository(new \SQLite3(":memory:"));
$indexRepository->init();
Config::set_indexcache($indexRepository);

$index = new TestIndex($indexRepository);

$render = new TestRender(new Reader, new Config, null, $index);

$render->run();

$indexes = array_keys($index->getNfo());

echo "Indexes stored:\n";

var_dump($indexes);

$format = new TestGenericChunkedXHTML;

$render = new TestRender(new Reader, new Config, $format);

$render->run();

?>
--EXPECT--
Indexes stored:
array(6) {
[0]=>
string(17) "example-numbering"
[1]=>
string(9) "example-1"
[2]=>
string(9) "example-2"
[3]=>
string(16) "third-example-id"
[4]=>
string(9) "example-4"
[5]=>
string(9) "example-5"
}
Filename: example-numbering.html
Content:
<div id="example-numbering" class="chapter">
<div class="section">
<div class="example" id="example-1">
<p><strong>Example #1 - 1. example without an xml:id</strong></p>
</div>
</div>

<div class="section">
<div class="example" id="example-2">
<p><strong>Example #2 - 2. example without an xml:id</strong></p>
</div>
</div>

<div class="section">
<div class="example" id="third-example-id">
<p><strong>Example #3 - 3. example with an xml:id</strong></p>
</div>
</div>

<div class="section">
<div class="example" id="example-4">
<p><strong>Example #4 - 4. example without an xml:id</strong></p>
</div>
</div>

<div class="section">
<div class="example" id="example-5">
<p><strong>Example #5 - 5. example without an xml:id</strong></p>
</div>
</div>
</div>
Loading