xref: /webtrees/tests/app/Module/MissingFactsReportModuleTest.php (revision f7fbac5eee26b56257dd10e318c579e3962d00e1)
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\Auth;
23use Fisharebest\Webtrees\Contracts\UserInterface;
24use Fisharebest\Webtrees\Report\AbstractRenderer;
25use Fisharebest\Webtrees\Report\HtmlRenderer;
26use Fisharebest\Webtrees\Report\PdfRenderer;
27use Fisharebest\Webtrees\Report\ReportBaseCell;
28use Fisharebest\Webtrees\Report\ReportBaseElement;
29use Fisharebest\Webtrees\Report\ReportBaseFootnote;
30use Fisharebest\Webtrees\Report\ReportBaseImage;
31use Fisharebest\Webtrees\Report\ReportBaseLine;
32use Fisharebest\Webtrees\Report\ReportBaseText;
33use Fisharebest\Webtrees\Report\ReportBaseTextbox;
34use Fisharebest\Webtrees\Report\ReportExpressionLanguageProvider;
35use Fisharebest\Webtrees\Report\ReportHtmlCell;
36use Fisharebest\Webtrees\Report\ReportHtmlFootnote;
37use Fisharebest\Webtrees\Report\ReportHtmlImage;
38use Fisharebest\Webtrees\Report\ReportHtmlLine;
39use Fisharebest\Webtrees\Report\ReportHtmlText;
40use Fisharebest\Webtrees\Report\ReportHtmlTextbox;
41use Fisharebest\Webtrees\Report\ReportParserBase;
42use Fisharebest\Webtrees\Report\ReportParserGenerate;
43use Fisharebest\Webtrees\Report\ReportParserSetup;
44use Fisharebest\Webtrees\Report\ReportPdfCell;
45use Fisharebest\Webtrees\Report\ReportPdfFootnote;
46use Fisharebest\Webtrees\Report\ReportPdfImage;
47use Fisharebest\Webtrees\Report\ReportPdfLine;
48use Fisharebest\Webtrees\Report\ReportPdfText;
49use Fisharebest\Webtrees\Report\ReportPdfTextBox;
50use Fisharebest\Webtrees\Report\TcpdfWrapper;
51use Fisharebest\Webtrees\Services\UserService;
52use Fisharebest\Webtrees\TestCase;
53use PHPUnit\Framework\Attributes\CoversClass;
54
55#[CoversClass(ModuleReportTrait::class)]
56#[CoversClass(PedigreeReportModule::class)]
57#[CoversClass(AbstractRenderer::class)]
58#[CoversClass(HtmlRenderer::class)]
59#[CoversClass(PdfRenderer::class)]
60#[CoversClass(ReportBaseCell::class)]
61#[CoversClass(ReportBaseElement::class)]
62#[CoversClass(ReportBaseFootnote::class)]
63#[CoversClass(ReportBaseImage::class)]
64#[CoversClass(ReportBaseLine::class)]
65#[CoversClass(ReportBaseText::class)]
66#[CoversClass(ReportBaseTextbox::class)]
67#[CoversClass(ReportExpressionLanguageProvider::class)]
68#[CoversClass(ReportHtmlCell::class)]
69#[CoversClass(ReportHtmlFootnote::class)]
70#[CoversClass(ReportHtmlImage::class)]
71#[CoversClass(ReportHtmlLine::class)]
72#[CoversClass(ReportHtmlText::class)]
73#[CoversClass(ReportHtmlTextbox::class)]
74#[CoversClass(ReportParserBase::class)]
75#[CoversClass(ReportParserGenerate::class)]
76#[CoversClass(ReportParserSetup::class)]
77#[CoversClass(ReportPdfCell::class)]
78#[CoversClass(ReportPdfFootnote::class)]
79#[CoversClass(ReportPdfImage::class)]
80#[CoversClass(ReportPdfLine::class)]
81#[CoversClass(ReportPdfText::class)]
82#[CoversClass(ReportPdfTextBox::class)]
83#[CoversClass(TcpdfWrapper::class)]
84class MissingFactsReportModuleTest extends TestCase
85{
86    protected static bool $uses_database = true;
87
88    public function testReportRunsWithoutError(): void
89    {
90        $user = (new UserService())->create('user', 'User', 'user@example.com', 'secret');
91        $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1');
92        Auth::login($user);
93
94        $tree   = $this->importTree('demo.ged');
95        $module = new MissingFactsReportModule();
96        $module->setName('missing_facts_report');
97
98        $xml  = 'resources/' . $module->xmlFilename();
99        $vars = [
100            'pid'       => ['id' => 'X1030'],
101            'relatives' => ['id' => 'direct-ancestors'],
102            'maxgen'    => ['id' => '*'],
103            'pageSize'  => ['id' => 'A4'],
104            'sortby'    => ['id' => 'NAME'],
105            'fbirt'     => ['id' => 'on'],
106            'fburi'     => ['id' => 'on'],
107            'fdeat'     => ['id' => 'on'],
108            'fsour'     => ['id' => 'on'],
109            'fbapm'     => ['id' => 'on'],
110            'fbarm'     => ['id' => 'on'],
111            'fbasm'     => ['id' => 'on'],
112            'fconf'     => ['id' => 'on'],
113            'fenga'     => ['id' => 'on'],
114            'ffcom'     => ['id' => 'on'],
115            'fmarb'     => ['id' => 'on'],
116            'fmarr'     => ['id' => 'on'],
117            'freli'     => ['id' => 'on'],
118        ];
119
120        $report = new ReportParserSetup($xml);
121        self::assertNotEmpty($report->reportProperties());
122
123        ob_start();
124        new ReportParserGenerate($xml, new HtmlRenderer(), $vars, $tree);
125        $html = ob_get_clean();
126        self::assertStringStartsWith('<', $html);
127        self::assertStringEndsWith('>', $html);
128
129        ob_start();
130        new ReportParserGenerate($xml, new PdfRenderer(), $vars, $tree);
131        $pdf = ob_get_clean();
132        self::assertStringStartsWith('%PDF', $pdf);
133        self::assertStringEndsWith("%%EOF\n", $pdf);
134    }
135}
136