Línea 27... |
Línea 27... |
27 |
*
|
27 |
*
|
28 |
* @package mod_data
|
28 |
* @package mod_data
|
29 |
* @copyright 2022 Laurent David <laurent.david@moodle.com>
|
29 |
* @copyright 2022 Laurent David <laurent.david@moodle.com>
|
30 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
30 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
31 |
*/
|
31 |
*/
|
32 |
class locallib_test extends \advanced_testcase {
|
32 |
final class locallib_test extends \advanced_testcase {
|
Línea 33... |
Línea 33... |
33 |
|
33 |
|
34 |
/**
|
34 |
/**
|
35 |
* Confirms that search is working
|
35 |
* Confirms that search is working
|
36 |
* @covers ::data_search_entries
|
36 |
* @covers ::data_search_entries
|
Línea 95... |
Línea 95... |
95 |
$this->assertCount(1, $records);
|
95 |
$this->assertCount(1, $records);
|
96 |
$this->assert_record_entries_contains($records, $captionfield->field->id, 'caption');
|
96 |
$this->assert_record_entries_contains($records, $captionfield->field->id, 'caption');
|
97 |
}
|
97 |
}
|
Línea 98... |
Línea 98... |
98 |
|
98 |
|
- |
|
99 |
/**
|
- |
|
100 |
* Confirms that search is working with groups
|
- |
|
101 |
* @covers ::data_search_entries
|
- |
|
102 |
*/
|
- |
|
103 |
public function test_data_search_entries_with_groups(): void {
|
- |
|
104 |
$this->resetAfterTest();
|
- |
|
105 |
$this->setAdminUser();
|
- |
|
106 |
$course = $this->getDataGenerator()->create_course(['groupmode' => SEPARATEGROUPS, 'groupmodeforce' => 1]);
|
- |
|
107 |
$group1 = $this->getDataGenerator()->create_group(['courseid' => $course->id]);
|
- |
|
108 |
$group2 = $this->getDataGenerator()->create_group(['courseid' => $course->id]);
|
- |
|
109 |
$student1 = $this->getDataGenerator()->create_and_enrol($course);
|
- |
|
110 |
$student2 = $this->getDataGenerator()->create_and_enrol($course);
|
- |
|
111 |
$student3 = $this->getDataGenerator()->create_and_enrol($course);
|
- |
|
112 |
$teacher1 = $this->getDataGenerator()->create_and_enrol($course, 'teacher');
|
- |
|
113 |
$teacher2 = $this->getDataGenerator()->create_and_enrol($course, 'teacher');
|
- |
|
114 |
$teacher3 = $this->getDataGenerator()->create_and_enrol($course, 'teacher');
|
- |
|
115 |
groups_add_member($group1->id, $student1->id);
|
- |
|
116 |
groups_add_member($group1->id, $teacher1->id);
|
- |
|
117 |
groups_add_member($group2->id, $student3->id);
|
- |
|
118 |
groups_add_member($group2->id, $teacher3->id);
|
- |
|
119 |
|
- |
|
120 |
$record = new \stdClass();
|
- |
|
121 |
$record->course = $course->id;
|
- |
|
122 |
$record->name = "Mod data delete test";
|
- |
|
123 |
$record->intro = "Some intro of some sort";
|
- |
|
124 |
$module = $this->getDataGenerator()->create_module('data', $record);
|
- |
|
125 |
$titlefield = $this->getDataGenerator()->get_plugin_generator('mod_data')->create_field(
|
- |
|
126 |
(object) [
|
- |
|
127 |
'name' => 'title',
|
- |
|
128 |
'type' => 'text',
|
- |
|
129 |
'required' => 1,
|
- |
|
130 |
],
|
- |
|
131 |
$module);
|
- |
|
132 |
$captionfield = $this->getDataGenerator()->get_plugin_generator('mod_data')->create_field(
|
- |
|
133 |
(object) [
|
- |
|
134 |
'name' => 'caption',
|
- |
|
135 |
'type' => 'text',
|
- |
|
136 |
'required' => 1,
|
- |
|
137 |
],
|
- |
|
138 |
$module);
|
- |
|
139 |
$this->getDataGenerator()->get_plugin_generator('mod_data')->create_entry($module, [
|
- |
|
140 |
$titlefield->field->id => 'Entry 1 - group 1',
|
- |
|
141 |
$captionfield->field->id => 'caption',
|
- |
|
142 |
],
|
- |
|
143 |
$group1->id,
|
- |
|
144 |
[],
|
- |
|
145 |
null,
|
- |
|
146 |
$student1->id
|
- |
|
147 |
);
|
- |
|
148 |
$this->getDataGenerator()->get_plugin_generator('mod_data')->create_entry($module, [
|
- |
|
149 |
$titlefield->field->id => 'Entry 2 - group 1',
|
- |
|
150 |
$captionfield->field->id => 'caption',
|
- |
|
151 |
],
|
- |
|
152 |
$group1->id,
|
- |
|
153 |
[],
|
- |
|
154 |
null,
|
- |
|
155 |
$student1->id
|
- |
|
156 |
);
|
- |
|
157 |
$this->getDataGenerator()->get_plugin_generator('mod_data')->create_entry($module, [
|
- |
|
158 |
$titlefield->field->id => 'Entry 3 - group 2',
|
- |
|
159 |
$captionfield->field->id => '',
|
- |
|
160 |
],
|
- |
|
161 |
$group2->id,
|
- |
|
162 |
[],
|
- |
|
163 |
null,
|
- |
|
164 |
$student3->id
|
- |
|
165 |
);
|
- |
|
166 |
$this->getDataGenerator()->get_plugin_generator('mod_data')->create_entry($module, [
|
- |
|
167 |
$titlefield->field->id => 'Entry 3 - no group',
|
- |
|
168 |
$captionfield->field->id => '',
|
- |
|
169 |
],
|
- |
|
170 |
0,
|
- |
|
171 |
[],
|
- |
|
172 |
null,
|
- |
|
173 |
$student2->id
|
- |
|
174 |
);
|
- |
|
175 |
$cm = get_coursemodule_from_id('data', $module->cmid);
|
- |
|
176 |
$this->setUser($teacher1);
|
- |
|
177 |
// As a non editing teacher in group 1, I should see only the entries for group 1.
|
- |
|
178 |
list($records, $maxcount, $totalcount, $page, $nowperpage, $sort, $mode) =
|
- |
|
179 |
data_search_entries($module, $cm, \context_course::instance($course->id), 'list', $group1->id);
|
- |
|
180 |
$this->assertCount(3, $records); // Record with group 1 and record with no group.
|
- |
|
181 |
// As a non editing teacher not in a group, I should see the entry from users not in a group.
|
- |
|
182 |
$this->setUser($teacher3);
|
- |
|
183 |
list($records, $maxcount, $totalcount, $page, $nowperpage, $sort, $mode) =
|
- |
|
184 |
data_search_entries($module, $cm, \context_course::instance($course->id), 'list', $group2->id);
|
- |
|
185 |
$this->assertCount(2, $records); // Record with group 2 and record with no group.
|
- |
|
186 |
// As a non editing teacher not in a group, I should see the entry from users not in a group.
|
- |
|
187 |
$this->setUser($teacher2);
|
- |
|
188 |
list($records, $maxcount, $totalcount, $page, $nowperpage, $sort, $mode) =
|
- |
|
189 |
data_search_entries($module, $cm, \context_course::instance($course->id), 'list', 0);
|
- |
|
190 |
$this->assertCount(1, $records); // Just the record with no group.
|
- |
|
191 |
$this->assert_record_entries_contains($records, $titlefield->field->id, 'Entry 3 - no group');
|
- |
|
192 |
}
|
- |
|
193 |
|
99 |
/**
|
194 |
/**
|
100 |
* Assert that all records contains a value for the matching field id.
|
195 |
* Assert that all records contains a value for the matching field id.
|
101 |
*
|
196 |
*
|
102 |
* @param array $records
|
197 |
* @param array $records
|
103 |
* @param int $fieldid
|
198 |
* @param int $fieldid
|