ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
assErrorTextTest.php
Go to the documentation of this file.
1<?php
2
27{
28 protected $backupGlobals = false;
29
30 protected function setUp(): void
31 {
32 chdir(__DIR__ . '/../../../../');
33
34 parent::setUp();
35
36 $ilCtrl_mock = $this->createMock('ilCtrl');
37 $ilCtrl_mock->expects($this->any())->method('saveParameter');
38 $ilCtrl_mock->expects($this->any())->method('saveParameterByClass');
39 $this->setGlobalVariable('ilCtrl', $ilCtrl_mock);
40
41 $lng_mock = $this->createMock('ilLanguage', ['txt'], [], '', false);
42 $this->setGlobalVariable('lng', $lng_mock);
43
44 $this->setGlobalVariable('ilias', $this->getIliasMock());
45 $this->setGlobalVariable('ilDB', $this->getDatabaseMock());
46 }
47
48 public function test_instantiateObjectSimple(): void
49 {
50 $instance = new assErrorText();
51
52 $this->assertInstanceOf(assErrorText::class, $instance);
53 }
54
55 public function test_getErrorsFromText(): void
56 {
57 $this->markTestSkipped('Generates warning for some unknown reason.');
58
59 $instance = new assErrorText();
60 $instance->setPointsWrong(-2);
61
62 $errortext = '
63 Eine Kündigung kommt durch zwei ((gleichlautende Willenserklärungen zustande)).
64 Ein Vertrag kommt durch ((drei gleichlaute)) Willenserklärungen zustande.
65 Ein Kaufvertrag an der Kasse im #Supermarkt kommt durch das legen von Ware auf das
66 Kassierband und den Kassiervorgang zustande. Dies nennt man ((konsequentes Handeln.))';
67
68 $expected = [
69 new assAnswerErrorText('gleichlautende Willenserklärungen zustande.', '', 0.0, 6),
70 new assAnswerErrorText('drei gleichlaute', '', 0.0, 13),
71 new assAnswerErrorText('Supermarkt', '', 0.0, 23),
72 new assAnswerErrorText('konsequentes Handeln.', '', 0.0, 40),
73 ];
74
75 $instance->setErrorText($errortext);
76 $instance->parseErrorText();
77 $instance->setErrorsFromParsedErrorText();
78 $actual = $instance->getErrorData();
79
80 $this->assertEquals($expected, $actual);
81 }
82
83 public function test_getErrorsFromText_noMatch(): void
84 {
85 $this->markTestSkipped('Generates warning for some unknown reason.');
86
87 $instance = new assErrorText();
88 $instance->setPointsWrong(-2);
89
90 $errortext = '
91 Eine Kündigung)) kommt durch zwei gleichlautende (Willenserklärungen) zustande.
92 Ein Vertrag kommt durch (drei gleichlaute) Willenserklärungen zustande.
93 Ein Kaufvertrag an der Kasse im Supermarkt [kommt] durch das legen von Ware auf das
94 Kassierband und den [[Kassiervorgang]] zustande. Dies nennt man *konsequentes Handeln.';
95
96 $expected = [];
97
98 $instance->setErrorText($errortext);
99 $instance->parseErrorText();
100 $instance->setErrorsFromParsedErrorText();
101 $actual = $instance->getErrorData();
102
103 $this->assertEquals($expected, $actual);
104 }
105
106 public function test_setErrordata(): void
107 {
108 $instance = new assErrorText();
109 $instance->setPointsWrong(-2);
110
111 $errordata = [new assAnswerErrorText('drei Matrosen')];
112 $expected = [new assAnswerErrorText('drei Matrosen', '', 0.0, null)];
113 $instance->setErrorData($errordata);
114 $actual = $instance->getErrorData();
115
116 $this->assertEquals($expected, $actual);
117 }
118
120 {
121 $instance = new assErrorText();
122 $instance->setPointsWrong(-2);
123
124 $old_errordata = [
125 new assAnswerErrorText('gleichlautende Willenserklärungen zustande.', '', 0.0, 6),
126 new assAnswerErrorText('drei gleichlaute', '', 0.0, 13),
127 new assAnswerErrorText('Supermarkt', '', 0.0, 23),
128 new assAnswerErrorText('konsequentes Handeln.', '', 0.0, 40),
129 ];
130 $new_errordata = [
131 new assAnswerErrorText('gleichlautende Willenserklärungen zustande.', '', 0.0, 2),
132 new assAnswerErrorText('drei gleichlaute', '', 0.0, 3),
133 new assAnswerErrorText('Supermarkt', '', 0.0, 11),
134 new assAnswerErrorText('konsequentes Handeln.', '', 0.0, 32),
135 ];
136
137 $instance->setErrorData($old_errordata);
138 $instance->setErrorData($new_errordata);
139
140 $actual = $instance->getErrorData();
141
142 $this->assertEquals($new_errordata, $actual);
143 }
145 {
146 $instance = new assErrorText();
147 $instance->setPointsWrong(-2);
148
149 $parsed_errortext = [
150 0 => [
151 ['text' => '1', 'error_type' => 'none'],
152 [
153 'text' => 'gleichlautende',
154 'text_wrong' => 'gleichlautende Willenserklärungen zustande.',
155 'error_type' => 'passage_start',
156 'error_position' => 1,
157 'text_correct' => '',
158 'points' => 1,
159 ],
160 ['text' => '2', 'error_type' => 'none'],
161 [
162 'text' => 'Supermarkt',
163 'text_wrong' => 'Supermarkt',
164 'error_type' => 'word',
165 'error_position' => 3,
166 'text_correct' => '',
167 'points' => 1,
168 ],
169 ]
170 ];
171
172 $errordata = [
173 new assAnswerErrorText('gleichlautende Willenserklärungen zustande.', '', 0.0),
174 new assAnswerErrorText('drei gleichlaute', '', 0.0),
175 new assAnswerErrorText('Supermarkt', '', 0.0),
176 new assAnswerErrorText('konsequentes Handeln.', '', ),
177 ];
178 $expected = [
179 new assAnswerErrorText('gleichlautende Willenserklärungen zustande.', '', 0.0, 1),
180 new assAnswerErrorText('Supermarkt', '', 0.0, 3),
181 ];
182
183 $instance->setParsedErrorText($parsed_errortext);
184 $instance->setErrorData($errordata);
185 $instance->removeErrorDataWithoutPosition();
186 $actual = $instance->getErrorData();
187
188 $this->assertEquals($expected, $actual);
189 }
190}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class assBaseTestCase.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class for error text questions.
setGlobalVariable(string $name, mixed $value)