Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matrix: incomplete answer list not marked as expected. #826739 #7

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
matrix:
include:
- php: '8.3'
moodle-branch: 'master'
moodle-branch: 'main'
database: 'mariadb'
- php: '8.2'
moodle-branch: 'MOODLE_404_STABLE'
Expand Down
30 changes: 25 additions & 5 deletions question.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,6 @@ protected function init_roworder(question_attempt $qa) {
}
}

#[\Override]
public function is_gradable_response(array $response) {
return $this->is_complete_response($response);
}

#[\Override]
public function check_file_access($qa, $options, $component, $filearea, $args, $forcedownload) {
if ($component == 'question' && in_array($filearea,
Expand Down Expand Up @@ -275,6 +270,18 @@ public function is_complete_response(array $response): bool {
return true;
}

#[\Override]
public function is_gradable_response(array $response): bool {
foreach ($this->roworder as $key => $rownumber) {
$fieldname = $this->field($key);
if (array_key_exists($fieldname, $response)) {
return true;
}
}

return false;
}

#[\Override]
public function classify_response(array $response): array {
$classifiedresponse = [];
Expand Down Expand Up @@ -450,6 +457,19 @@ public function is_complete_response(array $response): bool {
return true;
}

#[\Override]
public function is_gradable_response(array $response): bool {
foreach ($this->roworder as $key => $rownumber) {
foreach ($this->columns as $column) {
$fieldname = $this->field($key, $column->number);
if (array_key_exists($fieldname, $response)) {
return true;
}
}
}
return false;
}

#[\Override]
public function classify_response(array $response) {
$classifiedresponse = [];
Expand Down
9 changes: 6 additions & 3 deletions tests/question_multiple_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,16 @@ public function test_is_gradable_response(): void {

// If all rows (sub-questions) are answered then the response is gradable.
$response = ['rowanswers0_1' => '1'];
$this->assertFalse($question->is_gradable_response($response), $question->is_complete_response($response));
$this->assertTrue($question->is_gradable_response($response));

$response = ['rowanswers0_1' => '1', 'rowanswers1_2' => '1'];
$this->assertFalse($question->is_gradable_response($response), $question->is_complete_response($response));
$this->assertTrue($question->is_gradable_response($response));

$response = ['rowanswers0_1' => '1', 'rowanswers1_1' => '1', 'rowanswers2_1' => '1'];
$this->assertTrue($question->is_gradable_response($response), $question->is_complete_response($response));
$this->assertTrue($question->is_gradable_response($response));

$response = [];
$this->assertFalse($question->is_gradable_response($response));
}

public function test_classify_response_multiple(): void {
Expand Down
10 changes: 8 additions & 2 deletions tests/question_single_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,16 @@ public function test_is_gradable_response(): void {
$question->start_attempt(new question_attempt_step(), 1);

$response = ['rowanswers0' => '1', 'rowanswers1' => '1', 'rowanswers2' => '2', 'rowanswers3' => '2'];
$this->assertEquals($question->is_gradable_response($response), $question->is_complete_response($response));
$this->assertTrue($question->is_gradable_response($response));

$response = ['rowanswers0' => '1', 'rowanswers1' => '1', 'rowanswers2' => '2'];
$this->assertEquals($question->is_gradable_response($response), $question->is_complete_response($response));
$this->assertTrue($question->is_gradable_response($response));

$response = ['rowanswers0' => '1'];
$this->assertTrue($question->is_gradable_response($response));

$response = [];
$this->assertFalse($question->is_gradable_response($response));
}

public function test_classify_response_single(): void {
Expand Down
Loading