13763c3f2SGreg Roach<?php 23976b470SGreg Roach 33763c3f2SGreg Roach/** 43763c3f2SGreg Roach * webtrees: online genealogy 58fcd0d32SGreg Roach * Copyright (C) 2019 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; 23b6f35a76SGreg Roachuse Fisharebest\Webtrees\Report\HtmlRenderer; 249a3accd7SGreg Roachuse Fisharebest\Webtrees\Report\ReportParserGenerate; 254358d8aeSGreg Roachuse Fisharebest\Webtrees\Report\ReportParserSetup; 26b6f35a76SGreg Roachuse Fisharebest\Webtrees\Report\PdfRenderer; 27*824da64cSGreg Roachuse Fisharebest\Webtrees\Services\ModuleService; 283c5bb98bSGreg Roachuse Fisharebest\Webtrees\Services\UserService; 293cfcc809SGreg Roachuse Fisharebest\Webtrees\TestCase; 307c4add84SGreg Roachuse Fisharebest\Webtrees\User; 31a04bb9a2SGreg Roachuse League\Flysystem\Adapter\NullAdapter; 32a04bb9a2SGreg Roachuse League\Flysystem\Filesystem; 3369100c6dSGreg Roachuse PHPUnit\Framework\Error\Notice; 3469100c6dSGreg Roach 3569100c6dSGreg Roachuse function ob_get_clean; 3669100c6dSGreg Roachuse function ob_start; 379a3accd7SGreg Roach 383763c3f2SGreg Roach/** 393763c3f2SGreg Roach * Test harness for the class AhnentafelReportModule 40*824da64cSGreg Roach */ 41*824da64cSGreg Roachclass AhnentafelReportModuleTest extends TestCase 42*824da64cSGreg Roach{ 43*824da64cSGreg Roach protected static $uses_database = true; 44*824da64cSGreg Roach 45*824da64cSGreg Roach /** 466113edefSGreg Roach * @covers \Fisharebest\Webtrees\Module\ModuleReportTrait 47*824da64cSGreg Roach * @covers \Fisharebest\Webtrees\Module\PedigreeReportModule 48b6f35a76SGreg Roach * @covers \Fisharebest\Webtrees\Report\AbstractRenderer 49*824da64cSGreg Roach * @covers \Fisharebest\Webtrees\Report\HtmlRenderer 50*824da64cSGreg Roach * @covers \Fisharebest\Webtrees\Report\PdfRenderer 516113edefSGreg Roach * @covers \Fisharebest\Webtrees\Report\ReportBaseCell 526113edefSGreg Roach * @covers \Fisharebest\Webtrees\Report\ReportBaseElement 536113edefSGreg Roach * @covers \Fisharebest\Webtrees\Report\ReportBaseFootnote 546113edefSGreg Roach * @covers \Fisharebest\Webtrees\Report\ReportBaseHtml 556113edefSGreg Roach * @covers \Fisharebest\Webtrees\Report\ReportBaseImage 566113edefSGreg Roach * @covers \Fisharebest\Webtrees\Report\ReportBaseLine 57b6f35a76SGreg Roach * @covers \Fisharebest\Webtrees\Report\ReportBasePageHeader 586113edefSGreg Roach * @covers \Fisharebest\Webtrees\Report\ReportBaseText 596113edefSGreg Roach * @covers \Fisharebest\Webtrees\Report\ReportBaseTextbox 606113edefSGreg Roach * @covers \Fisharebest\Webtrees\Report\ReportExpressionLanguageProvider 616113edefSGreg Roach * @covers \Fisharebest\Webtrees\Report\ReportHtmlCell 626113edefSGreg Roach * @covers \Fisharebest\Webtrees\Report\ReportHtmlFootnote 636113edefSGreg Roach * @covers \Fisharebest\Webtrees\Report\ReportHtmlHtml 646113edefSGreg Roach * @covers \Fisharebest\Webtrees\Report\ReportHtmlImage 656113edefSGreg Roach * @covers \Fisharebest\Webtrees\Report\ReportHtmlLine 66b6f35a76SGreg Roach * @covers \Fisharebest\Webtrees\Report\ReportHtmlPageHeader 676113edefSGreg Roach * @covers \Fisharebest\Webtrees\Report\ReportHtmlText 686113edefSGreg Roach * @covers \Fisharebest\Webtrees\Report\ReportHtmlTextbox 696113edefSGreg Roach * @covers \Fisharebest\Webtrees\Report\ReportParserBase 70c52e6333SGreg Roach * @covers \Fisharebest\Webtrees\Report\ReportParserGenerate 716113edefSGreg Roach * @covers \Fisharebest\Webtrees\Report\ReportParserSetup 726113edefSGreg Roach * @covers \Fisharebest\Webtrees\Report\ReportPdfCell 736113edefSGreg Roach * @covers \Fisharebest\Webtrees\Report\ReportPdfFootnote 746113edefSGreg Roach * @covers \Fisharebest\Webtrees\Report\ReportPdfHtml 756113edefSGreg Roach * @covers \Fisharebest\Webtrees\Report\ReportPdfImage 766113edefSGreg Roach * @covers \Fisharebest\Webtrees\Report\ReportPdfLine 77b6f35a76SGreg Roach * @covers \Fisharebest\Webtrees\Report\ReportPdfPageHeader 786113edefSGreg Roach * @covers \Fisharebest\Webtrees\Report\ReportPdfText 79b6f35a76SGreg Roach * @covers \Fisharebest\Webtrees\Report\ReportPdfTextBox 80*824da64cSGreg Roach * @covers \Fisharebest\Webtrees\Report\TcpdfWrapper 81*824da64cSGreg Roach * 8252348eb8SGreg Roach * @return void 833763c3f2SGreg Roach */ 849a3accd7SGreg Roach public function testReportRunsWithoutError(): void 85c1010edaSGreg Roach { 86a04bb9a2SGreg Roach $data_filesystem = new Filesystem(new NullAdapter()); 87*824da64cSGreg Roach $module_service = new ModuleService(); 88a04bb9a2SGreg Roach 893c5bb98bSGreg Roach $user = (new UserService())->create('user', 'User', 'user@example.com', 'secret'); 907c4add84SGreg Roach $user->setPreference(User::PREF_IS_ADMINISTRATOR, '1'); 913c5bb98bSGreg Roach Auth::login($user); 923c5bb98bSGreg Roach 939a3accd7SGreg Roach $tree = $this->importTree('demo.ged'); 94*824da64cSGreg Roach $module = $module_service->findByInterface(AhnentafelReportModule::class)->first(); 95*824da64cSGreg Roach $xml = 'resources/' . $module->xmlFilename(); 969a3accd7SGreg Roach $vars = [ 973c5bb98bSGreg Roach 'pid' => ['id' => 'X1030'], 989a3accd7SGreg Roach 'maxgen' => ['id' => '3'], 999a3accd7SGreg Roach 'sources' => ['id' => 'on'], 1009a3accd7SGreg Roach 'pageSize' => ['id' => 'A4'], 1019a3accd7SGreg Roach 'notes' => ['id' => 'on'], 1029a3accd7SGreg Roach 'occu' => ['id' => 'on'], 1039a3accd7SGreg Roach 'resi' => ['id' => 'on'], 1049a3accd7SGreg Roach 'children' => ['id' => 'on'], 1059a3accd7SGreg Roach ]; 1069a3accd7SGreg Roach 1074358d8aeSGreg Roach $report = new ReportParserSetup($xml); 1084358d8aeSGreg Roach $this->assertIsArray($report->reportProperties()); 1094358d8aeSGreg Roach 1109a3accd7SGreg Roach ob_start(); 111b6f35a76SGreg Roach new ReportParserGenerate($xml, new HtmlRenderer(), $vars, $tree, $data_filesystem); 1129a3accd7SGreg Roach $html = ob_get_clean(); 1139a3accd7SGreg Roach $this->assertStringStartsWith('<', $html); 1149a3accd7SGreg Roach $this->assertStringEndsWith('>', $html); 1159a3accd7SGreg Roach 1169a3accd7SGreg Roach ob_start(); 11769100c6dSGreg Roach try { 11869100c6dSGreg Roach if (PHP_VERSION_ID >= 70400) { 11969100c6dSGreg Roach $this->expectException(Notice::class); 12069100c6dSGreg Roach $this->expectExceptionMessage('Trying to access array offset on value of type int'); 12169100c6dSGreg Roach } 12269100c6dSGreg Roach 123b6f35a76SGreg Roach new ReportParserGenerate($xml, new PdfRenderer(), $vars, $tree, $data_filesystem); 12469100c6dSGreg Roach } finally { 1259a3accd7SGreg Roach $pdf = ob_get_clean(); 12669100c6dSGreg Roach } 1279a3accd7SGreg Roach $this->assertStringStartsWith('%PDF', $pdf); 1289a3accd7SGreg Roach $this->assertStringEndsWith("%%EOF\n", $pdf); 1293763c3f2SGreg Roach } 1303763c3f2SGreg Roach} 131