From 78f753acea61ae4ee0d1115400371b8616b277bd Mon Sep 17 00:00:00 2001 From: sam marshall Date: Tue, 2 Sep 2014 12:53:20 +0100 Subject: [PATCH] MDL-44725 Availability: Replace groupmembersonly - feedback (16) There is one point where it restricted the list of users. I have fixed this and also altered the (only) script that calls that function so that it obtains a cm_info $cm rather than the old sort. There were previously no Behat tests at all in this module. In order to be confident that I didn't break it, I have implemented a Behat test (which should also be useful in general as it does go through other pages on the way to get to the relevant one). --- mod/feedback/lib.php | 7 +- mod/feedback/show_nonrespondents.php | 8 +- .../tests/behat/show_nonrespondents.feature | 80 +++++++++++++++++++ 3 files changed, 85 insertions(+), 10 deletions(-) create mode 100644 mod/feedback/tests/behat/show_nonrespondents.feature diff --git a/mod/feedback/lib.php b/mod/feedback/lib.php index 0176ec6aa36..68ab379674a 100644 --- a/mod/feedback/lib.php +++ b/mod/feedback/lib.php @@ -860,14 +860,14 @@ function feedback_check_is_switchrole() { * * @global object * @uses CONTEXT_MODULE - * @param object $cm + * @param cm_info $cm Course-module object * @param int $group single groupid * @param string $sort * @param int $startpage * @param int $pagecount * @return object the userrecords */ -function feedback_get_incomplete_users($cm, +function feedback_get_incomplete_users(cm_info $cm, $group = false, $sort = '', $startpage = false, @@ -892,7 +892,8 @@ function feedback_get_incomplete_users($cm, return false; } // Filter users that are not in the correct group/grouping. - $allusers = groups_filter_users_by_course_module_visible($cm, $allusers); + $info = new \core_availability\info_module($cm); + $allusers = $info->filter_user_list($allusers); $allusers = array_keys($allusers); diff --git a/mod/feedback/show_nonrespondents.php b/mod/feedback/show_nonrespondents.php index cbe74530939..1ed0250b5e1 100644 --- a/mod/feedback/show_nonrespondents.php +++ b/mod/feedback/show_nonrespondents.php @@ -43,14 +43,8 @@ $current_tab = 'nonrespondents'; //////////////////////////////////////////////////////// //get the objects //////////////////////////////////////////////////////// -if (! $cm = get_coursemodule_from_id('feedback', $id)) { - print_error('invalidcoursemodule'); -} - -if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { - print_error('coursemisconf'); -} +list ($course, $cm) = get_course_and_cm_from_cmid($id, 'feedback'); if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) { print_error('invalidcoursemodule'); } diff --git a/mod/feedback/tests/behat/show_nonrespondents.feature b/mod/feedback/tests/behat/show_nonrespondents.feature new file mode 100644 index 00000000000..9e8fd7d7279 --- /dev/null +++ b/mod/feedback/tests/behat/show_nonrespondents.feature @@ -0,0 +1,80 @@ +@mod @mod_feedback +Feature: Show users who have not responded to the feedback survey + In order to harass students about completing the feedback + As a teacher + I need to see which students haven't responded + + Background: + Given the following "users" exist: + | username | firstname | lastname | + | teacher1 | Teacher | 1 | + | student1 | Student | 1 | + | student2 | Student | 2 | + | student3 | Student | 3 | + And the following "courses" exist: + | fullname | shortname | + | Course 1 | C1 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + | student2 | C1 | student | + | student3 | C1 | student | + And the following "groups" exist: + | course | name | idnumber | + | C1 | G1 | GI1 | + And the following "group members" exist: + | user | group | + | student1 | GI1 | + | student2 | GI1 | + And the following "groupings" exist: + | name | course | idnumber | + | GX1 | C1 | GXI1 | + And the following "grouping groups" exist: + | grouping | group | + | GXI1 | GI1 | + And I log in as "admin" + And I set the following administration settings values: + | Enable conditional access | 1 | + And I navigate to "Manage activities" node in "Site administration > Plugins > Activity modules" + And I click on "Show" "link" in the "Feedback" "table_row" + And I log out + + @javascript + Scenario: See users who have not responded + # Set up a feedback. + When I log in as "teacher1" + And I follow "Course 1" + And I turn editing mode on + And I add a "Feedback" to section "1" and I fill the form with: + | Name | Frogs | + | Description | x | + | Record user names | User's name will be logged and shown with answers | + | Access restrictions | Grouping: GX1 | + And I follow "Frogs" + And I follow "Edit questions" + And I set the field "id_typ" to "Short text answer" + And I set the following fields to these values: + | Question | Y/N? | + And I press "Save question" + And I log out + + # Go in as student 1 and do the feedback. + And I log in as "student1" + And I follow "Course 1" + And I follow "Frogs" + And I follow "Answer the questions" + And I set the field "Y/N?" to "Y" + And I press "Submit your answers" + And I log out + + # Go in as teacher and check the users who haven't completed it. + And I log in as "teacher1" + And I follow "Course 1" + And I follow "Frogs" + And I follow "Show non-respondents" + + # Should only show student 2; not student 1 (they did it) or 3 (not in grouping). + Then I should see "Student 2" + And I should not see "Student 1" + And I should not see "Student 3"