Skip to content

Commit

Permalink
Fix GH-98
Browse files Browse the repository at this point in the history
Store IDs of non-chunked elements.
Closes #98.
  • Loading branch information
haszi committed Feb 26, 2024
1 parent b703f50 commit ae259a6
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
3 changes: 3 additions & 0 deletions phpdotnet/phd/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,9 @@ public function format_chunk($open, $name, $attrs, $props) {
$this->chunks[] = $id;
$this->currentchunk = $id;
$this->storeInfo($name, $id, $id);
} else {
$this->storeInfo($name, $id, $this->currentchunk, false);
$this->appendID();
}
return false;
}
Expand Down
8 changes: 8 additions & 0 deletions phpdotnet/phd/TestIndex.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
namespace phpdotnet\phd;

class TestIndex extends Index {
public function getIndexes(): array {
return $this->indexes;
}
}
37 changes: 37 additions & 0 deletions tests/index/bug_GH-98.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
--TEST--
Bug GH-98 - Non-chunked section is not linked
--FILE--
<?php
namespace phpdotnet\phd;

require_once __DIR__ . "/../setup.php";

$xml_file = __DIR__ . "/data/bug_GH-98.xml";

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

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

$render->run();

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

echo "Indexes stored:\n";

var_dump(in_array("non-chunked.element.id", $indexes));
var_dump(in_array("another.non-chunked.element.id", $indexes));
var_dump(in_array("chunked.element.id", $indexes));
var_dump(in_array("another.chunked.element.id", $indexes));
var_dump(in_array("bug-GH-98", $indexes));
?>
--EXPECT--
Indexes stored:
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
28 changes: 28 additions & 0 deletions tests/index/data/bug_GH-98.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<chapter xml:id="bug-GH-98">

<sect1 xmlns="http://docbook.org/ns/docbook" annotations="chunk:false" xml:id="non-chunked.element.id">
<para>
Content to ensure this elements is indexed
</para>
</sect1>

<section xmlns="http://docbook.org/ns/docbook" annotations="chunk:false" xml:id="another.non-chunked.element.id">
<para>
Content to ensure this elements is indexed too
</para>
</section>

<sect1 xmlns="http://docbook.org/ns/docbook" xml:id="chunked.element.id">
<para>
Content to ensure this elements is indexed as well
</para>
</sect1>

<section xmlns="http://docbook.org/ns/docbook" xml:id="another.chunked.element.id">
<para>
Content to ensure this elements is also indexed
</para>
</section>

</chapter>

0 comments on commit ae259a6

Please sign in to comment.