ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ScoreSettingsTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once(__DIR__ . "/../../../../UI/tests/Base.php");
22 require_once(__DIR__ . "/../../../../UI/tests/Component/Input/Field/CommonFieldRendering.php");
23 
25 use ILIAS\Test\Scoring\Settings\Settings as SettingsScoring;
30 use ILIAS\UI\Component as C;
32 
34 {
35  use BaseUITestTrait;
37 
38  public function testScoreSettingsBuild(): void
39  {
40  $id = -666;
41  $s = new ScoreSettings(
42  $id,
43  new SettingsScoring($id),
47  );
48  $this->assertInstanceOf(ScoreSettings::class, $s);
49  $this->assertEquals($id, $s->getTestId());
50  $this->assertInstanceOf(SettingsScoring::class, $s->getScoringSettings());
51  $this->assertInstanceOf(SettingsResultSummary::class, $s->getResultSummarySettings());
52  $this->assertInstanceOf(SettingsResultDetails::class, $s->getResultDetailsSettings());
53  $this->assertInstanceOf(SettingsGamification::class, $s->getGamificationSettings());
54  }
55 
56  public function testScoreSettingsScoring(): void
57  {
58  $s = new SettingsScoring(-666);
59  $this->assertEquals(-667, $s->withTestId(-667)->getTestId());
60  $this->assertEquals(2, $s->withCountSystem(2)->getCountSystem());
61  $this->assertEquals(4, $s->withScoreCutting(4)->getScoreCutting());
62  $this->assertEquals(5, $s->withPassScoring(5)->getPassScoring());
63  }
64 
65  public function testScoreSettingsSummary(): void
66  {
67  $dat = new \DateTimeImmutable();
68  $s = new SettingsResultSummary(-666);
69  $this->assertEquals(
70  ScoreReportingTypes::SCORE_REPORTING_AFTER_PASSED,
71  $s->withScoreReporting(ScoreReportingTypes::SCORE_REPORTING_AFTER_PASSED)->getScoreReporting()
72  );
73  $this->assertTrue($s->withShowGradingStatusEnabled(true)->getShowGradingStatusEnabled());
74  $this->assertFalse($s->withShowGradingStatusEnabled(false)->getShowGradingStatusEnabled());
75  $this->assertTrue($s->withShowGradingMarkEnabled(true)->getShowGradingMarkEnabled());
76  $this->assertFalse($s->withShowGradingMarkEnabled(false)->getShowGradingMarkEnabled());
77  $this->assertTrue($s->withPassDeletionAllowed(true)->getPassDeletionAllowed());
78  $this->assertFalse($s->withPassDeletionAllowed(false)->getPassDeletionAllowed());
79  $this->assertTrue($s->withShowPassDetails(true)->getShowPassDetails());
80  $this->assertFalse($s->withShowPassDetails(false)->getShowPassDetails());
81  }
82 
83  public function testScoreSettingsDetails(): void
84  {
85  $s = new SettingsResultDetails(-666);
86  $this->assertEquals(192, $s->withResultsPresentation(192)->getResultsPresentation(192));
87  $this->assertTrue($s->withShowExamIdInTestResults(true)->getShowExamIdInTestResults());
88  $this->assertTrue($s->withShowPassDetails(true)->getShowPassDetails());
89  $this->assertFalse($s->withShowPassDetails(false)->getShowPassDetails());
90  $this->assertTrue($s->withShowSolutionPrintview(true)->getShowSolutionPrintview());
91  $this->assertFalse($s->withShowSolutionPrintview(false)->getShowSolutionPrintview());
92  $this->assertTrue($s->withShowSolutionFeedback(true)->getShowSolutionFeedback());
93  $this->assertFalse($s->withShowSolutionFeedback(false)->getShowSolutionFeedback());
94  $this->assertTrue($s->withShowSolutionAnswersOnly(true)->getShowSolutionAnswersOnly());
95  $this->assertFalse($s->withShowSolutionAnswersOnly(false)->getShowSolutionAnswersOnly());
96  $this->assertTrue($s->withShowSolutionSignature(true)->getShowSolutionSignature());
97  $this->assertFalse($s->withShowSolutionSignature(false)->getShowSolutionSignature());
98  $this->assertTrue($s->withShowSolutionSuggested(true)->getShowSolutionSuggested());
99  $this->assertFalse($s->withShowSolutionSuggested(false)->getShowSolutionSuggested());
100  $this->assertTrue($s->withShowSolutionListComparison(true)->getShowSolutionListComparison());
101  $this->assertFalse($s->withShowSolutionListComparison(false)->getShowSolutionListComparison());
102  $this->assertTrue($s->withShowPassDetails(true)->getShowPassDetails());
103  }
104 
105  public function testScoreSettingsGamification(): void
106  {
107  $s = new SettingsGamification(-666);
108  $this->assertTrue($s->withHighscoreEnabled(true)->getHighscoreEnabled());
109  $this->assertFalse($s->withHighscoreEnabled(false)->getHighscoreEnabled());
110  $this->assertTrue($s->withHighscoreAnon(true)->getHighscoreAnon());
111  $this->assertFalse($s->withHighscoreAnon(false)->getHighscoreAnon());
112  $this->assertTrue($s->withHighscoreAchievedTS(true)->getHighscoreAchievedTS());
113  $this->assertFalse($s->withHighscoreAchievedTS(false)->getHighscoreAchievedTS());
114  $this->assertTrue($s->withHighscoreScore(true)->getHighscoreScore());
115  $this->assertFalse($s->withHighscoreScore(false)->getHighscoreScore());
116  $this->assertTrue($s->withHighscorePercentage(true)->getHighscorePercentage());
117  $this->assertFalse($s->withHighscorePercentage(false)->getHighscorePercentage());
118  $this->assertTrue($s->withHighscoreHints(true)->getHighscoreHints());
119  $this->assertFalse($s->withHighscoreHints(false)->getHighscoreHints());
120  $this->assertTrue($s->withHighscoreWTime(true)->getHighscoreWTime());
121  $this->assertFalse($s->withHighscoreWTime(false)->getHighscoreWTime());
122  $this->assertTrue($s->withHighscoreOwnTable(true)->getHighscoreOwnTable());
123  $this->assertFalse($s->withHighscoreOwnTable(false)->getHighscoreOwnTable());
124  $this->assertTrue($s->withHighscoreTopTable(true)->getHighscoreTopTable());
125  $this->assertFalse($s->withHighscoreTopTable(false)->getHighscoreTopTable());
126  $this->assertEquals(15, $s->withHighscoreTopNum(15)->getHighscoreTopNum());
127  }
128 
129  protected function getUIPack()
130  {
131  return [
132  $this->getLanguage(),
133  $this->getFieldFactory(),
134  $this->getRefinery()
135  ];
136  }
137 
138  public function testScoreSettingsSectionScoring(): void
139  {
140  $s = new SettingsScoring(666);
141  $actual = $this->render(
142  $s->toForm(...$this->getUIPack())
143  );
144 
145  $i1 = $this->getFormWrappedHtml(
146  'radio-field-input',
147  'tst_text_count_system',
148  '
149  <div class="c-field-radio">
150  <div class="c-field-radio__item">
151  <input type="radio" id="id_1_0_opt" value="0" checked="checked" />
152  <label for="id_1_0_opt">tst_count_partial_solutions</label>
153  <div class="c-input__help-byline">tst_count_partial_solutions_desc</div>
154  </div>
155 
156  <div class="c-field-radio__item">
157  <input type="radio" id="id_1_1_opt" value="1" />
158  <label for="id_1_1_opt">tst_count_correct_solutions</label>
159  <div class="c-input__help-byline">tst_count_correct_solutions_desc</div>
160  </div>
161  </div>
162  ',
163  null,
164  null,
165  null,
166  ''
167  );
168  $i2 = $this->getFormWrappedHtml(
169  'radio-field-input',
170  'tst_score_cutting',
171  '
172  <div class="c-field-radio">
173  <div class="c-field-radio__item">
174  <input type="radio" id="id_2_0_opt" value="0" checked="checked" />
175  <label for="id_2_0_opt">tst_score_cut_question</label>
176  <div class="c-input__help-byline">tst_score_cut_question_desc</div>
177  </div>
178 
179  <div class="c-field-radio__item">
180  <input type="radio" id="id_2_1_opt" value="1" />
181  <label for="id_2_1_opt">tst_score_cut_test</label>
182  <div class="c-input__help-byline">tst_score_cut_test_desc</div>
183  </div>
184  </div>
185  ',
186  null,
187  null,
188  null,
189  ''
190  );
191  $i3 = $this->getFormWrappedHtml(
192  'radio-field-input',
193  'tst_pass_scoring',
194  '
195  <div class="c-field-radio">
196  <div class="c-field-radio__item">
197  <input type="radio" id="id_3_0_opt" value="0" checked="checked" />
198  <label for="id_3_0_opt">tst_pass_last_pass</label>
199  <div class="c-input__help-byline">tst_pass_last_pass_desc</div>
200  </div>
201 
202  <div class="c-field-radio__item">
203  <input type="radio" id="id_3_1_opt" value="1" />
204  <label for="id_3_1_opt">tst_pass_best_pass</label>
205  <div class="c-input__help-byline">tst_pass_best_pass_desc</div>
206  </div>
207  </div>
208  ',
209  null,
210  null,
211  null,
212  ''
213  );
214 
215  $expected = $this->getFormWrappedHtml(
216  'section-field-input',
217  'test_scoring',
218  $i1 . $i2 . $i3,
219  null,
220  null,
221  null,
222  ''
223  );
224  $this->assertHTMLEquals($expected, $this->brutallyTrimSignals($actual));
225  }
226 
227 
228  public function getUIFactory(): NoUIFactory
229  {
230  return new class () extends NoUIFactory {
231  public function symbol(): S\Factory
232  {
233  return new S\Factory(
234  new S\Icon\Factory(),
235  new S\Glyph\Factory(),
236  new S\Avatar\Factory()
237  );
238  }
239  };
240  }
241 
242  public function testScoreSettingsSectionSummary(): void
243  {
244  $data_factory = new \ILIAS\Data\Factory();
245  $language = $this->getLanguage();
246  $refinery = new \ILIAS\Refinery\Factory($data_factory, $language);
247 
249  $this->createMock(\ILIAS\UI\Implementation\Component\Input\UploadLimitResolver::class),
250  new \ILIAS\UI\Implementation\Component\SignalGenerator(),
251  $data_factory,
252  $refinery,
253  $language
254  );
255  $ui = [$language, $field_factory, $refinery];
256 
257  $s = new SettingsResultSummary(666);
258  $actual = $this->render(
259  $s->toForm(...array_merge($ui, [[
260  'user_time_zone' => 'Europe/Berlin',
261  'user_date_format' => $data_factory->dateFormat()->withTime24(
262  $data_factory->dateFormat()->standard()
263  )
264  ]]))
265  );
266 
267  $i1_1_1 = $this->getFormWrappedHtml(
268  'group-field-input',
269  '<input type="radio" id="id_2" value="2" /><span>tst_results_access_always</span>',
270  '',
271  'tst_results_access_always_desc',
272  'id_2',
273  null,
274  ''
275  );
276  $i1_1_2 = $this->getFormWrappedHtml(
277  'group-field-input',
278  '<input type="radio" id="id_3" value="1" /><span>tst_results_access_finished</span>',
279  '',
280  'tst_results_access_finished_desc',
281  'id_3',
282  null,
283  ''
284  );
285  $i1_1_3 = $this->getFormWrappedHtml(
286  'group-field-input',
287  '<input type="radio" id="id_4" value="4" /><span>tst_results_access_passed</span>',
288  '',
289  'tst_results_access_passed_desc',
290  'id_4',
291  null,
292  ''
293  );
294 
295  $i1_1_4_1 = $this->getFormWrappedHtml(
296  'date-time-field-input',
297  'tst_reporting_date<span class="asterisk" aria-label="required_field">*</span>',
298  '<div class="c-input-group">
299  <input id="id_6" type="datetime-local" class="c-field-datetime" />
300  </div>',
301  null,
302  'id_6',
303  null,
304  ''
305  );
306 
307  $i1_1_4 = $this->getFormWrappedHtml(
308  'group-field-input',
309  '<input type="radio" id="id_5" value="3" /><span>tst_results_access_date</span><span class="asterisk" aria-label="required_field">*</span>',
310  $i1_1_4_1,
311  'tst_results_access_date_desc',
312  'id_5',
313  null,
314  ''
315  );
316 
317  $i1_1 = $this->getFormWrappedHtml(
318  'switchable-group-field-input',
319  'tst_results_access_setting<span class="asterisk" aria-label="required_field">*</span>',
320  $i1_1_1 . $i1_1_2 . $i1_1_3 . $i1_1_4,
321  null,
322  null,
323  null,
324  ''
325  );
326 
327  $i1_2 = $this->getFormWrappedHtml(
328  'checkbox-field-input',
329  'tst_results_grading_opt_show_status',
330  '<input type="checkbox" id="id_7" value="checked" class="c-field-checkbox" />',
331  'tst_results_grading_opt_show_status_desc',
332  'id_7',
333  null,
334  ''
335  );
336  $i1_3 = $this->getFormWrappedHtml(
337  'checkbox-field-input',
338  'tst_results_grading_opt_show_mark',
339  '<input type="checkbox" id="id_8" value="checked" class="c-field-checkbox" />',
340  'tst_results_grading_opt_show_mark_desc',
341  'id_8',
342  null,
343  ''
344  );
345  $i1_4 = $this->getFormWrappedHtml(
346  'checkbox-field-input',
347  'tst_results_grading_opt_show_details',
348  '<input type="checkbox" id="id_9" value="checked" class="c-field-checkbox" />',
349  'tst_results_grading_opt_show_details_desc',
350  'id_9',
351  null,
352  ''
353  );
354  $i1_5 = $this->getFormWrappedHtml(
355  'checkbox-field-input',
356  'tst_pass_deletion',
357  '<input type="checkbox" id="id_10" value="checked" class="c-field-checkbox" />',
358  'tst_pass_deletion_allowed',
359  'id_10',
360  null,
361  ''
362  );
363 
364  $i1 = $this->getFormWrappedHtml(
365  'optional-group-field-input',
366  '<span>tst_results_access_enabled</span><input type="checkbox" id="id_1" value="checked" />',
367  $i1_1 . $i1_2 . $i1_3 . $i1_4 . $i1_5,
368  'tst_results_access_enabled_desc',
369  'id_1',
370  null,
371  ''
372  );
373 
374  $expected = $this->getFormWrappedHtml(
375  'section-field-input',
376  'test_results',
377  $i1,
378  null,
379  null,
380  null,
381  ''
382  );
383  $this->assertEquals($expected, $this->brutallyTrimSignals($actual));
384  }
385 
386 
387  public function testScoreSettingsSectionDetails(): void
388  {
389  $s = new SettingsResultDetails(666);
390  $tax_ids = [1,2];
391  $actual = $this->render(
392  $s->toForm(
393  ...array_merge(
394  $this->getUIPack(),
395  [['taxonomy_options' => $tax_ids]]
396  )
397  )
398  );
399  $opts = [
400  ['tst_results_print_best_solution', 'tst_results_print_best_solution_info'],
401  ['tst_show_solution_feedback', 'tst_show_solution_feedback_desc'],
402  ['tst_show_solution_suggested', 'tst_show_solution_suggested_desc'],
403  ['tst_show_solution_printview', 'tst_show_solution_printview_desc'],
404  ['tst_hide_pagecontents', 'tst_hide_pagecontents_desc'],
405  ['tst_show_solution_signature', 'tst_show_solution_signature_desc'],
406  ['examid_in_test_res', 'examid_in_test_res_desc'],
407  ];
408  $options = '';
409  foreach ($opts as $index => $entry) {
410  list($label, $byline) = $entry;
411  $nr = (string) ($index + 1);
412  $checked = $index === 6 ? ' checked="checked"' : '';
413  $field_html = '<input type="checkbox" id="id_' . $nr . '" value="checked"' . $checked . ' class="c-field-checkbox" />';
414  $options .= $this->getFormWrappedHtml(
415  'checkbox-field-input',
416  $label,
417  $field_html,
418  $byline,
419  'id_' . $nr,
420  null,
421  ''
422  );
423  }
424 
425  $expected = $this->getFormWrappedHtml(
426  'section-field-input',
427  'tst_results_details_options',
428  $options,
429  null,
430  null,
431  null,
432  ''
433  );
434  $this->assertEquals($expected, $this->brutallyTrimSignals($actual));
435  }
436 
437 
438  public function testScoreSettingsSectionGamification(): void
439  {
440  $s = new SettingsGamification(666);
441  $actual = $this->render(
442  $s->toForm(...$this->getUIPack())
443  );
444 
445  $fields = $this->getFormWrappedHtml(
446  'radio-field-input',
447  'tst_highscore_mode<span class="asterisk" aria-label="required_field">*</span>',
448  '<div class="c-field-radio">
449  <div class="c-field-radio__item">
450  <input type="radio" id="id_2_1_opt" value="1" /><label for="id_2_1_opt">tst_highscore_own_table</label><div class="c-input__help-byline">tst_highscore_own_table_description</div>
451  </div>
452  <div class="c-field-radio__item">
453  <input type="radio" id="id_2_2_opt" value="2" /><label for="id_2_2_opt">tst_highscore_top_table</label><div class="c-input__help-byline">tst_highscore_top_table_description</div>
454  </div>
455  <div class="c-field-radio__item">
456  <input type="radio" id="id_2_3_opt" value="3" checked="checked" /><label for="id_2_3_opt">tst_highscore_all_tables</label><div class="c-input__help-byline">tst_highscore_all_tables_description</div>
457  </div>
458  </div>',
459  null,
460  null,
461  null,
462  ''
463  );
464  $fields .= $this->getFormWrappedHtml(
465  'numeric-field-input',
466  'tst_highscore_top_num<span class="asterisk" aria-label="required_field">*</span>',
467  '<input id="id_3" type="number" value="10" class="c-field-number" />',
468  'tst_highscore_top_num_description',
469  'id_3',
470  null,
471  ''
472  );
473 
474 
475  $opts = [
476  ['tst_highscore_anon', 'tst_highscore_anon_description'],
477  ['tst_highscore_achieved_ts', 'tst_highscore_achieved_ts_description'],
478  ['tst_highscore_score', 'tst_highscore_score_description'],
479  ['tst_highscore_percentage', 'tst_highscore_percentage_description'],
480  ['tst_highscore_hints', 'tst_highscore_hints_description'],
481  ['tst_highscore_wtime', 'tst_highscore_wtime_description']
482  ];
483  foreach ($opts as $index => $entry) {
484  list($label, $byline) = $entry;
485  $nr = (string) ($index + 4);
486  $field_html = '<input type="checkbox" id="id_' . $nr . '" value="checked" checked="checked" class="c-field-checkbox" />';
487  $fields .= $this->getFormWrappedHtml(
488  'checkbox-field-input',
489  $label,
490  $field_html,
491  $byline,
492  'id_' . $nr,
493  null,
494  ''
495  );
496  }
497 
498  $group = $this->getFormWrappedHtml(
499  'optional-group-field-input',
500  '<span>tst_highscore_enabled</span><input type="checkbox" id="id_1" value="checked" />',
501  $fields,
502  'tst_highscore_description',
503  'id_1',
504  null,
505  ''
506  );
507 
508  $expected = $this->getFormWrappedHtml(
509  'section-field-input',
510  'tst_results_gamification',
511  $group,
512  null,
513  null,
514  null,
515  ''
516  );
517  $this->assertHTMLEquals($expected, $this->brutallyTrimSignals($actual));
518  }
519 
521  {
522  $id = -666;
523  $s = new ScoreSettings(
524  $id,
525  new SettingsScoring($id),
529  );
530 
531  $t = new class ($s) extends ilObjTest {
532  public function __construct($s)
533  {
534  $this->score_settings = $s;
535  }
536  };
537 
538  $this->assertIsInt($t->getCountSystem());
539  $this->assertIsInt($t->getScoreCutting());
540  $this->assertIsInt($t->getPassScoring());
541  $this->assertIsBool($t->getShowPassDetails());
542  $this->assertIsBool($t->getShowSolutionAnswersOnly());
543  $this->assertIsBool($t->getShowSolutionSignature());
544  $this->assertIsBool($t->getShowSolutionSuggested());
545  $this->assertIsBool($t->getShowSolutionListComparison());
546  $this->assertIsBool($t->isPassDeletionAllowed());
547  $this->assertIsInt($t->getExportSettings());
548  $this->assertIsBool($t->getHighscoreEnabled());
549  $this->assertIsBool($t->getHighscoreAnon());
550  $this->assertIsBool($t->getHighscoreAchievedTS());
551  $this->assertIsBool($t->getHighscoreScore());
552  $this->assertIsBool($t->getHighscorePercentage());
553  $this->assertIsBool($t->getHighscoreHints());
554  $this->assertIsBool($t->getHighscoreWTime());
555  $this->assertIsBool($t->getHighscoreOwnTable());
556  $this->assertIsBool($t->getHighscoreTopTable());
557  $this->assertIsInt($t->getHighscoreTopNum());
558  $this->assertIsInt($t->getHighscoreMode());
559  }
560 
561  public function testScoreSettingsRelayingTestId(): void
562  {
563  $id = -666;
564  $s = new ScoreSettings(
565  $id,
566  new SettingsScoring($id),
570  );
571 
572  $nu_id = 1234;
573  $s = $s->withTestId($nu_id);
574  $this->assertEquals($nu_id, $s->getTestId());
575  $this->assertEquals($nu_id, $s->getScoringSettings()->getTestId());
576  $this->assertEquals($nu_id, $s->getResultSummarySettings()->getTestId());
577  $this->assertEquals($nu_id, $s->getResultDetailsSettings()->getTestId());
578  $this->assertEquals($nu_id, $s->getGamificationSettings()->getTestId());
579  }
580 }
Interface Observer Contains several chained tasks and infos about them.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getLanguage()
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
__construct(Container $dic, ilPlugin $plugin)