ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilXlsFoParserTest Class Reference
+ Inheritance diagram for ilXlsFoParserTest:
+ Collaboration diagram for ilXlsFoParserTest:

Public Member Functions

 testParseWithNonCustomPageFormatting ()
 
 testParseButXmlCheckerFindsAnError ()
 
 testParseWithCustomPageFormatting ()
 
 testCommasWillBeConvertedToPointInDecimalSepartor ()
 
 testTransformingParagraphsWithNoTextAndNoChildrenResultsInNonBreakingSpaceXslFoBlock (array $form_data, string $fo)
 
 testTransformingParagraphsWithTextOrChildrenResultsNotInNonBreakingSpaceXslFoBlock (array $form_data, string $fo)
 

Static Public Member Functions

static nonBreakingSpaceIsAddedDataProvider ()
 
static noNonBreakingSpaceIsAddedDataProvider ()
 

Private Member Functions

 verifyFoGeneratedFromXhtml (array $form_data, string $fo)
 
 normalizeXml (string $xml)
 

Additional Inherited Members

- Protected Member Functions inherited from ilCertificateBaseTestCase
 setUp ()
 
 tearDown ()
 
 assertDoesNotThrow (callable $cb, string $message='')
 
 assertThrows (callable $cb, ?string $expected_class=null, ?string $expected_message=null)
 @template T of Throwable More...
 
 setGlobalVariable (string $name, mixed $value)
 
- Protected Attributes inherited from ilCertificateBaseTestCase
Container $dic
 

Detailed Description

Definition at line 23 of file ilXlsFoParserTest.php.

Member Function Documentation

◆ nonBreakingSpaceIsAddedDataProvider()

static ilXlsFoParserTest::nonBreakingSpaceIsAddedDataProvider ( )
static

Definition at line 438 of file ilXlsFoParserTest.php.

438 : Generator
439 {
440 $expected_fo_with_centered_block = <<<EOT
441<?xml version="1.0"?>
442<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" font-family="rpc_pdf_font">
443 <fo:layout-master-set>
444 <fo:simple-page-master master-name="ILIAS_certificate" page-height="297mm" page-width="210mm">
445 <fo:region-body margin="1cm 2cm 3cm 4cm"/>
446 <fo:region-before region-name="background-image" extent="0"/>
447 </fo:simple-page-master>
448 </fo:layout-master-set>
449 <fo:page-sequence master-reference="ILIAS_certificate">
450 <fo:static-content flow-name="background-image">
451 <fo:block-container absolute-position="absolute" top="0cm" left="0cm" z-index="0">
452 <fo:block>
453 <fo:external-graphic src="url([BACKGROUND_IMAGE])" content-height="297mm" content-width="210mm"/>
454 </fo:block>
455 </fo:block-container>
456 </fo:static-content>
457 <fo:flow flow-name="xsl-region-body">
458 <fo:block>
459 <fo:block text-align="center">&#160;</fo:block>
460 </fo:block>
461 </fo:flow>
462 </fo:page-sequence>
463</fo:root>
464EOT;
465
466 yield 'Centered Paragraph' => [
467 [
468 'certificate_text' => '<p style="text-align: center;"></p>',
469 'margin_body' => [
470 'top' => '1cm',
471 'right' => '2cm',
472 'bottom' => '3cm',
473 'left' => '4cm'
474 ],
475 'pageformat' => 'custom',
476 'pagewidth' => '210mm',
477 'pageheight' => '297mm'
478 ],
479 $expected_fo_with_centered_block
480 ];
481
482 $expected_fo_with_centered_block = <<<EOT
483<?xml version="1.0"?>
484<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" font-family="rpc_pdf_font">
485 <fo:layout-master-set>
486 <fo:simple-page-master master-name="ILIAS_certificate" page-height="297mm" page-width="210mm">
487 <fo:region-body margin="1cm 2cm 3cm 4cm"/>
488 <fo:region-before region-name="background-image" extent="0"/>
489 </fo:simple-page-master>
490 </fo:layout-master-set>
491 <fo:page-sequence master-reference="ILIAS_certificate">
492 <fo:static-content flow-name="background-image">
493 <fo:block-container absolute-position="absolute" top="0cm" left="0cm" z-index="0">
494 <fo:block>
495 <fo:external-graphic src="url([BACKGROUND_IMAGE])" content-height="297mm" content-width="210mm"/>
496 </fo:block>
497 </fo:block-container>
498 </fo:static-content>
499 <fo:flow flow-name="xsl-region-body">
500 <fo:block>
501 <fo:block>&#160;</fo:block>
502 </fo:block>
503 </fo:flow>
504 </fo:page-sequence>
505</fo:root>
506EOT;
507
508 yield 'Empty paragraph' => [
509 [
510 'certificate_text' => '<p></p>',
511 'margin_body' => [
512 'top' => '1cm',
513 'right' => '2cm',
514 'bottom' => '3cm',
515 'left' => '4cm'
516 ],
517 'pageformat' => 'custom',
518 'pagewidth' => '210mm',
519 'pageheight' => '297mm'
520 ],
521 $expected_fo_with_centered_block
522 ];
523 }

References ILIAS\UI\examples\MainControls\SystemInfo\simple().

+ Here is the call graph for this function:

◆ noNonBreakingSpaceIsAddedDataProvider()

static ilXlsFoParserTest::noNonBreakingSpaceIsAddedDataProvider ( )
static

Definition at line 536 of file ilXlsFoParserTest.php.

536 : Generator
537 {
538 $expected_fo_with_centered_block = <<<EOT
539<?xml version="1.0"?>
540<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" font-family="rpc_pdf_font">
541 <fo:layout-master-set>
542 <fo:simple-page-master master-name="ILIAS_certificate" page-height="297mm" page-width="210mm">
543 <fo:region-body margin="1cm 2cm 3cm 4cm"/>
544 <fo:region-before region-name="background-image" extent="0"/>
545 </fo:simple-page-master>
546 </fo:layout-master-set>
547 <fo:page-sequence master-reference="ILIAS_certificate">
548 <fo:static-content flow-name="background-image">
549 <fo:block-container absolute-position="absolute" top="0cm" left="0cm" z-index="0">
550 <fo:block>
551 <fo:external-graphic src="url([BACKGROUND_IMAGE])" content-height="297mm" content-width="210mm"/>
552 </fo:block>
553 </fo:block-container>
554 </fo:static-content>
555 <fo:flow flow-name="xsl-region-body">
556 <fo:block>
557 <fo:block>[USER_FULLNAME]</fo:block>
558 </fo:block>
559 </fo:flow>
560 </fo:page-sequence>
561</fo:root>
562EOT;
563
564 yield 'Paragraph with Text' => [
565 [
566 'certificate_text' => '<p>[USER_FULLNAME]</p>',
567 'margin_body' => [
568 'top' => '1cm',
569 'right' => '2cm',
570 'bottom' => '3cm',
571 'left' => '4cm'
572 ],
573 'pageformat' => 'custom',
574 'pagewidth' => '210mm',
575 'pageheight' => '297mm'
576 ],
577 $expected_fo_with_centered_block
578 ];
579
580 $expected_fo_with_centered_block = <<<EOT
581<?xml version="1.0"?>
582<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" font-family="rpc_pdf_font">
583 <fo:layout-master-set>
584 <fo:simple-page-master master-name="ILIAS_certificate" page-height="297mm" page-width="210mm">
585 <fo:region-body margin="1cm 2cm 3cm 4cm"/>
586 <fo:region-before region-name="background-image" extent="0"/>
587 </fo:simple-page-master>
588 </fo:layout-master-set>
589 <fo:page-sequence master-reference="ILIAS_certificate">
590 <fo:static-content flow-name="background-image">
591 <fo:block-container absolute-position="absolute" top="0cm" left="0cm" z-index="0">
592 <fo:block>
593 <fo:external-graphic src="url([BACKGROUND_IMAGE])" content-height="297mm" content-width="210mm"/>
594 </fo:block>
595 </fo:block-container>
596 </fo:static-content>
597 <fo:flow flow-name="xsl-region-body">
598 <fo:block>
599 <fo:block><fo:inline font-size="24pt">[USER_FULLNAME]</fo:inline></fo:block>
600 </fo:block>
601 </fo:flow>
602 </fo:page-sequence>
603</fo:root>
604EOT;
605
606 yield 'Paragraph with Nodes' => [
607 [
608 'certificate_text' => '<p><span style="font-size: 24pt;">[USER_FULLNAME]</span></p>',
609 'margin_body' => [
610 'top' => '1cm',
611 'right' => '2cm',
612 'bottom' => '3cm',
613 'left' => '4cm'
614 ],
615 'pageformat' => 'custom',
616 'pagewidth' => '210mm',
617 'pageheight' => '297mm'
618 ],
619 $expected_fo_with_centered_block
620 ];
621 }

References ILIAS\UI\examples\MainControls\SystemInfo\simple().

+ Here is the call graph for this function:

◆ normalizeXml()

ilXlsFoParserTest::normalizeXml ( string  $xml)
private

Definition at line 73 of file ilXlsFoParserTest.php.

73 : string
74 {
75 $xml = str_replace(["\n", "\r", "\t"], '', $xml);
76 $xml = preg_replace("/>(\s+)</", "><", $xml);
77 $xml = preg_replace('# {2,}#', ' ', $xml);
78 $xml = trim($xml);
79
80 return $xml;
81 }

Referenced by verifyFoGeneratedFromXhtml().

+ Here is the caller graph for this function:

◆ testCommasWillBeConvertedToPointInDecimalSepartor()

ilXlsFoParserTest::testCommasWillBeConvertedToPointInDecimalSepartor ( )

Definition at line 343 of file ilXlsFoParserTest.php.

343 : void
344 {
345 $formData = [
346 'certificate_text' => '<xml> Some Context </xml>',
347 'margin_body' => [
348 'top' => '1cm',
349 'right' => '2cm',
350 'bottom' => '3cm',
351 'left' => '4cm'
352 ],
353 'pageformat' => 'custom',
354 'pagewidth' => '210mm',
355 'pageheight' => '297mm'
356 ];
357
358 $settings = $this->getMockBuilder(ilSetting::class)
359 ->disableOriginalConstructor()
360 ->getMock();
361
362 $settings->method('get')
363 ->willReturn('Something');
364
365 $pageFormats = $this->getMockBuilder(ilPageFormats::class)
366 ->disableOriginalConstructor()
367 ->getMock();
368
369 $pageFormats->method('fetchPageFormats')
370 ->willReturn([
371 'a4' => [
372 'name' => 'A4',
373 'value' => 'a4',
374 'width' => '21,0mm',
375 'height' => '29,7mm'
376 ],
377 ]);
378
379 $xmlChecker = new ilXMLChecker(new ILIAS\Data\Factory());
380
381 $utilHelper = $this->getMockBuilder(ilCertificateUtilHelper::class)
382 ->disableOriginalConstructor()
383 ->getMock();
384
385 $utilHelper->method('stripSlashes')
386 ->willReturnOnConsecutiveCalls(
387 '29,7mm',
388 '21,0mm',
389 '1cm',
390 '2cm',
391 '3cm',
392 '4cm'
393 );
394
395 $xlstProcess = $this->getMockBuilder(ilCertificateXlstProcess::class)
396 ->getMock();
397
398 $xlstProcess->method('process')
399 ->with(
400 [
401 '/_xml' => '<html><body><xml> Some Context </xml></body></html>',
402 '/_xsl' => '<xml>Some XLS Content</xml>'
403 ],
404 [
405 'pageheight' => '29.7mm',
406 'pagewidth' => '21.0mm',
407 'backgroundimage' => '[BACKGROUND_IMAGE]',
408 'marginbody' => '1cm 2cm 3cm 4cm'
409 ]
410 )
411 ->willReturn('Something Processed');
412
413 $language = $this->getMockBuilder(ilLanguage::class)
414 ->disableOriginalConstructor()
415 ->getMock();
416
417 $certificateXlsFileLoader = $this->getMockBuilder(ilCertificateXlsFileLoader::class)
418 ->getMock();
419
420 $certificateXlsFileLoader->method('getXlsCertificateContent')
421 ->willReturn('<xml>Some XLS Content</xml>');
422
423 $xlsFoParser = new ilXlsFoParser(
424 $settings,
425 $pageFormats,
426 $xmlChecker,
427 $utilHelper,
428 $xlstProcess,
429 $language,
430 $certificateXlsFileLoader
431 );
432
433 $output = $xlsFoParser->parse($formData);
434
435 $this->assertSame('Something Processed', $output);
436 }
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.

◆ testParseButXmlCheckerFindsAnError()

ilXlsFoParserTest::testParseButXmlCheckerFindsAnError ( )

Definition at line 176 of file ilXlsFoParserTest.php.

176 : never
177 {
178 $this->expectException(Exception::class);
179
180 $formData = [
181 'certificate_text' => '<xml> Some Context <xml>',
182 'margin_body' => [
183 'top' => '1cm',
184 'right' => '2cm',
185 'bottom' => '3cm',
186 'left' => '4cm'
187 ],
188 'pageformat' => 'custom'
189 ];
190
191 $settings = $this->getMockBuilder(ilSetting::class)
192 ->disableOriginalConstructor()
193 ->getMock();
194
195 $settings->method('get')
196 ->willReturn('Something');
197
198 $pageFormats = $this->getMockBuilder(ilPageFormats::class)
199 ->disableOriginalConstructor()
200 ->getMock();
201
202 $pageFormats->method('fetchPageFormats')
203 ->willReturn([
204 'a4' => [
205 'name' => 'A4',
206 'value' => 'a4',
207 'width' => '210mm',
208 'height' => '297mm'
209 ],
210 ]);
211
212 $xmlChecker = new ilXMLChecker(new ILIAS\Data\Factory());
213
214 $utilHelper = $this->getMockBuilder(ilCertificateUtilHelper::class)
215 ->disableOriginalConstructor()
216 ->getMock();
217
218 $xlstProcess = $this->getMockBuilder(ilCertificateXlstProcess::class)
219 ->getMock();
220
221 $language = $this->getMockBuilder(ilLanguage::class)
222 ->disableOriginalConstructor()
223 ->onlyMethods(['txt'])
224 ->getMock();
225 $language->expects($this->once())->method('txt')->willReturn('certificate_not_well_formed');
226
227 $certificateXlsFileLoader = $this->getMockBuilder(ilCertificateXlsFileLoader::class)
228 ->getMock();
229
230 $certificateXlsFileLoader->method('getXlsCertificateContent')
231 ->willReturn('<xml>Some XLS Content</xml>');
232
233 $xlsFoParser = new ilXlsFoParser(
234 $settings,
235 $pageFormats,
236 $xmlChecker,
237 $utilHelper,
238 $xlstProcess,
239 $language,
240 $certificateXlsFileLoader
241 );
242
243 $xlsFoParser->parse($formData);
244
245 $this->fail();
246 }

◆ testParseWithCustomPageFormatting()

ilXlsFoParserTest::testParseWithCustomPageFormatting ( )

Definition at line 248 of file ilXlsFoParserTest.php.

248 : void
249 {
250 $formData = [
251 'certificate_text' => '<xml> Some Context </xml>',
252 'margin_body' => [
253 'top' => '1cm',
254 'right' => '2cm',
255 'bottom' => '3cm',
256 'left' => '4cm'
257 ],
258 'pageformat' => 'custom',
259 'pagewidth' => '210mm',
260 'pageheight' => '297mm'
261 ];
262
263 $settings = $this->getMockBuilder(ilSetting::class)
264 ->disableOriginalConstructor()
265 ->getMock();
266
267 $settings->method('get')
268 ->willReturn('Something');
269
270 $pageFormats = $this->getMockBuilder(ilPageFormats::class)
271 ->disableOriginalConstructor()
272 ->getMock();
273
274 $pageFormats->method('fetchPageFormats')
275 ->willReturn([
276 'a4' => [
277 'name' => 'A4',
278 'value' => 'a4',
279 'width' => '210mm',
280 'height' => '297mm'
281 ],
282 ]);
283
284 $xmlChecker = new ilXMLChecker(new ILIAS\Data\Factory());
285
286 $utilHelper = $this->getMockBuilder(ilCertificateUtilHelper::class)
287 ->disableOriginalConstructor()
288 ->getMock();
289
290 $utilHelper->method('stripSlashes')
291 ->willReturnOnConsecutiveCalls(
292 '297mm',
293 '210mm',
294 '1cm',
295 '2cm',
296 '3cm',
297 '4cm'
298 );
299
300 $xlstProcess = $this->getMockBuilder(ilCertificateXlstProcess::class)
301 ->getMock();
302
303 $xlstProcess->method('process')
304 ->with(
305 [
306 '/_xml' => '<html><body><xml> Some Context </xml></body></html>',
307 '/_xsl' => '<xml>Some XLS Content</xml>'
308 ],
309 [
310 'pageheight' => '297mm',
311 'pagewidth' => '210mm',
312 'backgroundimage' => '[BACKGROUND_IMAGE]',
313 'marginbody' => '1cm 2cm 3cm 4cm'
314 ]
315 )
316 ->willReturn('Something Processed');
317
318 $language = $this->getMockBuilder(ilLanguage::class)
319 ->disableOriginalConstructor()
320 ->getMock();
321
322 $certificateXlsFileLoader = $this->getMockBuilder(ilCertificateXlsFileLoader::class)
323 ->getMock();
324
325 $certificateXlsFileLoader->method('getXlsCertificateContent')
326 ->willReturn('<xml>Some XLS Content</xml>');
327
328 $xlsFoParser = new ilXlsFoParser(
329 $settings,
330 $pageFormats,
331 $xmlChecker,
332 $utilHelper,
333 $xlstProcess,
334 $language,
335 $certificateXlsFileLoader
336 );
337
338 $output = $xlsFoParser->parse($formData);
339
340 $this->assertSame('Something Processed', $output);
341 }

◆ testParseWithNonCustomPageFormatting()

ilXlsFoParserTest::testParseWithNonCustomPageFormatting ( )

Definition at line 83 of file ilXlsFoParserTest.php.

83 : void
84 {
85 $formData = [
86 'certificate_text' => '<xml> Some Context </xml>',
87 'margin_body' => [
88 'top' => '1cm',
89 'right' => '2cm',
90 'bottom' => '3cm',
91 'left' => '4cm'
92 ],
93 'pageformat' => 'a4'
94 ];
95
96 $settings = $this->getMockBuilder(ilSetting::class)
97 ->disableOriginalConstructor()
98 ->getMock();
99
100 $settings->method('get')
101 ->willReturn('Something');
102
103 $pageFormats = $this->getMockBuilder(ilPageFormats::class)
104 ->disableOriginalConstructor()
105 ->getMock();
106
107 $pageFormats->method('fetchPageFormats')
108 ->willReturn([
109 'a4' => [
110 'name' => 'A4',
111 'value' => 'a4',
112 'width' => '210mm',
113 'height' => '297mm'
114 ],
115 ]);
116
117 $xmlChecker = new ilXMLChecker(new ILIAS\Data\Factory());
118
119 $utilHelper = $this->getMockBuilder(ilCertificateUtilHelper::class)
120 ->disableOriginalConstructor()
121 ->getMock();
122
123 $utilHelper->method('stripSlashes')
124 ->willReturnOnConsecutiveCalls(
125 '297mm',
126 '210mm',
127 '1cm',
128 '2cm',
129 '3cm',
130 '4cm'
131 );
132
133 $xlstProcess = $this->getMockBuilder(ilCertificateXlstProcess::class)
134 ->getMock();
135
136 $xlstProcess->method('process')
137 ->with(
138 [
139 '/_xml' => '<html><body><xml> Some Context </xml></body></html>',
140 '/_xsl' => '<xml>Some XLS Content</xml>'
141 ],
142 [
143 'pageheight' => '297mm',
144 'pagewidth' => '210mm',
145 'backgroundimage' => '[BACKGROUND_IMAGE]',
146 'marginbody' => '1cm 2cm 3cm 4cm'
147 ]
148 )
149 ->willReturn('Something Processed');
150
151 $language = $this->getMockBuilder(ilLanguage::class)
152 ->disableOriginalConstructor()
153 ->getMock();
154
155 $certificateXlsFileLoader = $this->getMockBuilder(ilCertificateXlsFileLoader::class)
156 ->getMock();
157
158 $certificateXlsFileLoader->method('getXlsCertificateContent')
159 ->willReturn('<xml>Some XLS Content</xml>');
160
161 $xlsFoParser = new ilXlsFoParser(
162 $settings,
163 $pageFormats,
164 $xmlChecker,
165 $utilHelper,
166 $xlstProcess,
167 $language,
168 $certificateXlsFileLoader
169 );
170
171 $output = $xlsFoParser->parse($formData);
172
173 $this->assertSame('Something Processed', $output);
174 }

◆ testTransformingParagraphsWithNoTextAndNoChildrenResultsInNonBreakingSpaceXslFoBlock()

ilXlsFoParserTest::testTransformingParagraphsWithNoTextAndNoChildrenResultsInNonBreakingSpaceXslFoBlock ( array  $form_data,
string  $fo 
)
Parameters
array{"certificate_text"string, "pageformat": string, "pagewidth"?: string, "pageheight"?: string, "margin_body": array{"top": string, "right": string, "bottom": string, "left": string}} $form_data

Definition at line 529 of file ilXlsFoParserTest.php.

532 : void {
533 $this->verifyFoGeneratedFromXhtml($form_data, $fo);
534 }
verifyFoGeneratedFromXhtml(array $form_data, string $fo)

◆ testTransformingParagraphsWithTextOrChildrenResultsNotInNonBreakingSpaceXslFoBlock()

ilXlsFoParserTest::testTransformingParagraphsWithTextOrChildrenResultsNotInNonBreakingSpaceXslFoBlock ( array  $form_data,
string  $fo 
)
Parameters
array{"certificate_text"string, "pageformat": string, "pagewidth"?: string, "pageheight"?: string, "margin_body": array{"top": string, "right": string, "bottom": string, "left": string}} $form_data

Definition at line 627 of file ilXlsFoParserTest.php.

630 : void {
631 $this->verifyFoGeneratedFromXhtml($form_data, $fo);
632 }

◆ verifyFoGeneratedFromXhtml()

ilXlsFoParserTest::verifyFoGeneratedFromXhtml ( array  $form_data,
string  $fo 
)
private
Parameters
array{"certificate_text"string, "pageformat": string, "pagewidth"?: string, "pageheight"?: string, "margin_body": array{"top": string, "right": string, "bottom": string, "left": string}} $form_data

Definition at line 28 of file ilXlsFoParserTest.php.

28 : void
29 {
30 $settings = $this->getMockBuilder(ilSetting::class)
31 ->disableOriginalConstructor()
32 ->getMock();
33 $settings->method('get')->willReturnArgument(0);
34
35 $language = $this->getMockBuilder(ilLanguage::class)->disableOriginalConstructor()->onlyMethods(
36 ['txt']
37 )->getMock();
38 $language->method('txt')->willReturnArgument(0);
39
40 $page_formats = new ilPageFormats($language);
41
42 $util_helper = $this->getMockBuilder(ilCertificateUtilHelper::class)
43 ->disableOriginalConstructor()
44 ->getMock();
45
46 $util_helper->method('stripSlashes')
47 ->willReturnArgument(0);
48
49 $xmlChecker = new ilXMLChecker(new ILIAS\Data\Factory());
50 $xslt_process = new ilCertificateXlstProcess();
51
52 $language = $this->getMockBuilder(ilLanguage::class)
53 ->disableOriginalConstructor()
54 ->getMock();
55
56 $xsl_loader = new ilCertificateXlsFileLoader();
57
58 $xlsFoParser = new ilXlsFoParser(
59 $settings,
60 $page_formats,
61 $xmlChecker,
62 $util_helper,
63 $xslt_process,
64 $language,
65 $xsl_loader
66 );
67
68 $output = $xlsFoParser->parse($form_data);
69
70 $this->assertSame($this->normalizeXml($fo), $this->normalizeXml($output));
71 }
normalizeXml(string $xml)

References normalizeXml().

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: