ILIAS  release_8 Revision v8.24
ilServicesXmlTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
5/******************************************************************************
6 *
7 * This file is part of ILIAS, a powerful learning management system.
8 *
9 * ILIAS is licensed with the GPL-3.0, you should have received a copy
10 * of said license along with the source code.
11 *
12 * If this is not the case or you just want to try ILIAS, you'll find
13 * us at:
14 * https://www.ilias.de
15 * https://github.com/ILIAS-eLearning
16 *
17 *****************************************************************************/
18
19use PHPUnit\Framework\TestCase;
21
22class ilServicesXmlTest extends TestCase
23{
24 public function testHeader(): void
25 {
26 $writer = new ilXmlWriter();
27 $writer->xmlHeader();
28
29 $this->assertEquals(
30 $this->brutallyTrim("<?xml version=\"1.0\" encoding=\"utf-8\"?><!--Generated by ILIAS XmlWriter-->"),
31 $this->brutallyTrim($writer->xmlDumpMem())
32 );
33 }
34
35 public function testStartEndTag(): void
36 {
37 $writer = new ilXmlWriter();
38 $writer->xmlStartTag('lorem');
39 $writer->xmlEndTag('lorem');
40 $this->assertEquals(
41 $this->brutallyTrim("<lorem></lorem>"),
42 $this->brutallyTrim($writer->xmlDumpMem())
43 );
44 }
45
46 public function testElements(): void
47 {
48 $writer = new ilXmlWriter();
49 $writer->xmlStartTag('lorem');
50 $writer->xmlElement('ipsum', ['attr1' => 1], 'data1');
51 $writer->xmlElement('dolor', ['attr2' => 2, 'attr3' => 3], 'data2');
52 $writer->xmlEndTag('lorem');
53 $this->assertEquals(
54 $this->brutallyTrim(
55 "<lorem><ipsum attr1=\"1\"> data1</ipsum><dolor attr2=\"2\" attr3=\"3\"> data2</dolor></lorem>"
56 ),
57 $this->brutallyTrim($writer->xmlDumpMem())
58 );
59 }
60
61 protected function brutallyTrim(string $string): string
62 {
63 $string = str_replace(["\n", "\r", "\t"], "", $string);
64 $string = preg_replace('# {2,}#', " ", $string);
65 $string = preg_replace("/>(\s+)</", "><", $string);
66 $string = str_replace(" >", ">", $string);
67 $string = str_replace(" <", "<", $string);
68 return trim($string);
69 }
70}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:32
brutallyTrim(string $string)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...