xref: /webtrees/tests/app/Module/ChangeReportModuleTest.php (revision 571594c0895f62d0fa91558dcbf8276f2e2b72d0)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2021 webtrees development team
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees\Module;
21
22use Fisharebest\Webtrees\Auth;
23use Fisharebest\Webtrees\Carbon;
24use Fisharebest\Webtrees\Contracts\UserInterface;
25use Fisharebest\Webtrees\Report\HtmlRenderer;
26use Fisharebest\Webtrees\Report\ReportParserGenerate;
27use Fisharebest\Webtrees\Report\ReportParserSetup;
28use Fisharebest\Webtrees\Report\PdfRenderer;
29use Fisharebest\Webtrees\Services\ModuleService;
30use Fisharebest\Webtrees\Services\UserService;
31use Fisharebest\Webtrees\TestCase;
32use League\Flysystem\Filesystem;
33use League\Flysystem\InMemory\InMemoryFilesystemAdapter;
34
35/**
36 * Test harness for the class ChangeReportModule
37 */
38class ChangeReportModuleTest extends TestCase
39{
40    protected static $uses_database = true;
41
42    /**
43     * @covers \Fisharebest\Webtrees\Module\ModuleReportTrait
44     * @covers \Fisharebest\Webtrees\Module\PedigreeReportModule
45     * @covers \Fisharebest\Webtrees\Report\AbstractRenderer
46     * @covers \Fisharebest\Webtrees\Report\HtmlRenderer
47     * @covers \Fisharebest\Webtrees\Report\PdfRenderer
48     * @covers \Fisharebest\Webtrees\Report\ReportBaseCell
49     * @covers \Fisharebest\Webtrees\Report\ReportBaseElement
50     * @covers \Fisharebest\Webtrees\Report\ReportBaseFootnote
51     * @covers \Fisharebest\Webtrees\Report\ReportBaseImage
52     * @covers \Fisharebest\Webtrees\Report\ReportBaseLine
53     * @covers \Fisharebest\Webtrees\Report\ReportBaseText
54     * @covers \Fisharebest\Webtrees\Report\ReportBaseTextbox
55     * @covers \Fisharebest\Webtrees\Report\ReportExpressionLanguageProvider
56     * @covers \Fisharebest\Webtrees\Report\ReportHtmlCell
57     * @covers \Fisharebest\Webtrees\Report\ReportHtmlFootnote
58     * @covers \Fisharebest\Webtrees\Report\ReportHtmlImage
59     * @covers \Fisharebest\Webtrees\Report\ReportHtmlLine
60     * @covers \Fisharebest\Webtrees\Report\ReportHtmlText
61     * @covers \Fisharebest\Webtrees\Report\ReportHtmlTextbox
62     * @covers \Fisharebest\Webtrees\Report\ReportParserBase
63     * @covers \Fisharebest\Webtrees\Report\ReportParserGenerate
64     * @covers \Fisharebest\Webtrees\Report\ReportParserSetup
65     * @covers \Fisharebest\Webtrees\Report\ReportPdfCell
66     * @covers \Fisharebest\Webtrees\Report\ReportPdfFootnote
67     * @covers \Fisharebest\Webtrees\Report\ReportPdfImage
68     * @covers \Fisharebest\Webtrees\Report\ReportPdfLine
69     * @covers \Fisharebest\Webtrees\Report\ReportPdfText
70     * @covers \Fisharebest\Webtrees\Report\ReportPdfTextBox
71     * @covers \Fisharebest\Webtrees\Report\TcpdfWrapper
72     *
73     * @return void
74     */
75    public function testReportRunsWithoutError(): void
76    {
77        $data_filesystem = new Filesystem(new InMemoryFilesystemAdapter());
78        $module_service  = new ModuleService();
79
80        $user = (new UserService())->create('user', 'User', 'user@example.com', 'secret');
81        $user->setPreference(UserInterface::PREF_IS_ADMINISTRATOR, '1');
82        Auth::login($user);
83
84        $tree   = $this->importTree('demo.ged');
85        $module = $module_service->findByInterface(ChangeReportModule::class)->first();
86        $xml    = 'resources/' . $module->xmlFilename();
87        $vars   = [
88            'changeRangeStart' => ['id' => Carbon::now()->subMonth()->format('d M Y')],
89            'changeRangeEnd'   => ['id' => Carbon::now()->format('d M Y')],
90            'pending'          => ['id' => 'yes'],
91            'sortby'           => ['id' => 'CHAN'],
92            'pageSize'         => ['id' => 'A4'],
93            'pageorient'       => ['id' => 'landscape'],
94        ];
95
96        $report = new ReportParserSetup($xml);
97        self::assertIsArray($report->reportProperties());
98
99        ob_start();
100        new ReportParserGenerate($xml, new HtmlRenderer(), $vars, $tree, $data_filesystem);
101        $html = ob_get_clean();
102        self::assertStringStartsWith('<', $html);
103        self::assertStringEndsWith('>', $html);
104
105        ob_start();
106        new ReportParserGenerate($xml, new PdfRenderer(), $vars, $tree, $data_filesystem);
107        $pdf = ob_get_clean();
108        self::assertStringStartsWith('%PDF', $pdf);
109        self::assertStringEndsWith("%%EOF\n", $pdf);
110    }
111}
112