Skip to content
This repository has been archived by the owner on Dec 13, 2024. It is now read-only.

Commit

Permalink
MDL-64761 assign: Add tests for hidden grader in WS
Browse files Browse the repository at this point in the history
  • Loading branch information
dpalou committed Feb 4, 2019
1 parent 208e137 commit 468ee73
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions mod/assign/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2159,6 +2159,64 @@ public function test_get_submission_status_access_control() {

}

/**
* Test hidden grader for get_submission_status.
*/
public function test_get_submission_status_hidden_grader() {
$this->resetAfterTest(true);

list($assign, $instance, $student1, $student2, $teacher, $g1, $g2) = $this->create_submission_for_testing_status(true);

// Grade the assign for the student1.
$this->setUser($teacher);

$data = new stdClass();
$data->grade = '50.0';
$data->assignfeedbackcomments_editor = ['text' => ''];
$assign->testable_apply_grade_to_user($data, $student1->id, 0);

$this->setUser($student1);

// Check that the student can see the grader by default.
$result = mod_assign_external::get_submission_status($assign->get_instance()->id);
// We expect debugging because of the $PAGE object, this won't happen in a normal WS request.
$this->assertDebuggingCalled();

$result = external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result);

$this->assertTrue(isset($result['feedback']));
$this->assertTrue(isset($result['feedback']['grade']));
$this->assertEquals($teacher->id, $result['feedback']['grade']['grader']);

// Now change the setting so the grader is hidden.
$this->setAdminUser();

$instance = $assign->get_instance();
$instance->instance = $instance->id;
$instance->hidegrader = true;
$assign->update_instance($instance);

$this->setUser($student1);

// Check that the student cannot see the grader anymore.
$result = mod_assign_external::get_submission_status($assign->get_instance()->id);
$result = external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result);

$this->assertTrue(isset($result['feedback']));
$this->assertTrue(isset($result['feedback']['grade']));
$this->assertEquals(-1, $result['feedback']['grade']['grader']);

// Check that the teacher can see the grader.
$this->setUser($teacher);

$result = mod_assign_external::get_submission_status($assign->get_instance()->id, $student1->id);
$result = external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result);

$this->assertTrue(isset($result['feedback']));
$this->assertTrue(isset($result['feedback']['grade']));
$this->assertEquals($teacher->id, $result['feedback']['grade']['grader']);
}

/**
* get_participant should throw an excaption if the requested assignment doesn't exist.
*
Expand Down

0 comments on commit 468ee73

Please sign in to comment.