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

Refactor test helpers and test files #104

Merged
merged 6 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
51 changes: 24 additions & 27 deletions tests/TestRender.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,36 @@
class TestRender {
protected ?Format $format = null;

protected Config $config;

public function __construct(
?Format $format,
array $opts,
?array $extra = [],
?array $indices = []
Config $config,
?array $indices = [],
) {
foreach ($opts as $k => $v) {
$method = "set_$k";
Config::$method($v);
}
if (count($extra) != 0) {
Config::init($extra);
}

if ($format !== null) {
$this->format = $format;

foreach ($indices as $index) {
$this->format->SQLiteIndex(
null, // $context,
null, // $index,
$index["docbook_id"] ?? "", // $id,
$index["filename"] ?? "", // $filename,
$index["parent_id"] ?? "", // $parent,
$index["sdesc"] ?? "", // $sdesc,
$index["ldesc"] ?? "", // $ldesc,
$index["element"] ?? "", // $element,
$index["previous"] ?? "", // $previous,
$index["next"] ?? "", // $next,
$index["chunk"] ?? 0, // $chunk
);
if ($indices) {
foreach ($indices as $index) {
$this->format->SQLiteIndex(
null, // $context,
null, // $index,
$index["docbook_id"] ?? "", // $id,
$index["filename"] ?? "", // $filename,
$index["parent_id"] ?? "", // $parent,
$index["sdesc"] ?? "", // $sdesc,
$index["ldesc"] ?? "", // $ldesc,
$index["element"] ?? "", // $element,
$index["previous"] ?? "", // $previous,
$index["next"] ?? "", // $next,
$index["chunk"] ?? 0, // $chunk
);
}
}
}

$this->config = $config;
}

public function run() {
Expand All @@ -46,14 +43,14 @@ public function run() {
if (Index::requireIndexing()) {
$format = new Index;
$render->attach($format);
$reader->open(Config::xml_file());
$reader->open($this->config::xml_file());
$render->execute($reader);
$render->detach($format);
}

if ($this->format !== null) {
$render->attach($this->format);
$reader->open(Config::xml_file());
$reader->open($this->config::xml_file());
$render->execute($reader);
}
}
Expand Down
9 changes: 3 additions & 6 deletions tests/php/bug49101-1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,18 @@ require_once __DIR__ . "/TestChunkedXHTML.php";

$xml_file = __DIR__ . "/data/bug49101-1.xml";

$opts = array(
Config::init([
"index" => true,
"xml_root" => dirname($xml_file),
"xml_file" => $xml_file,
"output_dir" => __DIR__ . "/output/",
);

$extra = array(
"lang_dir" => __DIR__ . "/../../phpdotnet/phd/data/langs/",
"phpweb_version_filename" => dirname($xml_file) . '/version.xml',
"phpweb_acronym_filename" => dirname($xml_file) . '/acronyms.xml',
);
]);

$format = new TestChunkedXHTML;
$render = new TestRender($format, $opts, $extra);
$render = new TestRender($format, new Config);

if (Index::requireIndexing() && !file_exists($opts["output_dir"])) {
mkdir($opts["output_dir"], 0755);
Expand Down
9 changes: 3 additions & 6 deletions tests/php/bug49101-2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,18 @@ require_once __DIR__ . "/TestBigXHTML.php";

$xml_file = __DIR__ . "/data/bug49101-1.xml";

$opts = array(
Config::init([
"index" => true,
"xml_root" => dirname($xml_file),
"xml_file" => $xml_file,
"output_dir" => __DIR__ . "/output/",
);

$extra = array(
"lang_dir" => __DIR__ . "/../../phpdotnet/phd/data/langs/",
"phpweb_version_filename" => dirname($xml_file) . '/version.xml',
"phpweb_acronym_filename" => dirname($xml_file) . '/acronyms.xml',
);
]);

$format = new TestBigXHTML;
$render = new TestRender($format, $opts, $extra);
$render = new TestRender($format, new Config);

if (Index::requireIndexing() && !file_exists($opts["output_dir"])) {
mkdir($opts["output_dir"], 0755);
Expand Down
11 changes: 4 additions & 7 deletions tests/php/bug49102-1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,19 @@ require_once __DIR__ . "/TestChunkedXHTML.php";

$xml_file = __DIR__ . "/data/bug49102-1.xml";

$opts = array(
Config::init([
"index" => true,
"xml_root" => dirname($xml_file),
"xml_file" => $xml_file,
"output_dir" => __DIR__ . "/output/",
'language' => 'en'
);

$extra = array(
'language' => 'en',
"lang_dir" => __DIR__ . "/../../phpdotnet/phd/data/langs/",
"phpweb_version_filename" => dirname($xml_file) . '/version.xml',
"phpweb_acronym_filename" => dirname($xml_file) . '/acronyms.xml',
);
]);

$format = new TestChunkedXHTML;
$render = new TestRender($format, $opts, $extra);
$render = new TestRender($format, new Config);

if (Index::requireIndexing() && !file_exists($opts["output_dir"])) {
mkdir($opts["output_dir"], 0755);
Expand Down
9 changes: 3 additions & 6 deletions tests/php/bug_doc-en_GH-3179.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,18 @@ require_once __DIR__ . "/TestChunkedXHTML.php";

$xml_file = __DIR__ . "/data/bug_doc-en_GH-3197.xml";

$opts = array(
Config::init([
"index" => true,
"xml_root" => dirname($xml_file),
"xml_file" => $xml_file,
"output_dir" => __DIR__ . "/output/",
);

$extra = array(
"lang_dir" => __PHDDIR__ . "phpdotnet/phd/data/langs/",
"phpweb_version_filename" => dirname($xml_file) . '/version.xml',
"phpweb_acronym_filename" => dirname($xml_file) . '/acronyms.xml',
);
]);

$format = new TestChunkedXHTML;
$render = new TestRender($format, $opts, $extra);
$render = new TestRender($format, new Config);

if (Index::requireIndexing() && !file_exists($opts["output_dir"])) {
mkdir($opts["output_dir"], 0755);
Expand Down
11 changes: 4 additions & 7 deletions tests/php/constant_links_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,17 @@ require_once __DIR__ . "/TestChunkedXHTML.php";

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

$opts = array(
Config::init([
"index" => true,
"xml_root" => dirname($xml_file),
"xml_file" => $xml_file,
"output_dir" => __DIR__ . "/output/",
);

$extra = array(
"lang_dir" => __PHDDIR__ . "phpdotnet/phd/data/langs/",
"phpweb_version_filename" => dirname($xml_file) . '/version.xml',
"phpweb_acronym_filename" => dirname($xml_file) . '/acronyms.xml',
);
]);

$indeces = [
$indices = [
[
"docbook_id" => "constant.definitely-exists",
"filename" => "extensionname.constantspage",
Expand All @@ -34,7 +31,7 @@ $indeces = [
];

$format = new TestChunkedXHTML;
$render = new TestRender($format, $opts, $extra, $indeces);
$render = new TestRender($format, new Config, $indices);

if (Index::requireIndexing() && !file_exists($opts["output_dir"])) {
mkdir($opts["output_dir"], 0755);
Expand Down
9 changes: 3 additions & 6 deletions tests/php/faq001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,18 @@ require_once __DIR__ . "/TestChunkedXHTML.php";

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

$opts = array(
Config::init([
"index" => false,
"xml_root" => dirname($xml_file),
"xml_file" => $xml_file,
"output_dir" => __DIR__ . "/output/",
);

$extra = array(
"lang_dir" => __DIR__ . "/../../phpdotnet/phd/data/langs/",
"phpweb_version_filename" => dirname($xml_file) . '/version.xml',
"phpweb_acronym_filename" => dirname($xml_file) . '/acronyms.xml',
);
]);

$format = new TestChunkedXHTML;
$render = new TestRender($format, $opts, $extra);
$render = new TestRender($format, new Config);

if (Index::requireIndexing() && !file_exists($opts["output_dir"])) {
mkdir($opts["output_dir"], 0755);
Expand Down
19 changes: 8 additions & 11 deletions tests/php/type_rendering_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,18 @@ require_once __DIR__ . "/TestChunkedXHTML.php";

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

$opts = array(
"index" => true,
"xml_root" => dirname($xml_file),
"xml_file" => $xml_file,
"output_dir" => __DIR__ . "/output/",
);

$extra = array(
"lang_dir" => __PHDDIR__ . "phpdotnet/phd/data/langs/",
Config::init([
"index" => true,
"xml_root" => dirname($xml_file),
"xml_file" => $xml_file,
"output_dir" => __DIR__ . "/output/",
"lang_dir" => __PHDDIR__ . "phpdotnet/phd/data/langs/",
"phpweb_version_filename" => dirname($xml_file) . '/version.xml',
"phpweb_acronym_filename" => dirname($xml_file) . '/acronyms.xml',
);
]);

$format = new TestChunkedXHTML;
$render = new TestRender($format, $opts, $extra);
$render = new TestRender($format, new Config);

if (Index::requireIndexing() && !file_exists($opts["output_dir"])) {
mkdir($opts["output_dir"], 0755);
Expand Down
9 changes: 3 additions & 6 deletions tests/php/type_rendering_002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,18 @@ require_once __DIR__ . "/TestChunkedXHTML.php";

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

$opts = array(
Config::init([
"index" => true,
"xml_root" => dirname($xml_file),
"xml_file" => $xml_file,
"output_dir" => __DIR__ . "/output/",
);

$extra = array(
"lang_dir" => __PHDDIR__ . "phpdotnet/phd/data/langs/",
"phpweb_version_filename" => dirname($xml_file) . '/version.xml',
"phpweb_acronym_filename" => dirname($xml_file) . '/acronyms.xml',
);
]);

$format = new TestChunkedXHTML;
$render = new TestRender($format, $opts, $extra);
$render = new TestRender($format, new Config);

if (Index::requireIndexing() && !file_exists($opts["output_dir"])) {
mkdir($opts["output_dir"], 0755);
Expand Down
9 changes: 3 additions & 6 deletions tests/php/type_rendering_003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,18 @@ require_once __DIR__ . "/TestChunkedXHTML.php";

$xml_file = __DIR__ . "/data/type_rendering_constructorsynopsis_parameters-and-return-type.xml";

$opts = array(
Config::init([
"index" => true,
"xml_root" => dirname($xml_file),
"xml_file" => $xml_file,
"output_dir" => __DIR__ . "/output/",
);

$extra = array(
"lang_dir" => __PHDDIR__ . "phpdotnet/phd/data/langs/",
"phpweb_version_filename" => dirname($xml_file) . '/version.xml',
"phpweb_acronym_filename" => dirname($xml_file) . '/acronyms.xml',
);
]);

$format = new TestChunkedXHTML;
$render = new TestRender($format, $opts, $extra);
$render = new TestRender($format, new Config);

if (Index::requireIndexing() && !file_exists($opts["output_dir"])) {
mkdir($opts["output_dir"], 0755);
Expand Down
9 changes: 3 additions & 6 deletions tests/xhtml/001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,18 @@ require_once __DIR__ . "/TestChunkedXHTML.php";

$xml_file = __DIR__ . "/data/001-1.xml";

$opts = array(
Config::init([
"index" => true,
"xml_root" => dirname($xml_file),
"xml_file" => $xml_file,
"output_dir" => __DIR__ . "/output/",
);

$extra = array(
"lang_dir" => __PHDDIR__ . "phpdotnet/phd/data/langs/",
"phpweb_version_filename" => dirname($xml_file) . '/version.xml',
"phpweb_acronym_filename" => dirname($xml_file) . '/acronyms.xml',
);
]);

$format = new TestChunkedXHTML;
$render = new TestRender($format, $opts, $extra);
$render = new TestRender($format, new Config);

if (Index::requireIndexing() && !file_exists($opts["output_dir"])) {
mkdir($opts["output_dir"], 0755);
Expand Down
9 changes: 3 additions & 6 deletions tests/xhtml/002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,18 @@ require_once __DIR__ . "/TestChunkedXHTML.php";

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

$opts = array(
Config::init([
"index" => true,
"xml_root" => dirname($xml_file),
"xml_file" => $xml_file,
"output_dir" => __DIR__ . "/output/",
);

$extra = array(
"lang_dir" => __PHDDIR__ . "phpdotnet/phd/data/langs/",
"phpweb_version_filename" => dirname($xml_file) . '/version.xml',
"phpweb_acronym_filename" => dirname($xml_file) . '/acronyms.xml',
);
]);

$format = new TestChunkedXHTML;
$render = new TestRender($format, $opts, $extra);
$render = new TestRender($format, new Config);

if (Index::requireIndexing() && !file_exists($opts["output_dir"])) {
mkdir($opts["output_dir"], 0755);
Expand Down
9 changes: 3 additions & 6 deletions tests/xhtml/003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,18 @@ require_once __DIR__ . "/TestChunkedXHTML.php";

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

$opts = array(
Config::init([
"index" => true,
"xml_root" => dirname($xml_file),
"xml_file" => $xml_file,
"output_dir" => __DIR__ . "/output/",
);

$extra = array(
"lang_dir" => __PHDDIR__ . "phpdotnet/phd/data/langs/",
"phpweb_version_filename" => dirname($xml_file) . '/version.xml',
"phpweb_acronym_filename" => dirname($xml_file) . '/acronyms.xml',
);
]);

$format = new TestChunkedXHTML;
$render = new TestRender($format, $opts, $extra);
$render = new TestRender($format, new Config);

if (Index::requireIndexing() && !file_exists($opts["output_dir"])) {
mkdir($opts["output_dir"], 0755);
Expand Down
Loading