ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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(dirname(__FILE__));
33  chdir('../../../');
34 
35  parent::setUp();
36 
37  $ilCtrl_mock = $this->createMock('ilCtrl');
38  $ilCtrl_mock->expects($this->any())->method('saveParameter');
39  $ilCtrl_mock->expects($this->any())->method('saveParameterByClass');
40  $this->setGlobalVariable('ilCtrl', $ilCtrl_mock);
41 
42  $lng_mock = $this->createMock('ilLanguage', array('txt'), array(), '', false);
43  //$lng_mock->expects( $this->once() )->method( 'txt' )->will( $this->returnValue('Test') );
44  $this->setGlobalVariable('lng', $lng_mock);
45 
46  $this->setGlobalVariable('ilias', $this->getIliasMock());
47  $this->setGlobalVariable('tpl', $this->getGlobalTemplateMock());
48  $this->setGlobalVariable('ilDB', $this->getDatabaseMock());
49  }
50 
51  public function test_instantiateObjectSimple(): void
52  {
53  // Act
54  $instance = new assErrorText();
55 
56  // Assert
57  $this->assertInstanceOf('assErrorText', $instance);
58  }
59 
60  public function test_getErrorsFromText(): void
61  {
62  $instance = new assErrorText();
63  $instance->setPointsWrong(-2);
64 
65  $errortext = '
66  Eine Kündigung kommt durch zwei ((gleichlautende Willenserklärungen zustande)).
67  Ein Vertrag kommt durch ((drei gleichlaute)) Willenserklärungen zustande.
68  Ein Kaufvertrag an der Kasse im #Supermarkt kommt durch das legen von Ware auf das
69  Kassierband und den Kassiervorgang zustande. Dies nennt man ((konsequentes Handeln.))';
70 
71  $expected = [
72  new assAnswerErrorText('gleichlautende Willenserklärungen zustande.', '', 0.0, 6),
73  new assAnswerErrorText('drei gleichlaute', '', 0.0, 13),
74  new assAnswerErrorText('Supermarkt', '', 0.0, 23),
75  new assAnswerErrorText('konsequentes Handeln.', '', 0.0, 40)
76  ];
77 
78  $instance->setErrorText($errortext);
79  $instance->parseErrorText();
80  $instance->setErrorsFromParsedErrorText();
81  $actual = $instance->getErrorData();
82 
83  $this->assertEquals($expected, $actual);
84  }
85 
86  public function test_getErrorsFromText_noMatch(): void
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setGlobalVariable(string $name, $value)