diff --git a/mod/data/tests/behat/group_mode.feature b/mod/data/tests/behat/group_mode.feature new file mode 100644 index 0000000000000..ac3676dbf2100 --- /dev/null +++ b/mod/data/tests/behat/group_mode.feature @@ -0,0 +1,110 @@ +@mod @mod_data +Feature: Group data activity + In order to create a database with my group + As a student + I need to add and view entries for the groups I am a member of + + Background: + And the following "courses" exist: + | fullname | shortname | + | Test Course 1 | C1 | + And the following "groups" exist: + | name | course | idnumber | participation | + | Group 1 | C1 | G1 | 1 | + | Group 2 | C1 | G2 | 1 | + | Group 3 | C1 | G3 | 0 | + And the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | TeacherG1 | 1 | teacher1@example.com | + | user1 | User1G1 | 1 | user1@example.com | + | user2 | User2G2 | 2 | user2@example.com | + | user3 | User3None | 3 | user3@example.com | + | user4 | User4NPgroup | 4 | user4@example.com | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | user1 | C1 | student | + | user2 | C1 | student | + | user3 | C1 | student | + | user4 | C1 | student | + And the following "group members" exist: + | user | group | + | teacher1 | G1 | + | user1 | G1 | + | user2 | G2 | + | user4 | G3 | + And the following "activities" exist: + | activity | name | intro | course | idnumber | groupmode | + | data | Separate data | Data with separate groups | C1 | data1 | 1 | + | data | Visible data | Data with visible groups | C1 | data2 | 2 | + And the following "mod_data > fields" exist: + | database | type | name | + | data1 | shorttext | separatetext | + | data2 | shorttext | visibletext | + And the following "mod_data > entries" exist: + | database | user | group | separatetext | + | data1 | user1 | G1 | I am user 1 | + | data1 | user2 | G2 | I am user 2 | + And the following "mod_data > entries" exist: + | database | user | separatetext | + | data1 | user3 | I am user 3 | + And the following "mod_data > entries" exist: + | database | user | group | visibletext | + | data2 | user1 | G1 | I am user 1 | + | data2 | user2 | G2 | I am user 2 | + And the following "mod_data > entries" exist: + | database | user | visibletext | + | data2 | user3 | I am user 3 | + | data2 | user4 | I am user 4 | + + Scenario Outline: Users should see their own participation groups in "separate groups" mode, and all + participation groups in "visible groups" mode. + Given I am on the "" "data activity" page logged in as "" + Then I "All participants" + And I "Group 1" + And I "I am user 1" + And I "Group 2" + And I "I am user 2" + # All users should see entries with no group. + And I should see "I am user 3" + # No-one should see non-participation groups. + And I should not see "Group 3" + + Examples: + | data | user | all | G1 | G2 | user1 | user2 | + | data1 | teacher1 | should see | should see | should see | should see | should see | + | data1 | user1 | should not see | should see | should not see | should see | should not see | + | data1 | user2 | should not see | should not see | should see | should not see | should see | + | data1 | user3 | should see | should not see | should not see | should not see | should not see | + | data1 | user4 | should see | should not see | should not see | should not see | should not see | + | data2 | teacher1 | should see | should see | should see | should see | should see | + | data2 | user1 | should see | should see | should see | should see | should not see | + | data2 | user2 | should see | should see | should see | should not see | should see | + | data2 | user3 | should see | should see | should see | should see | should not see | + | data2 | user4 | should see | should see | should see | should see | should not see | + + Scenario Outline: When viewing a database in visible groups mode, + a user should only have the "Add entry" button for their own participation groups + Given I am on the "data2" "data activity" page logged in as "" + And I select "" from the "group" singleselect + And I should see "Add entry" + When I select "" from the "group" singleselect + Then I should not see "Add entry" + + Examples: + | user | mygroup | othergroup | + | user1 | Group 1 | Group 2 | + | user2 | Group 2 | Group 1 | + | user1 | All participants | Group 2 | + | user2 | All participants | Group 1 | + + Scenario Outline: Users in no groups or non-participation groups should not be able to add entries + Given I am on the "" "data activity" page logged in as "" + Then I should not see "Add entry" + + Examples: + | data | user | + | data1 | user3 | + | data1 | user4 | + | data2 | user3 | + | data2 | user4 | diff --git a/mod/data/tests/generator/behat_mod_data_generator.php b/mod/data/tests/generator/behat_mod_data_generator.php index a0191dca615f1..1fd84e97ffb3e 100644 --- a/mod/data/tests/generator/behat_mod_data_generator.php +++ b/mod/data/tests/generator/behat_mod_data_generator.php @@ -35,7 +35,7 @@ protected function get_creatable_entities(): array { 'singular' => 'entry', 'datagenerator' => 'entry', 'required' => ['database'], - 'switchids' => ['database' => 'databaseid', 'user' => 'userid'], + 'switchids' => ['database' => 'databaseid', 'user' => 'userid', 'group' => 'groupid'], ], 'fields' => [ 'singular' => 'field', @@ -86,6 +86,12 @@ public function process_entry(array $data): void { $userid = $data['userid']; unset($data['userid']); } + if (array_key_exists('groupid', $data)) { + $groupid = $data['groupid']; + unset($data['groupid']); + } else { + $groupid = 0; + } $data = array_reduce(array_keys($data), function ($fields, $fieldname) use ($data, $database) { global $DB; @@ -97,7 +103,7 @@ public function process_entry(array $data): void { return $fields; }, []); - $this->get_data_generator()->create_entry($database, $data, 0, [], null, $userid); + $this->get_data_generator()->create_entry($database, $data, $groupid, [], null, $userid); } /**