19declare(strict_types=1);
21use PHPUnit\Framework\Attributes\DataProvider;
22use PHPUnit\Framework\MockObject\Stub;
31 $output = $this->createXlsFoParser()->parse($form_data);
39 $settings = $this->createStub(ilSetting::class);
40 $settings->method(
'get')->willReturnArgument(0);
43 $language = $this->getStubBuilder(ilLanguage::class)->disableOriginalConstructor()->onlyMethods(
46 $language->method(
'txt')->willReturnArgument(0);
51 $util_helper = $this->createStub(ilCertificateUtilHelper::class);
53 $util_helper->method(
'stripSlashes')
54 ->willReturnArgument(0);
60 $language = $this->createStub(ilLanguage::class);
80 $output = $this->createXlsFoParser()->parse([
81 'certificate_text' => $certificate_text,
88 'pageformat' =>
'custom',
89 'pagewidth' =>
'297mm',
90 'pageheight' =>
'210mm'
93 $document =
new DOMDocument();
94 $document->loadXML($output);
95 $xpath =
new DOMXPath($document);
96 $xpath->registerNamespace(
'fo',
'http://www.w3.org/1999/XSL/Format');
99 foreach ($xpath->query(
'//fo:flow/fo:block/fo:block') as $block) {
100 $alignments[] = $block->getAttribute(
'text-align');
108 $xml = str_replace([
"\n",
"\r",
"\t"],
'', $xml);
109 $xml = preg_replace(
"/>(\s+)</",
"><", $xml);
110 $xml = preg_replace(
'# {2,}#',
' ', $xml);
116 public function testParseWithNonCustomPageFormatting(): void
119 'certificate_text' =>
'<xml> Some Context </xml>',
130 $settings = $this->createStub(ilSetting::class);
133 ->willReturn(
'Something');
136 $pageFormats = $this->createStub(ilPageFormats::class);
138 $pageFormats->method(
'fetchPageFormats')
151 $utilHelper = $this->createStub(ilCertificateUtilHelper::class);
153 $utilHelper->method(
'stripSlashes')
154 ->willReturnOnConsecutiveCalls(
163 $xlstProcess = $this->getMockBuilder(ilCertificateXlstProcess::class)
167 ->expects($this->once())
171 '/_xml' =>
'<html><body><xml> Some Context </xml></body></html>',
172 '/_xsl' =>
'<xml>Some XLS Content</xml>'
175 'pageheight' =>
'297mm',
176 'pagewidth' =>
'210mm',
177 'backgroundimage' =>
'[BACKGROUND_IMAGE]',
178 'marginbody' =>
'1cm 2cm 3cm 4cm'
181 ->willReturn(
'Something Processed');
184 $language = $this->createStub(ilLanguage::class);
187 $certificateXlsFileLoader = $this->createStub(ilCertificateXlsFileLoader::class);
189 $certificateXlsFileLoader->method(
'getXlsCertificateContent')
190 ->willReturn(
'<xml>Some XLS Content</xml>');
199 $certificateXlsFileLoader
202 $output = $xlsFoParser->parse($formData);
204 $this->assertSame(
'Something Processed', $output);
207 public function testParseButXmlCheckerFindsAnError(): never
209 $this->expectException(Exception::class);
212 'certificate_text' =>
'<xml> Some Context <xml>',
219 'pageformat' =>
'custom'
223 $settings = $this->createStub(ilSetting::class);
226 ->willReturn(
'Something');
229 $pageFormats = $this->createStub(ilPageFormats::class);
231 $pageFormats->method(
'fetchPageFormats')
244 $utilHelper = $this->createStub(ilCertificateUtilHelper::class);
247 $xlstProcess = $this->createStub(ilCertificateXlstProcess::class);
249 $language = $this->getMockBuilder(ilLanguage::class)
250 ->disableOriginalConstructor()
251 ->onlyMethods([
'txt'])
253 $language->expects($this->once())->method(
'txt')->willReturn(
'certificate_not_well_formed');
256 $certificateXlsFileLoader = $this->createStub(ilCertificateXlsFileLoader::class);
258 $certificateXlsFileLoader->method(
'getXlsCertificateContent')
259 ->willReturn(
'<xml>Some XLS Content</xml>');
268 $certificateXlsFileLoader
271 $xlsFoParser->parse($formData);
276 public function testParseWithCustomPageFormatting(): void
279 'certificate_text' =>
'<xml> Some Context </xml>',
286 'pageformat' =>
'custom',
287 'pagewidth' =>
'210mm',
288 'pageheight' =>
'297mm'
292 $settings = $this->createStub(ilSetting::class);
295 ->willReturn(
'Something');
298 $pageFormats = $this->createStub(ilPageFormats::class);
300 $pageFormats->method(
'fetchPageFormats')
313 $utilHelper = $this->createStub(ilCertificateUtilHelper::class);
315 $utilHelper->method(
'stripSlashes')
316 ->willReturnOnConsecutiveCalls(
325 $xlstProcess = $this->getMockBuilder(ilCertificateXlstProcess::class)
329 ->expects($this->once())
333 '/_xml' =>
'<html><body><xml> Some Context </xml></body></html>',
334 '/_xsl' =>
'<xml>Some XLS Content</xml>'
337 'pageheight' =>
'297mm',
338 'pagewidth' =>
'210mm',
339 'backgroundimage' =>
'[BACKGROUND_IMAGE]',
340 'marginbody' =>
'1cm 2cm 3cm 4cm'
343 ->willReturn(
'Something Processed');
346 $language = $this->createStub(ilLanguage::class);
349 $certificateXlsFileLoader = $this->createStub(ilCertificateXlsFileLoader::class);
351 $certificateXlsFileLoader->method(
'getXlsCertificateContent')
352 ->willReturn(
'<xml>Some XLS Content</xml>');
361 $certificateXlsFileLoader
364 $output = $xlsFoParser->parse($formData);
366 $this->assertSame(
'Something Processed', $output);
369 public function testCommasWillBeConvertedToPointInDecimalSepartor(): void
372 'certificate_text' =>
'<xml> Some Context </xml>',
379 'pageformat' =>
'custom',
380 'pagewidth' =>
'210mm',
381 'pageheight' =>
'297mm'
385 $settings = $this->createStub(ilSetting::class);
388 ->willReturn(
'Something');
391 $pageFormats = $this->createStub(ilPageFormats::class);
393 $pageFormats->method(
'fetchPageFormats')
406 $utilHelper = $this->createStub(ilCertificateUtilHelper::class);
408 $utilHelper->method(
'stripSlashes')
409 ->willReturnOnConsecutiveCalls(
418 $xlstProcess = $this->getMockBuilder(ilCertificateXlstProcess::class)
422 ->expects($this->once())
426 '/_xml' =>
'<html><body><xml> Some Context </xml></body></html>',
427 '/_xsl' =>
'<xml>Some XLS Content</xml>'
430 'pageheight' =>
'29.7mm',
431 'pagewidth' =>
'21.0mm',
432 'backgroundimage' =>
'[BACKGROUND_IMAGE]',
433 'marginbody' =>
'1cm 2cm 3cm 4cm'
436 ->willReturn(
'Something Processed');
439 $language = $this->createStub(ilLanguage::class);
442 $certificateXlsFileLoader = $this->createStub(ilCertificateXlsFileLoader::class);
444 $certificateXlsFileLoader->method(
'getXlsCertificateContent')
445 ->willReturn(
'<xml>Some XLS Content</xml>');
454 $certificateXlsFileLoader
457 $output = $xlsFoParser->parse($formData);
459 $this->assertSame(
'Something Processed', $output);
464 $expected_fo_with_centered_block = <<<EOT
466<fo:root xmlns:fo=
"http://www.w3.org/1999/XSL/Format" font-family=
"rpc_pdf_font">
467 <fo:layout-master-
set>
468 <fo:
simple-page-master master-name=
"ILIAS_certificate" page-height=
"297mm" page-width=
"210mm">
469 <fo:region-body margin=
"1cm 2cm 3cm 4cm"/>
470 <fo:region-before region-name=
"background-image" extent=
"0"/>
472 </fo:layout-master-
set>
473 <fo:page-sequence master-reference=
"ILIAS_certificate">
474 <fo:
static-content flow-name=
"background-image">
475 <fo:block-container absolute-position=
"absolute" top=
"0cm" left=
"0cm" z-index=
"0">
477 <fo:external-graphic src=
"url([BACKGROUND_IMAGE])" content-height=
"297mm" content-width=
"210mm"/>
479 </fo:block-container>
481 <fo:flow flow-name=
"xsl-region-body">
483 <fo:block text-align=
"center"> </fo:block>
490 yield
'Centered Paragraph' => [
492 'certificate_text' =>
'<p style="text-align: center;"></p>',
499 'pageformat' =>
'custom',
500 'pagewidth' =>
'210mm',
501 'pageheight' =>
'297mm'
503 $expected_fo_with_centered_block
506 $expected_fo_with_centered_block = <<<EOT
508<fo:root xmlns:fo=
"http://www.w3.org/1999/XSL/Format" font-family=
"rpc_pdf_font">
509 <fo:layout-master-
set>
510 <fo:
simple-page-master master-name=
"ILIAS_certificate" page-height=
"297mm" page-width=
"210mm">
511 <fo:region-body margin=
"1cm 2cm 3cm 4cm"/>
512 <fo:region-before region-name=
"background-image" extent=
"0"/>
514 </fo:layout-master-
set>
515 <fo:page-sequence master-reference=
"ILIAS_certificate">
516 <fo:
static-content flow-name=
"background-image">
517 <fo:block-container absolute-position=
"absolute" top=
"0cm" left=
"0cm" z-index=
"0">
519 <fo:external-graphic src=
"url([BACKGROUND_IMAGE])" content-height=
"297mm" content-width=
"210mm"/>
521 </fo:block-container>
523 <fo:flow flow-name=
"xsl-region-body">
525 <fo:block> </fo:block>
532 yield
'Empty paragraph marked as emptyrow' => [
534 'certificate_text' =>
'<p class="emptyrow"></p>',
541 'pageformat' =>
'custom',
542 'pagewidth' =>
'210mm',
543 'pageheight' =>
'297mm'
545 $expected_fo_with_centered_block
548 yield
'Empty paragraph' => [
550 'certificate_text' =>
'<p></p>',
557 'pageformat' =>
'custom',
558 'pagewidth' =>
'210mm',
559 'pageheight' =>
'297mm'
561 $expected_fo_with_centered_block
568 #[DataProvider('nonBreakingSpaceIsAddedDataProvider')]
578 $expected_fo_with_centered_block = <<<EOT
580<fo:root xmlns:fo=
"http://www.w3.org/1999/XSL/Format" font-family=
"rpc_pdf_font">
581 <fo:layout-master-
set>
582 <fo:
simple-page-master master-name=
"ILIAS_certificate" page-height=
"297mm" page-width=
"210mm">
583 <fo:region-body margin=
"1cm 2cm 3cm 4cm"/>
584 <fo:region-before region-name=
"background-image" extent=
"0"/>
586 </fo:layout-master-
set>
587 <fo:page-sequence master-reference=
"ILIAS_certificate">
588 <fo:
static-content flow-name=
"background-image">
589 <fo:block-container absolute-position=
"absolute" top=
"0cm" left=
"0cm" z-index=
"0">
591 <fo:external-graphic src=
"url([BACKGROUND_IMAGE])" content-height=
"297mm" content-width=
"210mm"/>
593 </fo:block-container>
595 <fo:flow flow-name=
"xsl-region-body">
597 <fo:block>[USER_FULLNAME]</fo:block>
604 yield
'Paragraph with Text' => [
606 'certificate_text' =>
'<p>[USER_FULLNAME]</p>',
613 'pageformat' =>
'custom',
614 'pagewidth' =>
'210mm',
615 'pageheight' =>
'297mm'
617 $expected_fo_with_centered_block
620 $expected_fo_with_centered_block = <<<EOT
622<fo:root xmlns:fo=
"http://www.w3.org/1999/XSL/Format" font-family=
"rpc_pdf_font">
623 <fo:layout-master-
set>
624 <fo:
simple-page-master master-name=
"ILIAS_certificate" page-height=
"297mm" page-width=
"210mm">
625 <fo:region-body margin=
"1cm 2cm 3cm 4cm"/>
626 <fo:region-before region-name=
"background-image" extent=
"0"/>
628 </fo:layout-master-
set>
629 <fo:page-sequence master-reference=
"ILIAS_certificate">
630 <fo:
static-content flow-name=
"background-image">
631 <fo:block-container absolute-position=
"absolute" top=
"0cm" left=
"0cm" z-index=
"0">
633 <fo:external-graphic src=
"url([BACKGROUND_IMAGE])" content-height=
"297mm" content-width=
"210mm"/>
635 </fo:block-container>
637 <fo:flow flow-name=
"xsl-region-body">
639 <fo:block><fo:
inline font-size=
"24pt">[USER_FULLNAME]</fo:
inline></fo:block>
646 yield
'Paragraph with Nodes' => [
648 'certificate_text' =>
'<p><span style="font-size: 24pt;">[USER_FULLNAME]</span></p>',
655 'pageformat' =>
'custom',
656 'pagewidth' =>
'210mm',
657 'pageheight' =>
'297mm'
659 $expected_fo_with_centered_block
666 #[DataProvider('noNonBreakingSpaceIsAddedDataProvider')]
671 $this->verifyFoGeneratedFromXhtml($form_data, $fo);
677 [
'center',
'center',
'left',
'right',
'justify',
'center'],
678 $this->paragraphAlignments(
679 '<p align="left" style="text-align: center;">Confirmation</p>'
680 .
'<p align="left" style="padding-left: 10px; text-align: center;">Line</p>'
681 .
'<p align="center" style="text-align: left;">Left again</p>'
682 .
'<p align="left" style="text-align: right;">Right</p>'
683 .
'<p align="left" style="text-align: justify;">Justified</p>'
684 .
'<p align="center">Legacy center</p>'
691 $fo = $this->createXlsFoParser()->parse([
692 'certificate_text' =>
'<p style="text-align: center;">Confirmation</p><p style="text-align: left;">Line</p>',
699 'pageformat' =>
'custom',
700 'pagewidth' =>
'297mm',
701 'pageheight' =>
'210mm'
706 $this->assertStringNotContainsString(
'align=', $reloaded[
'certificate_text']);
707 $this->assertStringContainsString(
'text-align: center', $reloaded[
'certificate_text']);
708 $this->assertStringContainsString(
'text-align: left', $reloaded[
'certificate_text']);
711 $this->paragraphAlignments($reloaded[
'certificate_text'])
717 $output = $this->createXlsFoParser()->parse([
718 'certificate_text' =>
719 '<p style="text-align: center;"><span style="font-size: 36pt;">Bestätigung</span></p>'
720 .
'<p style="text-align: center;"><span style="font-size: 36pt;"></span></p>'
721 .
'<p style="text-align: center;"><span style="font-size: 36pt;"></span></p>'
722 .
'<p style="text-align: center;"><strong><span style="font-size: 12pt;">Durch dieses Zertifikat wird bestätigt, dass</span></strong></p>'
723 .
'<p style="text-align: center;"><span style="font-size: 12pt;"><strong></strong></span></p>'
724 .
'<p style="text-align: center;"><span style="font-size: 12pt;"><strong>Zertifikats-ID: [CERTIFICATE_ID]</strong></span></p>',
731 'pageformat' =>
'custom',
732 'pagewidth' =>
'297mm',
733 'pageheight' =>
'210mm'
736 $document =
new DOMDocument();
737 $document->loadXML($output);
738 $xpath =
new DOMXPath($document);
739 $xpath->registerNamespace(
'fo',
'http://www.w3.org/1999/XSL/Format');
742 foreach ($xpath->query(
'//fo:flow/fo:block/fo:block') as $block) {
746 $this->assertCount(6, $blocks);
747 foreach ($blocks as $block) {
748 $this->assertNotSame(
'', $block->textContent, $document->saveXML($block));
751 $this->assertSame(
'Bestätigung', $blocks[0]->textContent);
752 $this->assertSame(
"\u{00A0}", $blocks[1]->textContent);
753 $this->assertSame(
"\u{00A0}", $blocks[2]->textContent);
754 $this->assertSame(
'Durch dieses Zertifikat wird bestätigt, dass', $blocks[3]->textContent);
755 $this->assertSame(
"\u{00A0}", $blocks[4]->textContent);
756 $this->assertSame(
'Zertifikats-ID: [CERTIFICATE_ID]', $blocks[5]->textContent);
testTransformingParagraphsWithNoTextAndNoChildrenResultsInNonBreakingSpaceXslFoBlock(array $form_data, string $fo)
static nonBreakingSpaceIsAddedDataProvider()
testParagraphsWithoutDescendantTextKeepANonBreakingSpace()
verifyFoGeneratedFromXhtml(array $form_data, string $fo)
static noNonBreakingSpaceIsAddedDataProvider()
normalizeXml(string $xml)
testCssTextAlignOverridesStaleAlignAttribute()
testStoredCertificateReloadsAlignmentAsCss()
paragraphAlignments(string $certificate_text)
testTransformingParagraphsWithTextOrChildrenResultsNotInNonBreakingSpaceXslFoBlock(array $form_data, string $fo)
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.