xref: /webtrees/tests/app/Module/FactSourcesReportModuleTest.php (revision 9458f20a3c5e8e676f65488153a8d8a76b1773fb)
13763c3f2SGreg Roach<?php
23976b470SGreg Roach
33763c3f2SGreg Roach/**
43763c3f2SGreg Roach * webtrees: online genealogy
55bfc6897SGreg Roach * Copyright (C) 2022 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;
24b6f35a76SGreg Roachuse Fisharebest\Webtrees\Report\HtmlRenderer;
25f0c88a96SGreg Roachuse Fisharebest\Webtrees\Report\PdfRenderer;
269a3accd7SGreg Roachuse Fisharebest\Webtrees\Report\ReportParserGenerate;
274358d8aeSGreg Roachuse Fisharebest\Webtrees\Report\ReportParserSetup;
28824da64cSGreg Roachuse Fisharebest\Webtrees\Services\ModuleService;
293c5bb98bSGreg Roachuse Fisharebest\Webtrees\Services\UserService;
303cfcc809SGreg Roachuse Fisharebest\Webtrees\TestCase;
319a3accd7SGreg Roach
323763c3f2SGreg Roach/**
333763c3f2SGreg Roach * Test harness for the class FactSourcesReportModule
34824da64cSGreg Roach */
35824da64cSGreg Roachclass FactSourcesReportModuleTest extends TestCase
36824da64cSGreg Roach{
37cd94ca66SGreg Roach    protected static bool $uses_database = true;
38824da64cSGreg Roach
39824da64cSGreg Roach    /**
406113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Module\ModuleReportTrait
41824da64cSGreg Roach     * @covers \Fisharebest\Webtrees\Module\PedigreeReportModule
42b6f35a76SGreg Roach     * @covers \Fisharebest\Webtrees\Report\AbstractRenderer
43824da64cSGreg Roach     * @covers \Fisharebest\Webtrees\Report\HtmlRenderer
44824da64cSGreg Roach     * @covers \Fisharebest\Webtrees\Report\PdfRenderer
456113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportBaseCell
466113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportBaseElement
476113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportBaseFootnote
486113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportBaseImage
496113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportBaseLine
506113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportBaseText
516113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportBaseTextbox
526113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportExpressionLanguageProvider
536113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportHtmlCell
546113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportHtmlFootnote
556113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportHtmlImage
566113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportHtmlLine
576113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportHtmlText
586113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportHtmlTextbox
596113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportParserBase
60c52e6333SGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportParserGenerate
616113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportParserSetup
626113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportPdfCell
636113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportPdfFootnote
646113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportPdfImage
656113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportPdfLine
666113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportPdfText
67b6f35a76SGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportPdfTextBox
68824da64cSGreg Roach     * @covers \Fisharebest\Webtrees\Report\TcpdfWrapper
69824da64cSGreg Roach     *
7052348eb8SGreg Roach     * @return void
713763c3f2SGreg Roach     */
729a3accd7SGreg Roach    public function testReportRunsWithoutError(): void
73c1010edaSGreg Roach    {
74824da64cSGreg Roach        $module_service = new ModuleService();
75a04bb9a2SGreg Roach
763c5bb98bSGreg Roach        $user = (new UserService())->create('user', 'User', 'user@example.com', 'secret');
771fe542e9SGreg Roach        $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1');
783c5bb98bSGreg Roach        Auth::login($user);
793c5bb98bSGreg Roach
809a3accd7SGreg Roach        $tree   = $this->importTree('demo.ged');
81824da64cSGreg Roach        $module = $module_service->findByInterface(FactSourcesReportModule::class)->first();
82824da64cSGreg Roach        $xml    = 'resources/' . $module->xmlFilename();
839a3accd7SGreg Roach        $vars   = [
849a3accd7SGreg Roach            'id'       => ['id' => 's1'],
859a3accd7SGreg Roach            'stype'    => ['id' => 'facts'],
869a3accd7SGreg Roach            'sortby'   => ['id' => 'BIRT:DATE'],
879a3accd7SGreg Roach            'pageSize' => ['id' => 'A4'],
889a3accd7SGreg Roach        ];
899a3accd7SGreg Roach
904358d8aeSGreg Roach        $report = new ReportParserSetup($xml);
915e933c21SGreg Roach        self::assertIsArray($report->reportProperties());
924358d8aeSGreg Roach
939a3accd7SGreg Roach        ob_start();
94*9458f20aSGreg Roach        new ReportParserGenerate($xml, new HtmlRenderer(), $vars, $tree);
959a3accd7SGreg Roach        $html = ob_get_clean();
965e933c21SGreg Roach        self::assertStringStartsWith('<', $html);
975e933c21SGreg Roach        self::assertStringEndsWith('>', $html);
989a3accd7SGreg Roach
999a3accd7SGreg Roach        ob_start();
100*9458f20aSGreg Roach        new ReportParserGenerate($xml, new PdfRenderer(), $vars, $tree);
1019a3accd7SGreg Roach        $pdf = ob_get_clean();
1025e933c21SGreg Roach        self::assertStringStartsWith('%PDF', $pdf);
1035e933c21SGreg Roach        self::assertStringEndsWith("%%EOF\n", $pdf);
1043763c3f2SGreg Roach    }
1053763c3f2SGreg Roach}
106