Skip to content

Commit

Permalink
TA: PresentationTable, remove mutators from PassResultsSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
nhaagen authored and kergomard committed Oct 18, 2023
1 parent fbc7738 commit 56d614a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 68 deletions.
51 changes: 6 additions & 45 deletions Modules/Test/classes/Results/class.ilTestPassResultsSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,80 +24,41 @@
*/
class ilTestPassResultsSettings
{
protected bool $show_hidden_questions = false;
protected bool $show_optional_questions = false;
protected bool $show_best_solution = true;
protected bool $show_feedback = true;
protected bool $question_text_only = false;
protected bool $show_recapitulation = false;


public function __construct(
protected bool $show_hidden_questions = false,
protected bool $show_optional_questions = false,
protected bool $show_best_solution = true,
protected bool $show_feedback = true,
protected bool $question_text_only = false,
protected bool $show_recapitulation = false
) {
}

public function withShowHiddenQuestions(bool $flag): self
{
$clone = clone $this;
$clone->show_hidden_questions = $flag;
return $clone;
}
public function getShowHiddenQuestions(): bool
{
return $this->show_hidden_questions;
}

public function withShowOptionalQuestions(bool $flag): self
{
$clone = clone $this;
$clone->show_optional_questions = $flag;
return $clone;
}
public function getShowOptionalQuestions(): bool
{
return $this->show_optional_questions;
}

public function withShowBestSolution(bool $flag): self
{
$clone = clone $this;
$clone->show_best_solution = $flag;
return $clone;
}

public function getShowBestSolution(): bool
{
return $this->show_best_solution;
}

public function withShowFeedback(bool $flag): self
{
$clone = clone $this;
$clone->show_feedback = $flag;
return $clone;
}
public function getShowFeedback(): bool
{
return $this->show_feedback;
}

public function withQuestionTextOnly(bool $flag): self
{
$clone = clone $this;
$clone->question_text_only = $flag;
return $clone;
}
public function getQuestionTextOnly(): bool
{
return $this->question_text_only;
}

public function withShowRecapitulation(bool $flag): self
{
$clone = clone $this;
$clone->show_recapitulation = $flag;
return $clone;
}
public function getShowRecapitulation(): bool
{
return $this->show_recapitulation;
Expand Down
25 changes: 15 additions & 10 deletions Modules/Test/classes/Results/class.ilTestResultsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,23 @@ protected function getPassResultsSettings(
$settings = $test_obj->getScoreSettings();
$settings_summary = $settings->getResultSummarySettings();
$settings_result = $settings->getResultDetailsSettings();

$show_hidden_questions = false;
$show_optional_questions = true;
$show_best_solution = $is_user_output ?
$settings_result->getShowSolutionListComparison() :
(bool)ilSession::get('tst_results_show_best_solutions');

$pass_result_settings = (new ilTestPassResultsSettings())
->withShowHiddenQuestions(false)
->withShowOptionalQuestions(true)
->withShowBestSolution($show_best_solution)
->withShowFeedback($settings_result->getShowSolutionFeedback())
->withQuestionTextOnly($settings_result->getShowSolutionAnswersOnly())
->withShowRecapitulation($settings_result->getShowSolutionSuggested())
;
return $pass_result_settings;
$show_feedback = $settings_result->getShowSolutionFeedback();
$show_question_text_only = $settings_result->getShowSolutionAnswersOnly();
$show_content_for_recapitulation = $settings_result->getShowSolutionSuggested();

return new ilTestPassResultsSettings(
$show_hidden_questions,
$show_optional_questions,
$show_best_solution,
$show_feedback,
$show_question_text_only,
$show_content_for_recapitulation
);
}
}
28 changes: 15 additions & 13 deletions Modules/Test/test/TestPassResultsSettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,20 @@ public function testTestResultsSettingsDefaults(): void

public function testTestResultsSettingsBasicProps(): void
{
$trs = new \ilTestPassResultsSettings();
$this->assertTrue($trs->withShowHiddenQuestions(true)->getShowHiddenQuestions());
$this->assertFalse($trs->withShowHiddenQuestions(false)->getShowHiddenQuestions());
$this->assertTrue($trs->withShowOptionalQuestions(true)->getShowOptionalQuestions());
$this->assertFalse($trs->withShowOptionalQuestions(false)->getShowOptionalQuestions());
$this->assertTrue($trs->withShowBestSolution(true)->getShowBestSolution());
$this->assertFalse($trs->withShowBestSolution(false)->getShowBestSolution());
$this->assertTrue($trs->withShowFeedback(true)->getShowFeedback());
$this->assertFalse($trs->withShowFeedback(false)->getShowFeedback());
$this->assertTrue($trs->withQuestionTextOnly(true)->getQuestionTextOnly());
$this->assertFalse($trs->withQuestionTextOnly(false)->getQuestionTextOnly());
$this->assertTrue($trs->withShowRecapitulation(true)->getShowRecapitulation());
$this->assertFalse($trs->withShowRecapitulation(false)->getShowRecapitulation());
$trs = new \ilTestPassResultsSettings(true, true, true, true, true, true);
$this->assertTrue($trs->getShowHiddenQuestions());
$this->assertTrue($trs->getShowOptionalQuestions());
$this->assertTrue($trs->getShowBestSolution());
$this->assertTrue($trs->getShowFeedback());
$this->assertTrue($trs->getQuestionTextOnly());
$this->assertTrue($trs->getShowRecapitulation());

$trs = new \ilTestPassResultsSettings(false, false, false, false, false, false);
$this->assertFalse($trs->getShowHiddenQuestions());
$this->assertFalse($trs->getShowOptionalQuestions());
$this->assertFalse($trs->getShowBestSolution());
$this->assertFalse($trs->getShowFeedback());
$this->assertFalse($trs->getQuestionTextOnly());
$this->assertFalse($trs->getShowRecapitulation());
}
}

0 comments on commit 56d614a

Please sign in to comment.