Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 11
Línea 44... Línea 44...
44
     * Create quiz and course for test
44
     * Create quiz and course for test
45
     *
45
     *
46
     * @return array containing quiz object and course
46
     * @return array containing quiz object and course
47
     */
47
     */
48
    private function create_quiz_and_course(): array {
48
    private function create_quiz_and_course(): array {
49
        $course = $this->getDataGenerator()->create_course(['groupmode' => SEPARATEGROUPS]);
49
        $course = $this->getDataGenerator()->create_course(['groupmode' => SEPARATEGROUPS, 'groupmodeforce' => 1]);
50
        $quizparams = array_merge(self::TEST_QUIZ_SETTINGS, ['course' => $course->id]);
50
        $quizparams = array_merge(self::TEST_QUIZ_SETTINGS, ['course' => $course->id]);
51
        $quiz = $this->getDataGenerator()->create_module('quiz', $quizparams);
51
        $quiz = $this->getDataGenerator()->create_module('quiz', $quizparams);
52
        $quizobj = quiz_settings::create($quiz->id);
52
        $quizobj = quiz_settings::create($quiz->id);
53
        return [$quizobj, $course];
53
        return [$quizobj, $course];
54
    }
54
    }
Línea 122... Línea 122...
122
            'groupid1' => $groupid,
122
            'groupid1' => $groupid,
123
        ];
123
        ];
124
    }
124
    }
Línea 125... Línea 125...
125
 
125
 
-
 
126
    /**
-
 
127
     * Data provider for {@see test_can_view_override}
-
 
128
     *
-
 
129
     * @return array[]
-
 
130
     */
-
 
131
    public static function can_view_override_provider(): array {
-
 
132
        return [
-
 
133
            ['admin', true, true, true, true],
-
 
134
            ['teacher', true, false, true, false],
-
 
135
        ];
-
 
136
    }
-
 
137
 
-
 
138
    /**
-
 
139
     * Test whether user can view given override
-
 
140
     *
-
 
141
     * @param string $currentuser
-
 
142
     * @param bool $grouponeview
-
 
143
     * @param bool $grouptwoview
-
 
144
     * @param bool $studentoneview
-
 
145
     * @param bool $studenttwoview
-
 
146
     *
-
 
147
     * @dataProvider can_view_override_provider
-
 
148
     */
-
 
149
    public function test_can_view_override(
-
 
150
        string $currentuser,
-
 
151
        bool $grouponeview,
-
 
152
        bool $grouptwoview,
-
 
153
        bool $studentoneview,
-
 
154
        bool $studenttwoview,
-
 
155
    ): void {
-
 
156
        global $DB;
-
 
157
 
-
 
158
        $this->resetAfterTest();
-
 
159
 
-
 
160
        [$quizobj, $course] = $this->create_quiz_and_course();
-
 
161
 
-
 
162
        // Teacher cannot view all groups.
-
 
163
        $roleid = $DB->get_field('role', 'id', ['shortname' => 'editingteacher']);
-
 
164
        assign_capability('moodle/site:accessallgroups', CAP_PROHIBIT, $roleid, $quizobj->get_context()->id);
-
 
165
 
-
 
166
        // Group one will contain our teacher and another student.
-
 
167
        $groupone = $this->getDataGenerator()->create_group(['courseid' => $course->id]);
-
 
168
        $teacher = $this->getDataGenerator()->create_and_enrol($course, 'editingteacher', ['username' => 'teacher']);
-
 
169
        $this->getDataGenerator()->create_group_member(['groupid' => $groupone->id, 'userid' => $teacher->id]);
-
 
170
        $studentone = $this->getDataGenerator()->create_and_enrol($course);
-
 
171
        $this->getDataGenerator()->create_group_member(['groupid' => $groupone->id, 'userid' => $studentone->id]);
-
 
172
 
-
 
173
        // Group two will contain a solitary student.
-
 
174
        $grouptwo = $this->getDataGenerator()->create_group(['courseid' => $course->id]);
-
 
175
        $studenttwo = $this->getDataGenerator()->create_and_enrol($course);
-
 
176
        $this->getDataGenerator()->create_group_member(['groupid' => $grouptwo->id, 'userid' => $studenttwo->id]);
-
 
177
 
-
 
178
        $user = \core_user::get_user_by_username($currentuser);
-
 
179
        $this->setUser($user);
-
 
180
 
-
 
181
        /** @var override_manager $manager */
-
 
182
        $manager = $quizobj->get_override_manager();
-
 
183
 
-
 
184
        $this->assertEquals($grouponeview, $manager->can_view_override(
-
 
185
            (object) ['groupid' => $groupone->id, 'userid' => null],
-
 
186
            $course,
-
 
187
            $quizobj->get_cm(),
-
 
188
        ));
-
 
189
 
-
 
190
        $this->assertEquals($grouptwoview, $manager->can_view_override(
-
 
191
            (object) ['groupid' => $grouptwo->id, 'userid' => null],
-
 
192
            $course,
-
 
193
            $quizobj->get_cm(),
-
 
194
        ));
-
 
195
 
-
 
196
        $this->assertEquals($studentoneview, $manager->can_view_override(
-
 
197
            (object) ['userid' => $studentone->id, 'groupid' => null],
-
 
198
            $course,
-
 
199
            $quizobj->get_cm(),
-
 
200
        ));
-
 
201
 
-
 
202
        $this->assertEquals($studenttwoview, $manager->can_view_override(
-
 
203
            (object) ['userid' => $studenttwo->id, 'groupid' => null],
-
 
204
            $course,
-
 
205
            $quizobj->get_cm(),
-
 
206
        ));
-
 
207
    }
-
 
208
 
126
    /**
209
    /**
127
     * Provides values to test_save_and_get_override
210
     * Provides values to test_save_and_get_override
128
     *
211
     *
129
     * @return array
212
     * @return array
130
     */
213
     */