xref: /webtrees/tests/app/Module/DescendancyReportModuleTest.php (revision f7cf8a155e2743f3d124eef3d30a558ab062fa4b)
13763c3f2SGreg Roach<?php
23976b470SGreg Roach
33763c3f2SGreg Roach/**
43763c3f2SGreg Roach * webtrees: online genealogy
51fe542e9SGreg 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
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;
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\Filesystem;
32*f7cf8a15SGreg Roachuse League\Flysystem\InMemory\InMemoryFilesystemAdapter;
3369100c6dSGreg Roach
3469100c6dSGreg Roachuse function ob_get_clean;
3569100c6dSGreg Roachuse function ob_start;
369a3accd7SGreg Roach
373763c3f2SGreg Roach/**
383763c3f2SGreg Roach * Test harness for the class DescendancyReportModule
39824da64cSGreg Roach */
40824da64cSGreg Roachclass DescendancyReportModuleTest extends TestCase
41824da64cSGreg Roach{
42824da64cSGreg Roach    protected static $uses_database = true;
43824da64cSGreg Roach
44824da64cSGreg Roach    /**
456113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Module\ModuleReportTrait
46824da64cSGreg Roach     * @covers \Fisharebest\Webtrees\Module\PedigreeReportModule
47b6f35a76SGreg Roach     * @covers \Fisharebest\Webtrees\Report\AbstractRenderer
48824da64cSGreg Roach     * @covers \Fisharebest\Webtrees\Report\HtmlRenderer
49824da64cSGreg Roach     * @covers \Fisharebest\Webtrees\Report\PdfRenderer
506113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportBaseCell
516113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportBaseElement
526113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportBaseFootnote
536113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportBaseImage
546113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportBaseLine
556113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportBaseText
566113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportBaseTextbox
576113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportExpressionLanguageProvider
586113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportHtmlCell
596113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportHtmlFootnote
606113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportHtmlImage
616113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportHtmlLine
626113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportHtmlText
636113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportHtmlTextbox
646113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportParserBase
65c52e6333SGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportParserGenerate
666113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportParserSetup
676113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportPdfCell
686113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportPdfFootnote
696113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportPdfImage
706113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportPdfLine
716113edefSGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportPdfText
72b6f35a76SGreg Roach     * @covers \Fisharebest\Webtrees\Report\ReportPdfTextBox
73824da64cSGreg Roach     * @covers \Fisharebest\Webtrees\Report\TcpdfWrapper
74824da64cSGreg Roach     *
7552348eb8SGreg Roach     * @return void
763763c3f2SGreg Roach     */
779a3accd7SGreg Roach    public function testReportRunsWithoutError(): void
78c1010edaSGreg Roach    {
79*f7cf8a15SGreg Roach        $data_filesystem = new Filesystem(new InMemoryFilesystemAdapter());
80824da64cSGreg Roach        $module_service  = new ModuleService();
81a04bb9a2SGreg Roach
823c5bb98bSGreg Roach        $user = (new UserService())->create('user', 'User', 'user@example.com', 'secret');
831fe542e9SGreg Roach        $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1');
843c5bb98bSGreg Roach        Auth::login($user);
853c5bb98bSGreg Roach
869a3accd7SGreg Roach        $tree   = $this->importTree('demo.ged');
87824da64cSGreg Roach        $module = $module_service->findByInterface(DescendancyReportModule::class)->first();
88824da64cSGreg Roach        $xml    = 'resources/' . $module->xmlFilename();
899a3accd7SGreg Roach        $vars   = [
903c5bb98bSGreg Roach            'pid'      => ['id' => 'X1030'],
919a3accd7SGreg Roach            'maxgen'   => ['id' => '3'],
929a3accd7SGreg Roach            'sources'  => ['id' => 'on'],
939a3accd7SGreg Roach            'pageSize' => ['id' => 'A4'],
949a3accd7SGreg Roach        ];
959a3accd7SGreg Roach
964358d8aeSGreg Roach        $report = new ReportParserSetup($xml);
975e933c21SGreg Roach        self::assertIsArray($report->reportProperties());
984358d8aeSGreg Roach
999a3accd7SGreg Roach        ob_start();
100b6f35a76SGreg Roach        new ReportParserGenerate($xml, new HtmlRenderer(), $vars, $tree, $data_filesystem);
1019a3accd7SGreg Roach        $html = ob_get_clean();
1025e933c21SGreg Roach        self::assertStringStartsWith('<', $html);
1035e933c21SGreg Roach        self::assertStringEndsWith('>', $html);
1049a3accd7SGreg Roach
1059a3accd7SGreg Roach        ob_start();
106b6f35a76SGreg Roach        new ReportParserGenerate($xml, new PdfRenderer(), $vars, $tree, $data_filesystem);
1079a3accd7SGreg Roach        $pdf = ob_get_clean();
108d44668f6SGreg Roach
1095e933c21SGreg Roach        self::assertStringStartsWith('%PDF', $pdf);
1105e933c21SGreg Roach        self::assertStringEndsWith("%%EOF\n", $pdf);
1113763c3f2SGreg Roach    }
1123763c3f2SGreg Roach}
113