Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [Versions 400 and 403] [Versions 401 and 403] [Versions 402 and 403]
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 gradereport_singleview; 18 19 use gradereport_singleview_screen_testable; 20 21 defined('MOODLE_INTERNAL') || die(); 22 23 global $CFG; 24 require_once (__DIR__ . '/fixtures/screen.php'); 25 require_once($CFG->libdir . '/gradelib.php'); 26 27 /** 28 * Tests for screen class. 29 * 30 * @package gradereport_singleview 31 * @category test 32 * @copyright 2014 onwards Simey Lameze <simey@moodle.com> 33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 34 */ 35 class screen_test extends \advanced_testcase { 36 37 /** 38 * Test load_users method. 39 */ 40 public function test_load_users() { 41 global $DB; 42 43 $this->setAdminUser(); 44 $this->resetAfterTest(true); 45 46 $roleteacher = $DB->get_record('role', ['shortname' => 'teacher'], '*', MUST_EXIST); 47 48 // Create a course, users and groups. 49 $course = $this->getDataGenerator()->create_course(); 50 $coursecontext = \context_course::instance($course->id); 51 $group = $this->getDataGenerator()->create_group(['courseid' => $course->id]); 52 $teacher = $this->getDataGenerator()->create_user(); 53 $user1 = $this->getDataGenerator()->create_user(); 54 $user2 = $this->getDataGenerator()->create_user(); 55 $this->getDataGenerator()->enrol_user($teacher->id, $course->id, $roleteacher->id); 56 $this->getDataGenerator()->enrol_user($user1->id, $course->id); 57 $this->getDataGenerator()->enrol_user($user2->id, $course->id); 58 $this->getDataGenerator()->create_group_member(['groupid' => $group->id, 'userid' => $teacher->id]); 59 $this->getDataGenerator()->create_group_member(['groupid' => $group->id, 'userid' => $user1->id]); 60 $this->getDataGenerator()->create_group_member(['groupid' => $group->id, 'userid' => $user2->id]); 61 62 // Perform a regrade before creating the report. 63 grade_regrade_final_grades($course->id); 64 $screentest = new gradereport_singleview_screen_testable($course->id, 0, $group->id); 65 $groupusers = $screentest->test_load_users(); 66 $this->assertDebuggingCalled('The function load_users() is deprecated. ' . 67 'Please use grade_report::get_gradable_users() instead.'); 68 $this->assertCount(2, $groupusers); 69 70 // Now, let's suspend the enrolment of a user. Should return only one user. 71 $this->getDataGenerator()->enrol_user($user2->id, $course->id, $roleteacher->id, 'manual', 0, 0, ENROL_USER_SUSPENDED); 72 $users = $screentest->test_load_users(); 73 $this->assertDebuggingCalled('The function load_users() is deprecated. ' . 74 'Please use grade_report::get_gradable_users() instead.'); 75 $this->assertCount(1, $users); 76 77 // Change the viewsuspendedusers capabilities and set the user preference to display suspended users. 78 assign_capability('moodle/course:viewsuspendedusers', CAP_ALLOW, $roleteacher->id, $coursecontext, true); 79 set_user_preference('grade_report_showonlyactiveenrol', false, $teacher); 80 accesslib_clear_all_caches_for_unit_testing(); 81 $this->setUser($teacher); 82 $screentest = new gradereport_singleview_screen_testable($course->id, 0, $group->id); 83 $users = $screentest->test_load_users(); 84 $this->assertDebuggingCalled('The function load_users() is deprecated. ' . 85 'Please use grade_report::get_gradable_users() instead.'); 86 $this->assertCount(2, $users); 87 88 // Change the capability again, now the user can't see the suspended enrolments. 89 assign_capability('moodle/course:viewsuspendedusers', CAP_PROHIBIT, $roleteacher->id, $coursecontext, true); 90 set_user_preference('grade_report_showonlyactiveenrol', false, $teacher); 91 accesslib_clear_all_caches_for_unit_testing(); 92 $users = $screentest->test_load_users(); 93 $this->assertDebuggingCalled('The function load_users() is deprecated. ' . 94 'Please use grade_report::get_gradable_users() instead.'); 95 $this->assertCount(1, $users); 96 97 // Now, activate the user enrolment again. We shall get 2 users now. 98 $this->getDataGenerator()->enrol_user($user2->id, $course->id, $roleteacher->id, 'manual', 0, 0, ENROL_USER_ACTIVE); 99 $users = $screentest->test_load_users(); 100 $this->assertDebuggingCalled('The function load_users() is deprecated. ' . 101 'Please use grade_report::get_gradable_users() instead.'); 102 $this->assertCount(2, $users); 103 } 104 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body