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