ILIAS  trunk Revision v12.0_alpha-1541-g23eaa5e013d
DocumentProcessorBaseTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use PHPUnit\Framework\TestCase;
24use PHPUnit\Framework\Attributes\Test;
25use PHPUnit\Framework\Attributes\Small;
27
28#[Small]
29final class DocumentProcessorBaseTest extends TestCase
30{
32 {
33 return new class () extends DocumentProcessorBase {
34 public function processMountInstructions(string $a_raw_mount_instructions): array
35 {
36 return [];
37 }
38 };
39 }
40
41 #[Test]
43 {
44 $instructions = 'hello world';
45 $doc_processor = $this->createDocumentProcessorBaseObject();
46
47 $parsed_instructions = $doc_processor->parseInstructionsToAssocArray($instructions);
48
49 $this->assertEquals($instructions, $parsed_instructions[0]);
50 }
51
52 #[Test]
54 {
55 $instructions = 'This is a start [tag] with no end tag';
56 $doc_processor = $this->createDocumentProcessorBaseObject();
57
58 $parsed_instructions = $doc_processor->parseInstructionsToAssocArray($instructions);
59
60 $this->assertEquals($instructions, $parsed_instructions[0]);
61 }
62
63 #[Test]
65 {
66 $instructions = 'There is no start tag but an end [/tag] in the string';
67 $doc_processor = $this->createDocumentProcessorBaseObject();
68
69 $parsed_instructions = $doc_processor->parseInstructionsToAssocArray($instructions);
70
71 $this->assertEquals($instructions, $parsed_instructions[0]);
72 }
73
74 #[Test]
76 {
77 $instruction_text = 'This are the mount Instructions';
78 $tag_title = 'tag';
79 $start_tag = "[$tag_title]";
80 $end_tag = "[/$tag_title]";
81 $instructions = $start_tag . $instruction_text . $end_tag;
82 $doc_processor = $this->createDocumentProcessorBaseObject();
83
84 $parsed_instructions = $doc_processor->parseInstructionsToAssocArray($instructions);
85
86 $this->assertEquals($instruction_text, $parsed_instructions[$tag_title]);
87 }
88
89 #[Test]
91 {
92 $instruction_text = 'This are the mount Instructions';
93 $tag_title = 'tag with spaces';
94 $start_tag = "[$tag_title]";
95 $end_tag = "[/$tag_title]";
96 $instructions = $start_tag . $instruction_text . $end_tag;
97 $doc_processor = $this->createDocumentProcessorBaseObject();
98
99 $parsed_instructions = $doc_processor->parseInstructionsToAssocArray($instructions);
100
101 $this->assertEquals($instruction_text, $parsed_instructions[$tag_title]);
102 }
103
104 #[Test]
106 {
107 $instruction_text = 'This are the mount Instructions';
108 $tag_title = 'tag_w!th$pecial"chars?';
109 $start_tag = "[$tag_title]";
110 $end_tag = "[/$tag_title]";
111 $instructions = $start_tag . $instruction_text . $end_tag;
112 $doc_processor = $this->createDocumentProcessorBaseObject();
113
114 $parsed_instructions = $doc_processor->parseInstructionsToAssocArray($instructions);
115
116 $this->assertEquals($instruction_text, $parsed_instructions[$tag_title]);
117 }
118
119 #[Test]
121 ): void {
122 $instruction_text = 'This are the mount Instructions';
123 $tag_title = 'tag';
124 $start_tag = "[$tag_title]";
125 $end_tag = "[/$tag_title]";
126 $instructions = 'This will be cut off' . $start_tag . $instruction_text . $end_tag . 'and this of will be cut off as well';
127 $doc_processor = $this->createDocumentProcessorBaseObject();
128
129 $parsed_instructions = $doc_processor->parseInstructionsToAssocArray($instructions);
130
131 $this->assertEquals($instruction_text, $parsed_instructions[$tag_title]);
132 }
133
134 #[Test]
136 {
137 $instruction_text = 'This are the mount Instructions';
138 $tag_title = 'tag';
139 $start_tag = "[$tag_title]";
140 $end_tag = "[/$tag_title]";
141 $instructions = 'Here is a [placeholder] hidden before the start tag' . $start_tag . $instruction_text . $end_tag;
142 $doc_processor = $this->createDocumentProcessorBaseObject();
143
144 $parsed_instructions = $doc_processor->parseInstructionsToAssocArray($instructions);
145
146 $this->assertEquals($instruction_text, $parsed_instructions[$tag_title]);
147 }
148
149 #[Test]
151 {
152 $instruction_text1 = 'This are the first instructions';
153 $instruction_text2 = 'This are the second instructions\'';
154 $tag_title1 = 'tag1';
155 $start_tag1 = "[$tag_title1]";
156 $end_tag1 = "[/$tag_title1]";
157 $tag_title2 = 'tag2';
158 $start_tag2 = "[$tag_title2]";
159 $end_tag2 = "[/$tag_title2]";
160 $instructions = $start_tag1 . $instruction_text1 . $end_tag1 . $start_tag2 . $instruction_text2 . $end_tag2;
161 $doc_processor = $this->createDocumentProcessorBaseObject();
162
163 $parsed_instructions = $doc_processor->parseInstructionsToAssocArray($instructions);
164
165 $this->assertEquals($instruction_text1, $parsed_instructions[$tag_title1]);
166 $this->assertEquals($instruction_text2, $parsed_instructions[$tag_title2]);
167 }
168}