xref: /webtrees/tests/app/Module/FamilyGroupReportModuleTest.php (revision 58a588c63196cb1f4cc1926f6fe552c754b0d27a)
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;
24b6f35a76SGreg Roachuse Fisharebest\Webtrees\Report\HtmlRenderer;
25f0c88a96SGreg Roachuse Fisharebest\Webtrees\Report\PdfRenderer;
269a3accd7SGreg Roachuse Fisharebest\Webtrees\Report\ReportParserGenerate;
274358d8aeSGreg Roachuse Fisharebest\Webtrees\Report\ReportParserSetup;
283c5bb98bSGreg Roachuse Fisharebest\Webtrees\Services\UserService;
293cfcc809SGreg Roachuse Fisharebest\Webtrees\TestCase;
309a3accd7SGreg Roach
310acf1b4bSGreg Roachuse function ob_get_clean;
320acf1b4bSGreg Roach
333763c3f2SGreg Roach/**
343763c3f2SGreg Roach * Test harness for the class FamilyGroupReportModule
35824da64cSGreg Roach */
36824da64cSGreg Roachclass FamilyGroupReportModuleTest extends TestCase
37824da64cSGreg Roach{
38cd94ca66SGreg Roach    protected static bool $uses_database = true;
39824da64cSGreg Roach
40824da64cSGreg Roach    /**
416113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Module\ModuleReportTrait
42824da64cSGreg Roach     * @covers \Fisharebest\Webtrees\Module\PedigreeReportModule
43b6f35a76SGreg Roach     * @covers \Fisharebest\Webtrees\Report\AbstractRenderer
44824da64cSGreg Roach     * @covers \Fisharebest\Webtrees\Report\HtmlRenderer
45824da64cSGreg Roach     * @covers \Fisharebest\Webtrees\Report\PdfRenderer
466113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportBaseCell
476113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportBaseElement
486113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportBaseFootnote
496113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportBaseImage
506113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportBaseLine
516113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportBaseText
526113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportBaseTextbox
536113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportExpressionLanguageProvider
546113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportHtmlCell
556113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportHtmlFootnote
566113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportHtmlImage
576113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportHtmlLine
586113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportHtmlText
596113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportHtmlTextbox
606113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportParserBase
61c52e6333SGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportParserGenerate
626113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportParserSetup
636113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportPdfCell
646113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportPdfFootnote
656113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportPdfImage
666113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportPdfLine
676113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportPdfText
68b6f35a76SGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportPdfTextBox
69824da64cSGreg Roach     * @covers \Fisharebest\Webtrees\Report\TcpdfWrapper
703763c3f2SGreg Roach     */
719a3accd7SGreg Roach    public function testReportRunsWithoutError(): void
72c1010edaSGreg Roach    {
733c5bb98bSGreg Roach        $user = (new UserService())->create('user', 'User', 'user@example.com', 'secret');
741fe542e9SGreg Roach        $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1');
753c5bb98bSGreg Roach        Auth::login($user);
763c5bb98bSGreg Roach
779a3accd7SGreg Roach        $tree   = $this->importTree('demo.ged');
780acf1b4bSGreg Roach        $module = new FamilyGroupReportModule();
790acf1b4bSGreg Roach        $module->setName('family_group_report');
800acf1b4bSGreg Roach
81824da64cSGreg Roach        $xml  = 'resources/' . $module->xmlFilename();
829a3accd7SGreg Roach        $vars = [
839a3accd7SGreg Roach            'id'       => ['id' => 'f1'],
849a3accd7SGreg Roach            'sources'  => ['id' => 'on'],
859a3accd7SGreg Roach            'notes'    => ['id' => 'on'],
869a3accd7SGreg Roach            'photos'   => ['id' => 'on'],
879a3accd7SGreg Roach            'colors'   => ['id' => 'on'],
889a3accd7SGreg Roach            'blanks'   => ['id' => 'on'],
899a3accd7SGreg Roach            'pageSize' => ['id' => 'A4'],
909a3accd7SGreg Roach        ];
919a3accd7SGreg Roach
924358d8aeSGreg Roach        $report = new ReportParserSetup($xml);
93*58a588c6SGreg Roach        self::assertNotEmpty($report->reportProperties());
944358d8aeSGreg Roach
959a3accd7SGreg Roach        ob_start();
969458f20aSGreg Roach        new ReportParserGenerate($xml, new HtmlRenderer(), $vars, $tree);
979a3accd7SGreg Roach        $html = ob_get_clean();
985e933c21SGreg Roach        self::assertStringStartsWith('<', $html);
995e933c21SGreg Roach        self::assertStringEndsWith('>', $html);
1009a3accd7SGreg Roach
1019a3accd7SGreg Roach        ob_start();
1029458f20aSGreg Roach        new ReportParserGenerate($xml, new PdfRenderer(), $vars, $tree);
1039a3accd7SGreg Roach        $pdf = ob_get_clean();
1045e933c21SGreg Roach        self::assertStringStartsWith('%PDF', $pdf);
1055e933c21SGreg Roach        self::assertStringEndsWith("%%EOF\n", $pdf);
1063763c3f2SGreg Roach    }
1073763c3f2SGreg Roach}
108