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