This should be tested by running the test class mod_assign_external_testcase in mod/assign/tests/externallib_test.php. It can be run in phpunit with the following command:
phpunit mod_assign_external_testcase mod/assign/tests/externallib_test.php
|
This command will run tests test_get_user_flags() and test_get_user_mappings() in addition to tests for other functions. All tests must pass.
A manual test can also be run for each function if preferrred:
mod_assign_get_user_flags
=========================
- Create a new assignment in a course. Note the id of the assignment in the database assign table.
- Enrol a teacher and students into the course.
- In the assignment "grade" settings, set "Use marking workflow" and "Use marking allocation" to Yes
- In the student submissions list, select a student and set their workflow state to "In marking" and the allocated marker to the name of the teacher
- Note the id of the teacher and the student in the database user table
Following the instructions within Moodle, create a REST web service and add the function mod_assign_get_user_flags. Give the teacher the capabilities as described in the Web Services Overview -> Users as clients with token.
Login as the teacher and create/obtain their security key
Use the Moodle local Web service template plugin to call the web service function. The client.php file should be as shown below:
client.php
|
$token = 'f4458487f63c0558484f4505d61f1245'; // the teachers security key
|
$domainname = 'http://localhost/moodledev'; // the Moodle server
|
$functionname = 'mod_assign_get_user_flags'; // the web service function we are testing
|
$assignmentids[] = 1; // the assignment id
|
$params = array('assignmentids'=>$assignmentids); // the parameters
|
// The REST web service call
|
header('Content-Type: text/plain');
|
$serverurl = $domainname . '/webservice/rest/server.php'. '?wstoken=' . $token. '&wsfunction='.$functionname;
|
require_once('./curl.php');
|
$curl = new curl;
|
$resp = $curl->post($serverurl, $params);
|
print_r($resp);
|
Verify the results by searching for the assignmentid. Nested inside this element you should find an element representing a record in the user_flags database table with a userid for the selected student. This element must have workflowstate - "inmarking" and allocatedmarker that is the id of the teacher.
mod_assign_get_user_mappings
=========================
- Create a new assignment in a course. Note the id of the assignment in the database assign table.
- Enrol a teacher and students into the course.
- In the assignment "grade" settings, set "Blind marking" to Yes
- Note the user id of the students in the database user table
- Select "View/grade all submissions". You should see the students listed as "ParticipantId". Id represents the id of the mapping record in the assign_user_mapping table
Following the instructions within Moodle, create a REST web service and add the function mod_assign_get_user_mappings. Give the teacher the capabilities as described in the Web Services Overview -> Users as clients with token.
Login as the teacher and create/obtain their security key
Use the Moodle local Web service template plugin to call the web service function. The client.php file should be as shown below:
client.php
|
$token = 'f4458487f63c0558484f4505d61f1245'; // the teachers security key
|
$domainname = 'http://localhost/moodledev'; // the Moodle server
|
$functionname = 'mod_assign_get_user_mappings'; // the web service function we are testing
|
$assignmentids[] = 1; // the assignment id
|
$params = array('assignmentids'=>$assignmentids); // the parameters
|
// The REST web service call
|
header('Content-Type: text/plain');
|
$serverurl = $domainname . '/webservice/rest/server.php'. '?wstoken=' . $token. '&wsfunction='.$functionname;
|
require_once('./curl.php');
|
$curl = new curl;
|
$resp = $curl->post($serverurl, $params);
|
print_r($resp);
|
Verify the results by searching for the assignmentid. There should be an associated list of "mappings". There should be a mapping for each student.