xref: /webtrees/tests/app/Module/BirthDeathMarriageReportModuleTest.php (revision 1270d2767576ed4a83917769b0ee3613e3b010bf)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2023 webtrees development team
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees\Module;
21
22use Fisharebest\Webtrees\Report\AbstractRenderer;
23use Fisharebest\Webtrees\Report\HtmlRenderer;
24use Fisharebest\Webtrees\Report\PdfRenderer;
25use Fisharebest\Webtrees\Report\ReportBaseCell;
26use Fisharebest\Webtrees\Report\ReportBaseElement;
27use Fisharebest\Webtrees\Report\ReportBaseFootnote;
28use Fisharebest\Webtrees\Report\ReportBaseImage;
29use Fisharebest\Webtrees\Report\ReportBaseLine;
30use Fisharebest\Webtrees\Report\ReportBaseText;
31use Fisharebest\Webtrees\Report\ReportBaseTextbox;
32use Fisharebest\Webtrees\Report\ReportExpressionLanguageProvider;
33use Fisharebest\Webtrees\Report\ReportHtmlCell;
34use Fisharebest\Webtrees\Report\ReportHtmlFootnote;
35use Fisharebest\Webtrees\Report\ReportHtmlImage;
36use Fisharebest\Webtrees\Report\ReportHtmlLine;
37use Fisharebest\Webtrees\Report\ReportHtmlText;
38use Fisharebest\Webtrees\Report\ReportHtmlTextbox;
39use Fisharebest\Webtrees\Report\ReportParserBase;
40use Fisharebest\Webtrees\Report\ReportParserGenerate;
41use Fisharebest\Webtrees\Report\ReportParserSetup;
42use Fisharebest\Webtrees\Report\ReportPdfCell;
43use Fisharebest\Webtrees\Report\ReportPdfFootnote;
44use Fisharebest\Webtrees\Report\ReportPdfImage;
45use Fisharebest\Webtrees\Report\ReportPdfLine;
46use Fisharebest\Webtrees\Report\ReportPdfText;
47use Fisharebest\Webtrees\Report\ReportPdfTextBox;
48use Fisharebest\Webtrees\Report\TcpdfWrapper;
49use Fisharebest\Webtrees\TestCase;
50use PHPUnit\Framework\Attributes\CoversClass;
51use PHPUnit\Framework\Attributes\CoversTrait;
52
53#[CoversTrait(ModuleReportTrait::class)]
54#[CoversClass(PedigreeReportModule::class)]
55#[CoversClass(AbstractRenderer::class)]
56#[CoversClass(HtmlRenderer::class)]
57#[CoversClass(PdfRenderer::class)]
58#[CoversClass(ReportBaseCell::class)]
59#[CoversClass(ReportBaseElement::class)]
60#[CoversClass(ReportBaseFootnote::class)]
61#[CoversClass(ReportBaseImage::class)]
62#[CoversClass(ReportBaseLine::class)]
63#[CoversClass(ReportBaseText::class)]
64#[CoversClass(ReportBaseTextbox::class)]
65#[CoversClass(ReportExpressionLanguageProvider::class)]
66#[CoversClass(ReportHtmlCell::class)]
67#[CoversClass(ReportHtmlFootnote::class)]
68#[CoversClass(ReportHtmlImage::class)]
69#[CoversClass(ReportHtmlLine::class)]
70#[CoversClass(ReportHtmlText::class)]
71#[CoversClass(ReportHtmlTextbox::class)]
72#[CoversClass(ReportParserBase::class)]
73#[CoversClass(ReportParserGenerate::class)]
74#[CoversClass(ReportParserSetup::class)]
75#[CoversClass(ReportPdfCell::class)]
76#[CoversClass(ReportPdfFootnote::class)]
77#[CoversClass(ReportPdfImage::class)]
78#[CoversClass(ReportPdfLine::class)]
79#[CoversClass(ReportPdfText::class)]
80#[CoversClass(ReportPdfTextBox::class)]
81#[CoversClass(TcpdfWrapper::class)]
82class BirthDeathMarriageReportModuleTest extends TestCase
83{
84    protected static bool $uses_database = true;
85
86    public function testReportRunsWithoutError(): void
87    {
88        $tree   = $this->importTree('demo.ged');
89        $module = new BirthDeathMarriageReportModule();
90        $module->setName('bdm_report');
91
92        $xml  = 'resources/' . $module->xmlFilename();
93        $vars = [
94            'name'       => ['id' => ''],
95            'bdmplace'   => ['id' => ''],
96            'birthdate1' => ['id' => ''],
97            'birthdate2' => ['id' => ''],
98            'deathdate1' => ['id' => ''],
99            'deathdate2' => ['id' => ''],
100            'sortby'     => ['id' => 'BIRT:DATE'],
101            'pageSize'   => ['id' => 'A4'],
102        ];
103
104        new ReportParserSetup($xml);
105
106        ob_start();
107        new ReportParserGenerate($xml, new HtmlRenderer(), $vars, $tree);
108        $html = ob_get_clean();
109        self::assertIsString($html);
110        self::assertStringStartsWith('<', $html);
111        self::assertStringEndsWith('>', $html);
112
113        ob_start();
114        new ReportParserGenerate($xml, new PdfRenderer(), $vars, $tree);
115        $pdf = ob_get_clean();
116        self::assertIsString($pdf);
117        self::assertStringStartsWith('%PDF', $pdf);
118        self::assertStringEndsWith("%%EOF\n", $pdf);
119    }
120}
121