xref: /webtrees/tests/app/Module/FactSourcesReportModuleTest.php (revision 73f6d2b56f07f42ca02190f0dfc40653a1e91834)
13763c3f2SGreg Roach<?php
23976b470SGreg Roach
33763c3f2SGreg Roach/**
43763c3f2SGreg Roach * webtrees: online genealogy
5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team
63763c3f2SGreg Roach * This program is free software: you can redistribute it and/or modify
73763c3f2SGreg Roach * it under the terms of the GNU General Public License as published by
83763c3f2SGreg Roach * the Free Software Foundation, either version 3 of the License, or
93763c3f2SGreg Roach * (at your option) any later version.
103763c3f2SGreg Roach * This program is distributed in the hope that it will be useful,
113763c3f2SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
123763c3f2SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
133763c3f2SGreg Roach * GNU General Public License for more details.
143763c3f2SGreg Roach * You should have received a copy of the GNU General Public License
1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
163763c3f2SGreg Roach */
17fcfa147eSGreg Roach
18e7f56f2aSGreg Roachdeclare(strict_types=1);
19e7f56f2aSGreg Roach
2084e2cf4eSGreg Roachnamespace Fisharebest\Webtrees\Module;
213763c3f2SGreg Roach
223c5bb98bSGreg Roachuse Fisharebest\Webtrees\Auth;
231fe542e9SGreg Roachuse Fisharebest\Webtrees\Contracts\UserInterface;
24202c018bSGreg Roachuse Fisharebest\Webtrees\Report\AbstractRenderer;
25b6f35a76SGreg Roachuse Fisharebest\Webtrees\Report\HtmlRenderer;
26f0c88a96SGreg Roachuse Fisharebest\Webtrees\Report\PdfRenderer;
27202c018bSGreg Roachuse Fisharebest\Webtrees\Report\ReportBaseCell;
28202c018bSGreg Roachuse Fisharebest\Webtrees\Report\ReportBaseElement;
29202c018bSGreg Roachuse Fisharebest\Webtrees\Report\ReportBaseFootnote;
30202c018bSGreg Roachuse Fisharebest\Webtrees\Report\ReportBaseImage;
31202c018bSGreg Roachuse Fisharebest\Webtrees\Report\ReportBaseLine;
32202c018bSGreg Roachuse Fisharebest\Webtrees\Report\ReportBaseText;
33202c018bSGreg Roachuse Fisharebest\Webtrees\Report\ReportBaseTextbox;
34202c018bSGreg Roachuse Fisharebest\Webtrees\Report\ReportExpressionLanguageProvider;
35202c018bSGreg Roachuse Fisharebest\Webtrees\Report\ReportHtmlCell;
36202c018bSGreg Roachuse Fisharebest\Webtrees\Report\ReportHtmlFootnote;
37202c018bSGreg Roachuse Fisharebest\Webtrees\Report\ReportHtmlImage;
38202c018bSGreg Roachuse Fisharebest\Webtrees\Report\ReportHtmlLine;
39202c018bSGreg Roachuse Fisharebest\Webtrees\Report\ReportHtmlText;
40202c018bSGreg Roachuse Fisharebest\Webtrees\Report\ReportHtmlTextbox;
41202c018bSGreg Roachuse Fisharebest\Webtrees\Report\ReportParserBase;
429a3accd7SGreg Roachuse Fisharebest\Webtrees\Report\ReportParserGenerate;
434358d8aeSGreg Roachuse Fisharebest\Webtrees\Report\ReportParserSetup;
44202c018bSGreg Roachuse Fisharebest\Webtrees\Report\ReportPdfCell;
45202c018bSGreg Roachuse Fisharebest\Webtrees\Report\ReportPdfFootnote;
46202c018bSGreg Roachuse Fisharebest\Webtrees\Report\ReportPdfImage;
47202c018bSGreg Roachuse Fisharebest\Webtrees\Report\ReportPdfLine;
48202c018bSGreg Roachuse Fisharebest\Webtrees\Report\ReportPdfText;
49202c018bSGreg Roachuse Fisharebest\Webtrees\Report\ReportPdfTextBox;
50202c018bSGreg Roachuse Fisharebest\Webtrees\Report\TcpdfWrapper;
513c5bb98bSGreg Roachuse Fisharebest\Webtrees\Services\UserService;
523cfcc809SGreg Roachuse Fisharebest\Webtrees\TestCase;
53202c018bSGreg Roachuse PHPUnit\Framework\Attributes\CoversClass;
54a6305e60SGreg Roachuse PHPUnit\Framework\Attributes\CoversTrait;
55202c018bSGreg Roach
560acf1b4bSGreg Roachuse function ob_get_clean;
570acf1b4bSGreg Roach
58168400f2SJulien BARBEY#[CoversTrait(ModuleReportTrait::class)]
59202c018bSGreg Roach#[CoversClass(PedigreeReportModule::class)]
60202c018bSGreg Roach#[CoversClass(AbstractRenderer::class)]
61202c018bSGreg Roach#[CoversClass(HtmlRenderer::class)]
62202c018bSGreg Roach#[CoversClass(PdfRenderer::class)]
63202c018bSGreg Roach#[CoversClass(ReportBaseCell::class)]
64202c018bSGreg Roach#[CoversClass(ReportBaseElement::class)]
65202c018bSGreg Roach#[CoversClass(ReportBaseFootnote::class)]
66202c018bSGreg Roach#[CoversClass(ReportBaseImage::class)]
67202c018bSGreg Roach#[CoversClass(ReportBaseLine::class)]
68202c018bSGreg Roach#[CoversClass(ReportBaseText::class)]
69202c018bSGreg Roach#[CoversClass(ReportBaseTextbox::class)]
70202c018bSGreg Roach#[CoversClass(ReportExpressionLanguageProvider::class)]
71202c018bSGreg Roach#[CoversClass(ReportHtmlCell::class)]
72202c018bSGreg Roach#[CoversClass(ReportHtmlFootnote::class)]
73202c018bSGreg Roach#[CoversClass(ReportHtmlImage::class)]
74202c018bSGreg Roach#[CoversClass(ReportHtmlLine::class)]
75202c018bSGreg Roach#[CoversClass(ReportHtmlText::class)]
76202c018bSGreg Roach#[CoversClass(ReportHtmlTextbox::class)]
77202c018bSGreg Roach#[CoversClass(ReportParserBase::class)]
78202c018bSGreg Roach#[CoversClass(ReportParserGenerate::class)]
79202c018bSGreg Roach#[CoversClass(ReportParserSetup::class)]
80202c018bSGreg Roach#[CoversClass(ReportPdfCell::class)]
81202c018bSGreg Roach#[CoversClass(ReportPdfFootnote::class)]
82202c018bSGreg Roach#[CoversClass(ReportPdfImage::class)]
83202c018bSGreg Roach#[CoversClass(ReportPdfLine::class)]
84202c018bSGreg Roach#[CoversClass(ReportPdfText::class)]
85202c018bSGreg Roach#[CoversClass(ReportPdfTextBox::class)]
86202c018bSGreg Roach#[CoversClass(TcpdfWrapper::class)]
87824da64cSGreg Roachclass FactSourcesReportModuleTest extends TestCase
88824da64cSGreg Roach{
89cd94ca66SGreg Roach    protected static bool $uses_database = true;
90824da64cSGreg Roach
919a3accd7SGreg Roach    public function testReportRunsWithoutError(): void
92c1010edaSGreg Roach    {
933c5bb98bSGreg Roach        $user = (new UserService())->create('user', 'User', 'user@example.com', 'secret');
941fe542e9SGreg Roach        $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1');
953c5bb98bSGreg Roach        Auth::login($user);
963c5bb98bSGreg Roach
979a3accd7SGreg Roach        $tree   = $this->importTree('demo.ged');
980acf1b4bSGreg Roach        $module = new FactSourcesReportModule();
990acf1b4bSGreg Roach        $module->setName('fact_sources');
1000acf1b4bSGreg Roach
101824da64cSGreg Roach        $xml  = 'resources/' . $module->xmlFilename();
1029a3accd7SGreg Roach        $vars = [
1039a3accd7SGreg Roach            'id'       => ['id' => 's1'],
1049a3accd7SGreg Roach            'stype'    => ['id' => 'facts'],
1059a3accd7SGreg Roach            'sortby'   => ['id' => 'BIRT:DATE'],
1069a3accd7SGreg Roach            'pageSize' => ['id' => 'A4'],
1079a3accd7SGreg Roach        ];
1089a3accd7SGreg Roach
109*73f6d2b5SGreg Roach        new ReportParserSetup($xml);
1104358d8aeSGreg Roach
1119a3accd7SGreg Roach        ob_start();
1129458f20aSGreg Roach        new ReportParserGenerate($xml, new HtmlRenderer(), $vars, $tree);
1139a3accd7SGreg Roach        $html = ob_get_clean();
114*73f6d2b5SGreg Roach        self::assertIsString($html);
1155e933c21SGreg Roach        self::assertStringStartsWith('<', $html);
1165e933c21SGreg Roach        self::assertStringEndsWith('>', $html);
1179a3accd7SGreg Roach
1189a3accd7SGreg Roach        ob_start();
1199458f20aSGreg Roach        new ReportParserGenerate($xml, new PdfRenderer(), $vars, $tree);
1209a3accd7SGreg Roach        $pdf = ob_get_clean();
121*73f6d2b5SGreg Roach        self::assertIsString($pdf);
1225e933c21SGreg Roach        self::assertStringStartsWith('%PDF', $pdf);
1235e933c21SGreg Roach        self::assertStringEndsWith("%%EOF\n", $pdf);
1243763c3f2SGreg Roach    }
1253763c3f2SGreg Roach}
126