Skip to content

Commit

Permalink
Add example indexing and rendering test
Browse files Browse the repository at this point in the history
  • Loading branch information
haszi committed Jun 4, 2024
1 parent 195745e commit 20c580c
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 0 deletions.
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>

0 comments on commit 20c580c

Please sign in to comment.