Skip to content

Commit

Permalink
CTP-4026 Add test coverage for newly supported activities
Browse files Browse the repository at this point in the history
  • Loading branch information
aydevworks committed Jan 17, 2025
1 parent 5bc69f9 commit 3555dc7
Show file tree
Hide file tree
Showing 9 changed files with 357 additions and 40 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:

services:
postgres:
image: postgres:13
image: postgres:14
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
Expand Down Expand Up @@ -81,6 +81,7 @@ jobs:
run: |
moodle-plugin-ci add-plugin -b main --clone https://aspark21:"$GHA_MOODLE_READ_ACCESS"@github.com/ucl-isd/moodle-block_portico_enrolments.git
moodle-plugin-ci add-plugin -b main --clone https://aspark21:"$GHA_MOODLE_READ_ACCESS"@github.com/ucl-isd/moodle-block_lifecycle.git
moodle-plugin-ci add-plugin -b main --clone https://aspark21:"$GHA_MOODLE_READ_ACCESS"@github.com/ucl-isd/moodle-mod_coursework.git
moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1
env:
DB: ${{ matrix.database }}
Expand Down
36 changes: 30 additions & 6 deletions tests/behat/behat_sitsgradepush.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,11 @@ public function map_source(string $sourcetype, string $sourcename, string $mabna
global $DB;
$manager = manager::get_manager();

$sourceexplode = explode('_', $sourcetype);

// Get the source.
$source = match ($sourcetype) {
'mod' => $DB->get_record(
'course_modules',
['idnumber' => $sourcename]
),
$source = match ($sourceexplode[0]) {
'mod' => $this->get_coursemodule($sourceexplode[1], $sourcename),
'gradeitem' => $DB->get_record(
'grade_items',
['idnumber' => $sourcename]
Expand All @@ -276,7 +275,7 @@ public function map_source(string $sourcetype, string $sourcename, string $mabna
$mab = $DB->get_record('local_sitsgradepush_mab', ['mabname' => $mabname]);

// Get the assessment.
$assessment = assessmentfactory::get_assessment($sourcetype, $source->id);
$assessment = assessmentfactory::get_assessment($sourceexplode[0], $source->id);

// Insert new mapping.
$record = new \stdClass();
Expand All @@ -294,6 +293,31 @@ public function map_source(string $sourcetype, string $sourcename, string $mabna
$DB->insert_record($manager::TABLE_ASSESSMENT_MAPPING, $record);
}

/**
* Get the course module.
*
* @param string $modulename
* @param string $sourcename
* @return object
* @throws \Exception
*/
public function get_coursemodule(string $modulename, string $sourcename ): mixed {
global $DB;

if($modulename == 'lti') {
$sql = "SELECT cm.id FROM {course_modules} cm JOIN {lti} lti ON cm.instance = lti.id WHERE lti.name = :sourcename";
$coursemodule = $DB->get_record_sql($sql, ['sourcename' => $sourcename]);
} else {
$coursemodule = $DB->get_record('course_modules', ['idnumber' => $sourcename]);
}

if (!$coursemodule) {
throw new Exception("Course module with module name '$modulename', source name '$sourcename' not found.");
}

return $coursemodule;
}

/**
* Re-grade the course.
*
Expand Down
139 changes: 119 additions & 20 deletions tests/behat/marks_transfer.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ Feature: Marks transfer from Moodle to SITS
| student3 | Student3 | Test | 23456783 | student3@example.com |
| teacher1 | Teacher1 | Test | tea1 | teacher1@example.com |
And the following custom field exists for grade push:
| category | CLC |
| category | CLC |
| shortname | course_year |
| name | Course Year |
| type | text |
And the following "courses" exist:
| fullname | shortname | format | customfield_course_year |
| Course 1 | C1 | topics | ##now##%Y## |
And the following "course enrolments" exist:
| user | course | role |
| student1 | C1 | student |
| student2 | C1 | student |
| student3 | C1 | student |
| user | course | role |
| student1 | C1 | student |
| student2 | C1 | student |
| student3 | C1 | student |
| teacher1 | C1 | editingteacher |
And the following "permission overrides" exist:
| capability | permission | role | contextlevel | reference |
Expand All @@ -35,15 +35,15 @@ Feature: Marks transfer from Moodle to SITS
@javascript
Scenario: Transfer marks for an assignment to SITS
Given the following "activities" exist:
| activity | name | intro | course | idnumber | section |
| assign | Assign 1 | A1 desc | C1 | assign1 | 1 |
| activity | name | intro | course | idnumber | section |
| assign | Assign 1 | A1 desc | C1 | assign1 | 1 |
And the following "mod_assign > submissions" exist:
| assign | user | onlinetext |
| assign1 | student1 | This is a submission for assignment |
| assign | user | onlinetext |
| assign1 | student1 | This is a submission for assignment |
And the following "grade grades" exist:
| gradeitem | user | grade |
| Assign 1 | student1 | 50 |
And the "mod" "assign1" is mapped to "72hr take-home examination (3000 words)"
| Assign 1 | student1 | 50 |
And the "mod_assign" "assign1" is mapped to "72hr take-home examination (3000 words)"
And I am on the "Course 1" course page logged in as teacher1
And I click on "More" "link" in the ".secondary-navigation" "css_element"
And I select "SITS Marks Transfer" from secondary navigation
Expand All @@ -58,8 +58,8 @@ Feature: Marks transfer from Moodle to SITS
@javascript
Scenario: Transfer marks for a quiz to SITS
Given the following "activities" exist:
| activity | name | intro | course | idnumber | section |
| quiz | Quiz 1 | Q1 desc | C1 | quiz1 | 1 |
| activity | name | intro | course | idnumber | section |
| quiz | Quiz 1 | Q1 desc | C1 | quiz1 | 1 |
And the following "question categories" exist:
| contextlevel | reference | name |
| Course | C1 | Test questions |
Expand All @@ -75,13 +75,13 @@ Feature: Marks transfer from Moodle to SITS
| TF2 | 1 | 50.0 |
And user "student1" has attempted "Quiz 1" with responses:
| slot | response |
| 2 | True |
| 3 | False |
| 2 | True |
| 3 | False |
And user "student2" has attempted "Quiz 1" with responses:
| slot | response |
| 2 | True |
| 3 | True |
And the "mod" "quiz1" is mapped to "72hr take-home examination (3000 words)"
| 2 | True |
| 3 | True |
And the "mod_quiz" "quiz1" is mapped to "72hr take-home examination (3000 words)"
And I am on the "Course 1" course page logged in as teacher1
And I click on "More" "link" in the ".secondary-navigation" "css_element"
And I select "SITS Marks Transfer" from secondary navigation
Expand All @@ -96,8 +96,8 @@ Feature: Marks transfer from Moodle to SITS
@javascript
Scenario: Transfer marks for a grade item to SITS
Given the following "grade items" exist:
| itemname | course | idnumber |
| Grade Item 1 | C1 | gradeitem1 |
| itemname | course | idnumber |
| Grade Item 1 | C1 | gradeitem1 |
And the following "grade grades" exist:
| gradeitem | user | grade |
| Grade Item 1 | student1 | 21.00 |
Expand Down Expand Up @@ -139,3 +139,102 @@ Feature: Marks transfer from Moodle to SITS
And I run all adhoc tasks
And I reload the page
Then I should see "0" marks to transfer for "72hr take-home examination (3000 words)"

@javascript @_file_upload
Scenario: Transfer marks for coursework to SITS
Given the "mod_coursework" plugin is installed
And the following "activities" exist:
| activity | name | intro | course | idnumber | section | allowearlyfinalisation | numberofmarkers |
| coursework | Coursework 1 | CW1 desc | C1 | coursework1 | 1 | 1 | 1 |
And the following "permission overrides" exist:
| capability | permission | role | contextlevel | reference |
| mod/coursework:publish | Allow | editingteacher | Course | C1 |
And I am on the "Course 1" course page logged in as student1
And I follow "Coursework 1"
And I press "Upload your submission"
And I upload "lib/tests/fixtures/empty.txt" file to "Upload a file" filemanager
And I press "Submit"
And I press "Finalise your submission"
And I press "Yes"
And I log out
And I am on the "Course 1" course page logged in as teacher1
And I follow "Coursework 1"
And I click on "Add final feedback" "link"
And I press "Save and finalise"
And I reload the page
And I press "Release all grades"
And I press "Continue"
And the "mod_coursework" "coursework1" is mapped to "72hr take-home examination (3000 words)"
And I am on the "Course 1" course page logged in as teacher1
And I click on "More" "link" in the ".secondary-navigation" "css_element"
And I select "SITS Marks Transfer" from secondary navigation
And I should see "1" marks to transfer for "72hr take-home examination (3000 words)"
And I click on the "Transfer marks" button for "72hr take-home examination (3000 words)"
And I press "Confirm"
And I run the scheduled task "\local_sitsgradepush\task\pushtask"
And I run all adhoc tasks
And I reload the page
Then I should see "0" marks to transfer for "72hr take-home examination (3000 words)"

@javascript
Scenario: Transfer marks for lesson to SITS
Given the following "activities" exist:
| activity | name | course | idnumber |
| lesson | Test lesson name | C1 | lesson1 |
And the following "mod_lesson > pages" exist:
| lesson | qtype | title | content |
| Test lesson name | truefalse | True/false question 1 | Paper is made from trees. |
| Test lesson name | truefalse | True/false question 2 | The sky is Pink. |
And the following "mod_lesson > answers" exist:
| page | answer | response | jumpto | score |
| True/false question 1 | True | Correct | Next page | 1 |
| True/false question 1 | False | Wrong | This page | 0 |
| True/false question 2 | False | Correct | Next page | 1 |
| True/false question 2 | True | Wrong | This page | 0 |
When I am on the "Test lesson name" "lesson activity" page logged in as student1
And I should see "Paper is made from trees."
And I set the following fields to these values:
| True | 1 |
And I press "Submit"
And I press "Continue"
And I should see "The sky is Pink."
And I set the following fields to these values:
| True | 1 |
And I press "Submit"
And I press "Continue"
And the "mod_lesson" "lesson1" is mapped to "72hr take-home examination (3000 words)"
And I am on the "Course 1" course page logged in as teacher1
And I click on "More" "link" in the ".secondary-navigation" "css_element"
And I select "SITS Marks Transfer" from secondary navigation
And I should see "1" marks to transfer for "72hr take-home examination (3000 words)"
And I click on the "Transfer marks" button for "72hr take-home examination (3000 words)"
And I press "Confirm"
And I run the scheduled task "\local_sitsgradepush\task\pushtask"
And I run all adhoc tasks
And I reload the page
Then I should see "0" marks to transfer for "72hr take-home examination (3000 words)"

@javascript
Scenario: Transfer marks for lti to SITS
Given the following "mod_lti > tool types" exist:
| name | baseurl | coursevisible | state |
| Teaching Tool 1 | /mod/lti/tests/fixtures/tool_provider.php | 2 | 1 |
And I am on the "Course 1" course page logged in as teacher1
And I turn editing mode on
And I add a "Teaching Tool 1" to section "1" using the activity chooser
And I set the field "Activity name" to "lti 1"
And I press "Save and return to course"
And I am on the "Course 1" "grades > Grader report > View" page
And I give the grade "90.00" to the user "Student1 Test" for the grade item "lti 1"
And I press "Save changes"
And the "mod_lti" "lti 1" is mapped to "72hr take-home examination (3000 words)"
And I am on the "Course 1" course page
And I click on "More" "link" in the ".secondary-navigation" "css_element"
And I select "SITS Marks Transfer" from secondary navigation
And I should see "1" marks to transfer for "72hr take-home examination (3000 words)"
And I click on the "Transfer marks" button for "72hr take-home examination (3000 words)"
And I press "Confirm"
And I run the scheduled task "\local_sitsgradepush\task\pushtask"
And I run all adhoc tasks
And I reload the page
Then I should see "0" marks to transfer for "72hr take-home examination (3000 words)"
4 changes: 2 additions & 2 deletions tests/behat/marks_transfer_all.feature
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Feature: Transfer all mapped sources from Moodle to SITS
And the following "grade grades" exist:
| gradeitem | user | grade |
| Assign 1 | student1 | 50 |
And the "mod" "assign1" is mapped to "72hr take-home examination (3000 words)"
And the "mod_assign" "assign1" is mapped to "72hr take-home examination (3000 words)"
And the following "activities" exist:
| activity | name | intro | course | idnumber | section |
| quiz | Quiz 1 | Q1 desc | C1 | quiz1 | 1 |
Expand All @@ -65,7 +65,7 @@ Feature: Transfer all mapped sources from Moodle to SITS
| slot | response |
| 2 | True |
| 3 | True |
And the "mod" "quiz1" is mapped to "2000 word essay"
And the "mod_quiz" "quiz1" is mapped to "2000 word essay"

@javascript
Scenario: Transfer all marks to SITS
Expand Down
Loading

0 comments on commit 3555dc7

Please sign in to comment.