Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'MDL-30031-22' of git://github.com/bostelm/moodle into M…

…OODLE_22_STABLE
  • Loading branch information...
commit f36884dde739f38b7c2e59f14cd57f8fc4e24358 2 parents 5dff4c5 + fb93cfa
@stronk7 stronk7 authored
View
2  question/behaviour/adaptive/behaviour.php
@@ -119,7 +119,7 @@ public function process_submit(question_attempt_pending_step $pendingstep) {
$status = $this->process_save($pendingstep);
$response = $pendingstep->get_qt_data();
- if (!$this->question->is_gradable_response($response)) {
+ if (!$this->question->is_complete_response($response)) {
$pendingstep->set_state(question_state::$invalid);
if ($this->qa->get_state() != question_state::$invalid) {
$status = question_attempt::KEEP;
View
1  question/behaviour/adaptive/lang/en/qbehaviour_adaptive.php
@@ -23,6 +23,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+$string['disregardedwithoutpenalty'] = 'The submission was invalid, and has been disregarded without penalty.';
$string['gradingdetails'] = 'Marks for this submission: {$a->raw}/{$a->max}.';
$string['gradingdetailsadjustment'] = 'Accounting for previous tries, this gives <strong>{$a->cur}/{$a->max}</strong>.';
$string['gradingdetailspenalty'] = 'This submission attracted a penalty of {$a}.';
View
18 question/behaviour/adaptive/renderer.php
@@ -42,6 +42,16 @@ public function controls(question_attempt $qa, question_display_options $options
}
public function feedback(question_attempt $qa, question_display_options $options) {
+ if ($qa->get_state() == question_state::$invalid) {
+ // If the latest answer was invalid, display an informative message
+ $output = '';
+ $info = $this->disregarded_info();
+ if ($info) {
+ $output = html_writer::tag('div', $info, array('class' => 'gradingdetails'));
+ }
+ return $output;
+ }
+
// Try to find the last graded step.
$gradedstep = $qa->get_behaviour()->get_graded_step($qa);
@@ -116,4 +126,12 @@ protected function penalty_info(question_attempt $qa, $mark,
return $output;
}
+
+ /**
+ * Display information about a disregarded (incomplete) response.
+ */
+ protected function disregarded_info() {
+ return get_string('disregardedwithoutpenalty', 'qbehaviour_adaptive');
+ }
+
}
View
119 question/behaviour/adaptive/simpletest/testwalkthrough.php
@@ -63,6 +63,16 @@ protected function get_does_not_contain_total_penalty_expectation() {
return new NoPatternExpectation($penaltypattern);
}
+ protected function get_contains_disregarded_info_expectation() {
+ $penaltyinfo = get_string('disregardedwithoutpenalty', 'qbehaviour_adaptive');
+ return new PatternExpectation('/'.preg_quote($penaltyinfo).'/');
+ }
+
+ protected function get_does_not_contain_disregarded_info_expectation() {
+ $penaltyinfo = get_string('disregardedwithoutpenalty', 'qbehaviour_adaptive');
+ return new NoPatternExpectation('/'.preg_quote($penaltyinfo).'/');
+ }
+
public function test_adaptive_multichoice() {
// Create a multiple choice, single response question.
@@ -542,7 +552,8 @@ public function test_adaptive_shortanswer_try_to_submit_blank() {
$this->get_does_not_contain_correctness_expectation(),
$this->get_does_not_contain_penalty_info_expectation(),
$this->get_does_not_contain_total_penalty_expectation(),
- $this->get_contains_validation_error_expectation());
+ $this->get_contains_validation_error_expectation(),
+ $this->get_contains_disregarded_info_expectation());
$this->assertNull($this->quba->get_response_summary($this->slot));
// Now get it wrong.
@@ -568,7 +579,7 @@ public function test_adaptive_shortanswer_try_to_submit_blank() {
$this->check_current_output(
$this->get_contains_mark_summary(0.8),
$this->get_contains_submit_button_expectation(true),
- $this->get_contains_partcorrect_expectation(),
+ $this->get_does_not_contain_correctness_expectation(),
$this->get_does_not_contain_penalty_info_expectation(),
$this->get_does_not_contain_total_penalty_expectation(),
$this->get_contains_validation_error_expectation());
@@ -628,4 +639,108 @@ public function test_adaptive_numerical() {
$this->get_contains_incorrect_expectation(),
$this->get_does_not_contain_validation_error_expectation());
}
+
+ public function test_adaptive_numerical_invalid() {
+
+ // Create a numerical question
+ $numq = test_question_maker::make_question('numerical', 'pi');
+ $numq->penalty = 0.1;
+ $this->start_attempt_at_question($numq, 'adaptive');
+
+ // Check the initial state.
+ $this->check_current_state(question_state::$todo);
+ $this->check_current_mark(null);
+ $this->check_current_output(
+ $this->get_contains_marked_out_of_summary(),
+ $this->get_contains_submit_button_expectation(true),
+ $this->get_does_not_contain_feedback_expectation());
+
+ // Submit a non-numerical answer.
+ $this->process_submission(array('-submit' => 1, 'answer' => 'Pi'));
+
+ // Verify.
+ $this->check_current_state(question_state::$invalid);
+ $this->check_current_mark(null);
+ $this->check_current_output(
+ $this->get_contains_marked_out_of_summary(1),
+ $this->get_contains_submit_button_expectation(true),
+ $this->get_does_not_contain_correctness_expectation(),
+ $this->get_does_not_contain_penalty_info_expectation(),
+ $this->get_does_not_contain_total_penalty_expectation(),
+ $this->get_contains_validation_error_expectation(),
+ $this->get_contains_disregarded_info_expectation());
+
+ // Submit an incorrect answer.
+ $this->process_submission(array('-submit' => 1, 'answer' => '-5'));
+
+ // Verify.
+ $this->check_current_state(question_state::$todo);
+ $this->check_current_mark(0);
+ $this->check_current_output(
+ $this->get_contains_mark_summary(0),
+ $this->get_contains_submit_button_expectation(true),
+ $this->get_contains_incorrect_expectation(),
+ $this->get_contains_penalty_info_expectation(0.1),
+ $this->get_does_not_contain_total_penalty_expectation(),
+ $this->get_does_not_contain_validation_error_expectation(),
+ $this->get_does_not_contain_disregarded_info_expectation());
+
+ // Submit another non-numerical answer.
+ $this->process_submission(array('-submit' => 1, 'answer' => 'Pi*2'));
+
+ // Verify.
+ $this->check_current_state(question_state::$invalid);
+ $this->check_current_mark(0);
+ $this->check_current_output(
+ $this->get_contains_mark_summary(0),
+ $this->get_contains_submit_button_expectation(true),
+ $this->get_does_not_contain_correctness_expectation(),
+ $this->get_does_not_contain_penalty_info_expectation(),
+ $this->get_does_not_contain_total_penalty_expectation(),
+ $this->get_contains_validation_error_expectation(),
+ $this->get_contains_disregarded_info_expectation());
+
+ // Submit the correct answer.
+ $this->process_submission(array('-submit' => 1, 'answer' => '3.14'));
+
+ // Verify.
+ $this->check_current_state(question_state::$complete);
+ $this->check_current_mark(0.9);
+ $this->check_current_output(
+ $this->get_contains_mark_summary(0.9),
+ $this->get_contains_submit_button_expectation(true),
+ $this->get_contains_correct_expectation(),
+ $this->get_does_not_contain_penalty_info_expectation(),
+ $this->get_does_not_contain_total_penalty_expectation(),
+ $this->get_does_not_contain_validation_error_expectation(),
+ $this->get_does_not_contain_disregarded_info_expectation());
+
+ // Submit another non-numerical answer.
+ $this->process_submission(array('-submit' => 1, 'answer' => 'Pi/3'));
+
+ // Verify.
+ $this->check_current_state(question_state::$invalid);
+ $this->check_current_mark(0.9);
+ $this->check_current_output(
+ $this->get_contains_mark_summary(0.9),
+ $this->get_contains_submit_button_expectation(true),
+ $this->get_does_not_contain_correctness_expectation(),
+ $this->get_does_not_contain_penalty_info_expectation(),
+ $this->get_does_not_contain_total_penalty_expectation(),
+ $this->get_contains_validation_error_expectation(),
+ $this->get_contains_disregarded_info_expectation());
+
+ // Finish the attempt.
+ $this->quba->finish_all_questions();
+
+ // Verify.
+ $this->check_current_state(question_state::$gradedwrong);
+ $this->check_current_mark(0.9);
+ $this->check_current_output(
+ $this->get_contains_mark_summary(0.9),
+ $this->get_contains_submit_button_expectation(false),
+ $this->get_contains_incorrect_expectation(),
+ $this->get_does_not_contain_validation_error_expectation(),
+ $this->get_does_not_contain_disregarded_info_expectation());
+ }
}
View
3  question/behaviour/adaptivenopenalty/renderer.php
@@ -41,4 +41,7 @@ class qbehaviour_adaptivenopenalty_renderer extends qbehaviour_adaptive_renderer
protected function penalty_info($qa, $mark) {
return '';
}
+ protected function disregarded_info() {
+ return '';
+ }
}
View
96 question/behaviour/adaptivenopenalty/simpletest/testwalkthrough.php
@@ -38,6 +38,11 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qbehaviour_adaptivenopenalty_walkthrough_test extends qbehaviour_walkthrough_test_base {
+
+ protected function get_does_not_contain_gradingdetails_expectation() {
+ return new NoPatternExpectation('/class="gradingdetails"/');
+ }
+
public function test_multichoice() {
// Create a multiple choice, single response question.
@@ -192,4 +197,95 @@ public function test_multichoice2() {
$this->get_contains_submit_button_expectation(false),
$this->get_contains_correct_expectation());
}
+
+ public function test_numerical_invalid() {
+
+ // Create a numerical question
+ $numq = test_question_maker::make_question('numerical', 'pi');
+ $numq->penalty = 0.1;
+ $this->start_attempt_at_question($numq, 'adaptivenopenalty');
+
+ // Check the initial state.
+ $this->check_current_state(question_state::$todo);
+ $this->check_current_mark(null);
+ $this->check_current_output(
+ $this->get_contains_marked_out_of_summary(),
+ $this->get_contains_submit_button_expectation(true),
+ $this->get_does_not_contain_feedback_expectation());
+
+ // Submit a non-numerical answer.
+ $this->process_submission(array('-submit' => 1, 'answer' => 'Pi'));
+
+ // Verify.
+ $this->check_current_state(question_state::$invalid);
+ $this->check_current_mark(null);
+ $this->check_current_output(
+ $this->get_contains_marked_out_of_summary(1),
+ $this->get_contains_submit_button_expectation(true),
+ $this->get_does_not_contain_correctness_expectation(),
+ $this->get_contains_validation_error_expectation(),
+ $this->get_does_not_contain_feedback_expectation());
+
+ // Submit an incorrect answer.
+ $this->process_submission(array('-submit' => 1, 'answer' => '-5'));
+
+ // Verify.
+ $this->check_current_state(question_state::$todo);
+ $this->check_current_mark(0);
+ $this->check_current_output(
+ $this->get_contains_mark_summary(0),
+ $this->get_contains_submit_button_expectation(true),
+ $this->get_contains_incorrect_expectation(),
+ $this->get_does_not_contain_validation_error_expectation());
+
+ // Submit another non-numerical answer.
+ $this->process_submission(array('-submit' => 1, 'answer' => 'Pi*2'));
+
+ // Verify.
+ $this->check_current_state(question_state::$invalid);
+ $this->check_current_mark(0);
+ $this->check_current_output(
+ $this->get_contains_mark_summary(0),
+ $this->get_contains_submit_button_expectation(true),
+ $this->get_does_not_contain_correctness_expectation(),
+ $this->get_contains_validation_error_expectation(),
+ $this->get_does_not_contain_gradingdetails_expectation());
+
+ // Submit the correct answer.
+ $this->process_submission(array('-submit' => 1, 'answer' => '3.14'));
+
+ // Verify.
+ $this->check_current_state(question_state::$complete);
+ $this->check_current_mark(1.0);
+ $this->check_current_output(
+ $this->get_contains_mark_summary(1.0),
+ $this->get_contains_submit_button_expectation(true),
+ $this->get_contains_correct_expectation(),
+ $this->get_does_not_contain_validation_error_expectation());
+
+ // Submit another non-numerical answer.
+ $this->process_submission(array('-submit' => 1, 'answer' => 'Pi/3'));
+
+ // Verify.
+ $this->check_current_state(question_state::$invalid);
+ $this->check_current_mark(1.0);
+ $this->check_current_output(
+ $this->get_contains_mark_summary(1.0),
+ $this->get_contains_submit_button_expectation(true),
+ $this->get_does_not_contain_correctness_expectation(),
+ $this->get_contains_validation_error_expectation(),
+ $this->get_does_not_contain_gradingdetails_expectation());
+
+ // Finish the attempt.
+ $this->quba->finish_all_questions();
+
+ // Verify.
+ $this->check_current_state(question_state::$gradedwrong);
+ $this->check_current_mark(1.0);
+ $this->check_current_output(
+ $this->get_contains_mark_summary(1.0),
+ $this->get_contains_submit_button_expectation(false),
+ $this->get_contains_incorrect_expectation(),
+ $this->get_does_not_contain_validation_error_expectation());
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.