ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilServicesXmlTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use PHPUnit\Framework\TestCase;
23
24class ilServicesXmlTest extends TestCase
25{
26 public function testHeader(): void
27 {
28 $writer = new ilXmlWriter();
29 $writer->xmlHeader();
30
31 $this->assertEquals(
32 $this->brutallyTrim("<?xml version=\"1.0\" encoding=\"utf-8\"?><!--Generated by ILIAS XmlWriter-->"),
33 $this->brutallyTrim($writer->xmlDumpMem())
34 );
35 }
36
37 public function testStartEndTag(): void
38 {
39 $writer = new ilXmlWriter();
40 $writer->xmlStartTag('lorem');
41 $writer->xmlEndTag('lorem');
42 $this->assertEquals(
43 $this->brutallyTrim("<lorem></lorem>"),
44 $this->brutallyTrim($writer->xmlDumpMem())
45 );
46 }
47
48 public function testElements(): void
49 {
50 $writer = new ilXmlWriter();
51 $writer->xmlStartTag('lorem');
52 $writer->xmlElement('ipsum', ['attr1' => 1], 'data1');
53 $writer->xmlElement('dolor', ['attr2' => 2, 'attr3' => 3], 'data2');
54 $writer->xmlEndTag('lorem');
55 $this->assertEquals(
56 $this->brutallyTrim(
57 "<lorem><ipsum attr1=\"1\"> data1</ipsum><dolor attr2=\"2\" attr3=\"3\"> data2</dolor></lorem>"
58 ),
59 $this->brutallyTrim($writer->xmlDumpMem())
60 );
61 }
62
63 protected function brutallyTrim(string $string): string
64 {
65 $string = str_replace(["\n", "\r", "\t"], "", $string);
66 $string = preg_replace('# {2,}#', " ", $string);
67 $string = preg_replace("/>(\s+)</", "><", $string);
68 $string = str_replace(" >", ">", $string);
69 $string = str_replace(" <", "<", $string);
70 return trim($string);
71 }
72}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
brutallyTrim(string $string)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...