xref: /webtrees/tests/app/Module/PedigreeReportModuleTest.php (revision 1fe542e96f8f7eedeebc278fae1e0ab0d9e74d95)
13763c3f2SGreg Roach<?php
23976b470SGreg Roach
33763c3f2SGreg Roach/**
43763c3f2SGreg Roach * webtrees: online genealogy
5*1fe542e9SGreg Roach * Copyright (C) 2021 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
153763c3f2SGreg Roach * along with this program. If not, see <http://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;
23*1fe542e9SGreg Roachuse Fisharebest\Webtrees\Contracts\UserInterface;
24b6f35a76SGreg Roachuse Fisharebest\Webtrees\Report\HtmlRenderer;
259a3accd7SGreg Roachuse Fisharebest\Webtrees\Report\ReportParserGenerate;
264358d8aeSGreg Roachuse Fisharebest\Webtrees\Report\ReportParserSetup;
27b6f35a76SGreg Roachuse Fisharebest\Webtrees\Report\PdfRenderer;
28824da64cSGreg Roachuse Fisharebest\Webtrees\Services\ModuleService;
293c5bb98bSGreg Roachuse Fisharebest\Webtrees\Services\UserService;
303cfcc809SGreg Roachuse Fisharebest\Webtrees\TestCase;
31a04bb9a2SGreg Roachuse League\Flysystem\Adapter\NullAdapter;
32a04bb9a2SGreg Roachuse League\Flysystem\Filesystem;
339a3accd7SGreg Roach
343763c3f2SGreg Roach/**
353763c3f2SGreg Roach * Test harness for the class PedigreeReportModule
365a3d686cSGreg Roach *
375a3d686cSGreg Roach * @covers \Fisharebest\Webtrees\Module\PedigreeReportModule
38824da64cSGreg Roach */
39824da64cSGreg Roachclass PedigreeReportModuleTest extends TestCase
40824da64cSGreg Roach{
41824da64cSGreg Roach    protected static $uses_database = true;
42824da64cSGreg Roach
43824da64cSGreg Roach    /**
446113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Module\ModuleReportTrait
456113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Module\PedigreeReportModule
46b6f35a76SGreg Roach     * @covers \Fisharebest\Webtrees\Report\AbstractRenderer
47824da64cSGreg Roach     * @covers \Fisharebest\Webtrees\Report\HtmlRenderer
48824da64cSGreg Roach     * @covers \Fisharebest\Webtrees\Report\PdfRenderer
496113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportBaseCell
506113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportBaseElement
516113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportBaseFootnote
526113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportBaseImage
536113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportBaseLine
546113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportBaseText
556113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportBaseTextbox
566113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportExpressionLanguageProvider
576113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportHtmlCell
586113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportHtmlFootnote
596113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportHtmlImage
606113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportHtmlLine
616113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportHtmlText
626113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportHtmlTextbox
636113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportParserBase
64c52e6333SGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportParserGenerate
656113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportParserSetup
666113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportPdfCell
676113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportPdfFootnote
686113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportPdfImage
696113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportPdfLine
706113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportPdfText
71b6f35a76SGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportPdfTextBox
72824da64cSGreg Roach     * @covers \Fisharebest\Webtrees\Report\TcpdfWrapper
73824da64cSGreg Roach     *
7452348eb8SGreg Roach     * @return void
753763c3f2SGreg Roach     */
769a3accd7SGreg Roach    public function testReportRunsWithoutError(): void
77c1010edaSGreg Roach    {
78a04bb9a2SGreg Roach        $data_filesystem = new Filesystem(new NullAdapter());
79824da64cSGreg Roach        $module_service  = new ModuleService();
80a04bb9a2SGreg Roach
813c5bb98bSGreg Roach        $user = (new UserService())->create('user', 'User', 'user@example.com', 'secret');
82*1fe542e9SGreg Roach        $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1');
833c5bb98bSGreg Roach        Auth::login($user);
843c5bb98bSGreg Roach
859a3accd7SGreg Roach        $tree   = $this->importTree('demo.ged');
86824da64cSGreg Roach        $module = $module_service->findByInterface(PedigreeReportModule::class)->first();
87824da64cSGreg Roach        $xml    = 'resources/' . $module->xmlFilename();
889a3accd7SGreg Roach        $vars   = [
893c5bb98bSGreg Roach            'pid'         => ['id' => 'X1030'],
9069cbf2a4SGreg Roach            'spouses'     => ['id' => 'on'],
919a3accd7SGreg Roach            'orientation' => ['id' => 'portrait'],
929a3accd7SGreg Roach        ];
939a3accd7SGreg Roach
944358d8aeSGreg Roach        $report = new ReportParserSetup($xml);
955e933c21SGreg Roach        self::assertIsArray($report->reportProperties());
964358d8aeSGreg Roach
979a3accd7SGreg Roach        ob_start();
98b6f35a76SGreg Roach        new ReportParserGenerate($xml, new HtmlRenderer(), $vars, $tree, $data_filesystem);
999a3accd7SGreg Roach        $html = ob_get_clean();
1005e933c21SGreg Roach        self::assertStringStartsWith('<', $html);
1015e933c21SGreg Roach        self::assertStringEndsWith('>', $html);
1029a3accd7SGreg Roach
1039a3accd7SGreg Roach        ob_start();
104b6f35a76SGreg Roach        new ReportParserGenerate($xml, new PdfRenderer(), $vars, $tree, $data_filesystem);
1059a3accd7SGreg Roach        $pdf = ob_get_clean();
1065e933c21SGreg Roach        self::assertStringStartsWith('%PDF', $pdf);
1075e933c21SGreg Roach        self::assertStringEndsWith("%%EOF\n", $pdf);
1083763c3f2SGreg Roach    }
1093763c3f2SGreg Roach}
110