ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
TransformUtilTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use PHPUnit\Framework\TestCase;
25
29class TransformUtilTest extends TestCase
30{
32
33 protected function setUp(): void
34 {
35 parent::setUp();
36 $this->util = new TransformUtil();
37 }
38
39 public function testGetPosOfPlaceholder(): void
40 {
41 $html = "...{{{{{TestTag;1}}}}}...";
42 $pos = $this->util->getPosOfPlaceholder($html, "TestTag");
43 $this->assertEquals(
44 3,
45 $pos
46 );
47
48 $pos = $this->util->getPosOfPlaceholder($html, "TestMissing");
49 $this->assertEquals(
50 null,
51 $pos
52 );
53 }
54
55 public function testGetEndPosOfPlaceholder(): void
56 {
57 $html = "...{{{{{TestTag;1}}}}}...";
58 $pos = $this->util->getEndPosOfPlaceholder($html);
59 $this->assertEquals(
60 22,
61 $pos
62 );
63 }
64
65 public function testGetPlaceholderParamString(): void
66 {
67 $html = "...{{{{{TestTag;1;ab;cd}}}}}...";
68 $ph_string = $this->util->getPlaceholderParamString($html, "TestTag");
69 $this->assertEquals(
70 "TestTag;1;ab;cd",
71 $ph_string
72 );
73 }
74
75 public function testGetPlaceholderParams(): void
76 {
77 $html = "...{{{{{TestTag;1;ab;cd}}}}}...";
78 $ph_string = $this->util->getPlaceholderParams($html, "TestTag");
79 $this->assertEquals(
80 ["TestTag", "1", "ab", "cd"],
81 $ph_string
82 );
83 }
84
85 public function testGetInnerContentOfPlaceholders(): void
86 {
87 $html = "...{{{{{TestStart;1;ab;cd}}}}}The inner content.{{{{{TestEnd;1;ab;cd}}}}}";
88 $ph_string = $this->util->getInnerContentOfPlaceholders($html, "TestStart", "TestEnd");
89 $this->assertEquals(
90 "The inner content.",
91 $ph_string
92 );
93 }
94
96 {
97 $html = "...{{{{{TestStart;1;ab;cd}}}}}The inner content.{{{{{TestEnd;1;ab;cd}}}}} abc";
98 $ph_string = $this->util->replaceInnerContentAndPlaceholders($html, "TestStart", "TestEnd", "The new content.");
99 $this->assertEquals(
100 "...The new content. abc",
101 $ph_string
102 );
103 }
104
105}