xref: /webtrees/tests/app/Module/FactSourcesReportModuleTest.php (revision 202c018b592d5a516e4a465dc6dc515f3be37399)
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;
53
54use PHPUnit\Framework\Attributes\CoversClass;
55
56use function ob_get_clean;
57
58
59#[CoversClass(ModuleReportTrait::class)]
60#[CoversClass(PedigreeReportModule::class)]
61#[CoversClass(AbstractRenderer::class)]
62#[CoversClass(HtmlRenderer::class)]
63#[CoversClass(PdfRenderer::class)]
64#[CoversClass(ReportBaseCell::class)]
65#[CoversClass(ReportBaseElement::class)]
66#[CoversClass(ReportBaseFootnote::class)]
67#[CoversClass(ReportBaseImage::class)]
68#[CoversClass(ReportBaseLine::class)]
69#[CoversClass(ReportBaseText::class)]
70#[CoversClass(ReportBaseTextbox::class)]
71#[CoversClass(ReportExpressionLanguageProvider::class)]
72#[CoversClass(ReportHtmlCell::class)]
73#[CoversClass(ReportHtmlFootnote::class)]
74#[CoversClass(ReportHtmlImage::class)]
75#[CoversClass(ReportHtmlLine::class)]
76#[CoversClass(ReportHtmlText::class)]
77#[CoversClass(ReportHtmlTextbox::class)]
78#[CoversClass(ReportParserBase::class)]
79#[CoversClass(ReportParserGenerate::class)]
80#[CoversClass(ReportParserSetup::class)]
81#[CoversClass(ReportPdfCell::class)]
82#[CoversClass(ReportPdfFootnote::class)]
83#[CoversClass(ReportPdfImage::class)]
84#[CoversClass(ReportPdfLine::class)]
85#[CoversClass(ReportPdfText::class)]
86#[CoversClass(ReportPdfTextBox::class)]
87#[CoversClass(TcpdfWrapper::class)]
88class FactSourcesReportModuleTest extends TestCase
89{
90    protected static bool $uses_database = true;
91
92    public function testReportRunsWithoutError(): void
93    {
94        $user = (new UserService())->create('user', 'User', 'user@example.com', 'secret');
95        $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1');
96        Auth::login($user);
97
98        $tree   = $this->importTree('demo.ged');
99        $module = new FactSourcesReportModule();
100        $module->setName('fact_sources');
101
102        $xml  = 'resources/' . $module->xmlFilename();
103        $vars = [
104            'id'       => ['id' => 's1'],
105            'stype'    => ['id' => 'facts'],
106            'sortby'   => ['id' => 'BIRT:DATE'],
107            'pageSize' => ['id' => 'A4'],
108        ];
109
110        $report = new ReportParserSetup($xml);
111        self::assertNotEmpty($report->reportProperties());
112
113        ob_start();
114        new ReportParserGenerate($xml, new HtmlRenderer(), $vars, $tree);
115        $html = ob_get_clean();
116        self::assertStringStartsWith('<', $html);
117        self::assertStringEndsWith('>', $html);
118
119        ob_start();
120        new ReportParserGenerate($xml, new PdfRenderer(), $vars, $tree);
121        $pdf = ob_get_clean();
122        self::assertStringStartsWith('%PDF', $pdf);
123        self::assertStringEndsWith("%%EOF\n", $pdf);
124    }
125}
126