1441 |
ariadna |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
namespace mod_feedback;
|
|
|
18 |
|
|
|
19 |
use advanced_testcase;
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* Class for unit testing mod_feedback\dates.
|
|
|
23 |
*
|
|
|
24 |
* @category test
|
|
|
25 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
26 |
* @copyright 2025 Laurent David <laurent.david@moodle.com>
|
|
|
27 |
* @package mod_feedback
|
|
|
28 |
* @covers \mod_feedback\manager
|
|
|
29 |
*/
|
|
|
30 |
final class manager_test extends advanced_testcase {
|
|
|
31 |
/**
|
|
|
32 |
* Data provider for test_can_see_others_in_groups.
|
|
|
33 |
*
|
|
|
34 |
* @return array[]
|
|
|
35 |
*/
|
|
|
36 |
public static function can_see_others_in_groups_provider(): array {
|
|
|
37 |
return [
|
|
|
38 |
'student no groups, separate group' => [
|
|
|
39 |
'mode' => SEPARATEGROUPS, 'username' => 's1', 'expected' => false,
|
|
|
40 |
],
|
|
|
41 |
'student in groups, separate group' => [
|
|
|
42 |
'mode' => SEPARATEGROUPS, 'username' => 's2', 'expected' => true,
|
|
|
43 |
],
|
|
|
44 |
'non editing teacher no groups, separate group' => [
|
|
|
45 |
'mode' => SEPARATEGROUPS, 'username' => 't1', 'expected' => false,
|
|
|
46 |
],
|
|
|
47 |
'non editing teacher in groups, separate group' => [
|
|
|
48 |
'mode' => SEPARATEGROUPS, 'username' => 't2', 'expected' => true,
|
|
|
49 |
],
|
|
|
50 |
'editing teacher no groups, separate group' => [
|
|
|
51 |
'mode' => SEPARATEGROUPS, 'username' => 't3', 'expected' => true,
|
|
|
52 |
],
|
|
|
53 |
'editing teacher in groups, separate group' => [
|
|
|
54 |
'mode' => SEPARATEGROUPS, 'username' => 't4', 'expected' => true,
|
|
|
55 |
],
|
|
|
56 |
'student no groups, visible group' => [
|
|
|
57 |
'mode' => VISIBLEGROUPS, 'username' => 's1', 'expected' => true,
|
|
|
58 |
],
|
|
|
59 |
'student in groups, visible group' => [
|
|
|
60 |
'mode' => VISIBLEGROUPS, 'username' => 's2', 'expected' => true,
|
|
|
61 |
],
|
|
|
62 |
'non editing teacher no groups, visible group' => [
|
|
|
63 |
'mode' => VISIBLEGROUPS, 'username' => 't1', 'expected' => true,
|
|
|
64 |
],
|
|
|
65 |
'non editing teacher in groups, visible group' => [
|
|
|
66 |
'mode' => VISIBLEGROUPS, 'username' => 't2', 'expected' => true,
|
|
|
67 |
],
|
|
|
68 |
'editing teacher no groups, visible group' => [
|
|
|
69 |
'mode' => VISIBLEGROUPS, 'username' => 't3', 'expected' => true,
|
|
|
70 |
],
|
|
|
71 |
'editing teacher in groups, visible group' => [
|
|
|
72 |
'mode' => VISIBLEGROUPS, 'username' => 't4', 'expected' => true,
|
|
|
73 |
],
|
|
|
74 |
];
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
/**
|
|
|
78 |
* Test if we can see or not others in groups.
|
|
|
79 |
*
|
|
|
80 |
* @param int $mode The group mode.
|
|
|
81 |
* @param string $username The username of the user to test.
|
|
|
82 |
* @param bool $expected The expected result.
|
|
|
83 |
*
|
|
|
84 |
* @covers ::can_see_others_in_groups
|
|
|
85 |
* @dataProvider can_see_others_in_groups_provider
|
|
|
86 |
*/
|
|
|
87 |
public function test_can_see_others_in_groups(int $mode, string $username, bool $expected): void {
|
|
|
88 |
$this->resetAfterTest();
|
|
|
89 |
|
|
|
90 |
$course = $this->getDataGenerator()->create_course(['groupmode' => $mode, 'groupmodeforce' => 1]);
|
|
|
91 |
$group = $this->getDataGenerator()->create_group(['courseid' => $course->id, 'name' => 'Group 1']);
|
|
|
92 |
$users = [];
|
|
|
93 |
$data = [
|
|
|
94 |
's1' => 'student',
|
|
|
95 |
's2' => 'student',
|
|
|
96 |
't1' => 'teacher',
|
|
|
97 |
't2' => 'teacher',
|
|
|
98 |
't3' => 'editingteacher',
|
|
|
99 |
't4' => 'editingteacher',
|
|
|
100 |
];
|
|
|
101 |
foreach ($data as $user => $role) {
|
|
|
102 |
$users[$user] = $this->getDataGenerator()->create_and_enrol($course, $role, $user);
|
|
|
103 |
}
|
|
|
104 |
foreach (['s2', 't2', 't3'] as $uname) {
|
|
|
105 |
$user = $users[$uname];
|
|
|
106 |
$this->getDataGenerator()->create_group_member(
|
|
|
107 |
['groupid' => $group->id, 'userid' => $user->id]
|
|
|
108 |
);
|
|
|
109 |
}
|
|
|
110 |
$feedback = $this->getDataGenerator()->create_module('feedback', ['course' => $course]);
|
|
|
111 |
$this->setUser($users[$username]);
|
|
|
112 |
$cm = get_fast_modinfo($course)->cms[$feedback->cmid];
|
|
|
113 |
$this->assertEquals($expected, manager::can_see_others_in_groups($cm));
|
|
|
114 |
}
|
|
|
115 |
}
|