ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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  //$lng_mock->expects( $this->once() )->method( 'txt' )->will( $this->returnValue('Test') );
43  $this->setGlobalVariable('lng', $lng_mock);
44 
45  $this->setGlobalVariable('ilias', $this->getIliasMock());
46  $this->setGlobalVariable('ilDB', $this->getDatabaseMock());
47  }
48 
49  public function test_instantiateObjectSimple(): void
50  {
51  $instance = new assErrorText();
52 
53  $this->assertInstanceOf(assErrorText::class, $instance);
54  }
55 
56  public function test_getErrorsFromText(): void
57  {
58  $this->markTestSkipped('Generates warning for some unknown reason.');
59 
60  $instance = new assErrorText();
61  $instance->setPointsWrong(-2);
62 
63  $errortext = '
64  Eine Kündigung kommt durch zwei ((gleichlautende Willenserklärungen zustande)).
65  Ein Vertrag kommt durch ((drei gleichlaute)) Willenserklärungen zustande.
66  Ein Kaufvertrag an der Kasse im #Supermarkt kommt durch das legen von Ware auf das
67  Kassierband und den Kassiervorgang zustande. Dies nennt man ((konsequentes Handeln.))';
68 
69  $expected = [
70  new assAnswerErrorText('gleichlautende Willenserklärungen zustande.', '', 0.0, 6),
71  new assAnswerErrorText('drei gleichlaute', '', 0.0, 13),
72  new assAnswerErrorText('Supermarkt', '', 0.0, 23),
73  new assAnswerErrorText('konsequentes Handeln.', '', 0.0, 40),
74  ];
75 
76  $instance->setErrorText($errortext);
77  $instance->parseErrorText();
78  $instance->setErrorsFromParsedErrorText();
79  $actual = $instance->getErrorData();
80 
81  $this->assertEquals($expected, $actual);
82  }
83 
84  public function test_getErrorsFromText_noMatch(): void
85  {
86  $this->markTestSkipped('Generates warning for some unknown reason.');
87 
88  $instance = new assErrorText();
89  $instance->setPointsWrong(-2);
90 
91  $errortext = '
92  Eine Kündigung)) kommt durch zwei gleichlautende (Willenserklärungen) zustande.
93  Ein Vertrag kommt durch (drei gleichlaute) Willenserklärungen zustande.
94  Ein Kaufvertrag an der Kasse im Supermarkt [kommt] durch das legen von Ware auf das
95  Kassierband und den [[Kassiervorgang]] zustande. Dies nennt man *konsequentes Handeln.';
96 
97  $expected = [];
98 
99  $instance->setErrorText($errortext);
100  $instance->parseErrorText();
101  $instance->setErrorsFromParsedErrorText();
102  $actual = $instance->getErrorData();
103 
104  $this->assertEquals($expected, $actual);
105  }
106 
107  public function test_setErrordata(): void
108  {
109  $instance = new assErrorText();
110  $instance->setPointsWrong(-2);
111 
112  $errordata = [new assAnswerErrorText('drei Matrosen')];
113  $expected = [new assAnswerErrorText('drei Matrosen', '', 0.0, null)];
114  $instance->setErrorData($errordata);
115  $actual = $instance->getErrorData();
116 
117  $this->assertEquals($expected, $actual);
118  }
119 
121  {
122  $instance = new assErrorText();
123  $instance->setPointsWrong(-2);
124 
125  $old_errordata = [
126  new assAnswerErrorText('gleichlautende Willenserklärungen zustande.', '', 0.0, 6),
127  new assAnswerErrorText('drei gleichlaute', '', 0.0, 13),
128  new assAnswerErrorText('Supermarkt', '', 0.0, 23),
129  new assAnswerErrorText('konsequentes Handeln.', '', 0.0, 40),
130  ];
131  $new_errordata = [
132  new assAnswerErrorText('gleichlautende Willenserklärungen zustande.', '', 0.0, 2),
133  new assAnswerErrorText('drei gleichlaute', '', 0.0, 3),
134  new assAnswerErrorText('Supermarkt', '', 0.0, 11),
135  new assAnswerErrorText('konsequentes Handeln.', '', 0.0, 32),
136  ];
137 
138  $instance->setErrorData($old_errordata);
139  $instance->setErrorData($new_errordata);
140 
141  $actual = $instance->getErrorData();
142 
143  $this->assertEquals($new_errordata, $actual);
144  }
145  public function test_removeErrorDataWithoutPosition(): void
146  {
147  $instance = new assErrorText();
148  $instance->setPointsWrong(-2);
149 
150  $parsed_errortext = [
151  0 => [
152  ['text' => '1', 'error_type' => 'none'],
153  [
154  'text' => 'gleichlautende',
155  'text_wrong' => 'gleichlautende Willenserklärungen zustande.',
156  'error_type' => 'passage_start',
157  'error_position' => 1,
158  'text_correct' => '',
159  'points' => 1,
160  ],
161  ['text' => '2', 'error_type' => 'none'],
162  [
163  'text' => 'Supermarkt',
164  'text_wrong' => 'Supermarkt',
165  'error_type' => 'word',
166  'error_position' => 3,
167  'text_correct' => '',
168  'points' => 1,
169  ],
170  ]
171  ];
172 
173  $errordata = [
174  new assAnswerErrorText('gleichlautende Willenserklärungen zustande.', '', 0.0),
175  new assAnswerErrorText('drei gleichlaute', '', 0.0),
176  new assAnswerErrorText('Supermarkt', '', 0.0),
177  new assAnswerErrorText('konsequentes Handeln.', '', ),
178  ];
179  $expected = [
180  new assAnswerErrorText('gleichlautende Willenserklärungen zustande.', '', 0.0, 1),
181  new assAnswerErrorText('Supermarkt', '', 0.0, 3),
182  ];
183 
184  $instance->setParsedErrorText($parsed_errortext);
185  $instance->setErrorData($errordata);
186  $instance->removeErrorDataWithoutPosition();
187  $actual = $instance->getErrorData();
188 
189  $this->assertEquals($expected, $actual);
190  }
191 }
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...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
Class for error text questions.