public function test_build() { $testCases = array(array('param_passedStatus' => false, 'param_obligationsAnsweredStatus' => false, 'param_obligationsEnabled' => false, 'expected' => 'mark_tst_failed'), array('param_passedStatus' => false, 'param_obligationsAnsweredStatus' => false, 'param_obligationsEnabled' => true, 'expected' => 'mark_tst_failed_obligations_missing'), array('param_passedStatus' => false, 'param_obligationsAnsweredStatus' => true, 'param_obligationsEnabled' => false, 'expected' => 'mark_tst_failed'), array('param_passedStatus' => false, 'param_obligationsAnsweredStatus' => true, 'param_obligationsEnabled' => true, 'expected' => 'mark_tst_failed_obligations_answered'), array('param_passedStatus' => true, 'param_obligationsAnsweredStatus' => false, 'param_obligationsEnabled' => false, 'expected' => 'mark_tst_passed'), array('param_passedStatus' => true, 'param_obligationsAnsweredStatus' => false, 'param_obligationsEnabled' => true, 'expected' => 'mark_tst_failed_obligations_missing'), array('param_passedStatus' => true, 'param_obligationsAnsweredStatus' => true, 'param_obligationsEnabled' => false, 'expected' => 'mark_tst_passed'), array('param_passedStatus' => true, 'param_obligationsAnsweredStatus' => true, 'param_obligationsEnabled' => true, 'expected' => 'mark_tst_passed_obligations_answered')); foreach ($testCases as $case) { // arrange $passedStatus = $case['param_passedStatus']; $obligationsAnsweredStatus = $case['param_obligationsAnsweredStatus']; $obligationsEnabled = $case['param_obligationsEnabled']; $expected = $case['expected']; include_once './Modules/Test/classes/class.ilTestFinalMarkLangVarBuilder.php'; $instance = new ilTestFinalMarkLangVarBuilder($passedStatus, $obligationsAnsweredStatus, $obligationsEnabled); // act $actual = $instance->build(); // assert $this->assertEquals($expected, $actual); } }
/** * Returns the final statement for a user * * @param array An array containing the information on reached points, max points etc. ("test" key of ilObjTest::getTestResult) * @return string HTML code of the final statement * @access public */ function getFinalStatement($active_id) { $test_data_array = $this->object->getResultsForActiveId($active_id); $obligationsAnswered = $test_data_array['obligations_answered']; if (!$test_data_array["max_points"]) { $percentage = 0; } else { $percentage = $test_data_array["reached_points"] / $test_data_array["max_points"] * 100; } $total_max = $test_data_array["max_points"]; $total_reached = $test_data_array["reached_points"]; $result_percentage = $percentage; $result_total_reached = $total_reached; $result_total_max = $total_max; $mark = ""; $markects = ""; $mark_obj = $this->object->mark_schema->getMatchingMark($result_percentage); if ($mark_obj) { require_once './Modules/Test/classes/class.ilTestFinalMarkLangVarBuilder.php'; $langVarBuilder = new ilTestFinalMarkLangVarBuilder($mark_obj->getPassed(), $obligationsAnswered, $this->object->areObligationsEnabled()); $mark = $this->lng->txt($langVarBuilder->build()); $mark = str_replace("[mark]", $mark_obj->getOfficialName(), $mark); $mark = str_replace("[markshort]", $mark_obj->getShortName(), $mark); $mark = str_replace("[percentage]", sprintf("%.2f", $result_percentage), $mark); $mark = str_replace("[reached]", $result_total_reached, $mark); $mark = str_replace("[max]", $result_total_max, $mark); } if ($this->object->ects_output) { $passed_array =& $this->object->getTotalPointsPassedArray(); $ects_mark = $this->object->getECTSGrade($passed_array, $result_total_reached, $result_total_max); $markects = $this->lng->txt("mark_tst_ects"); $markects = str_replace("[markects]", $this->lng->txt("ects_grade_" . strtolower($ects_mark)), $markects); } return array("mark" => $mark, "markects" => $markects); }