[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 /** 18 * Cohort enrolment sync functional test. 19 * 20 * @package enrol_cohort 21 * @category test 22 * @copyright 2015 Adrian Greeve <adrian@moodle.com> 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 global $CFG; 29 require_once($CFG->dirroot.'/cohort/lib.php'); 30 require_once($CFG->dirroot.'/group/lib.php'); 31 32 /** 33 * Contains tests for the cohort library. 34 * 35 * @package enrol_cohort 36 * @copyright 2015 Adrian Greeve <adrian@moodle.com> 37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 38 */ 39 class enrol_cohort_lib_testcase extends advanced_testcase { 40 41 /** 42 * Test that a new group with the name of the cohort is created. 43 */ 44 public function test_enrol_cohort_create_new_group() { 45 global $DB; 46 $this->resetAfterTest(); 47 // Create a category. 48 $category = $this->getDataGenerator()->create_category(); 49 // Create two courses. 50 $course = $this->getDataGenerator()->create_course(array('category' => $category->id)); 51 $course2 = $this->getDataGenerator()->create_course(array('category' => $category->id)); 52 // Create a cohort. 53 $cohort = $this->getDataGenerator()->create_cohort(array('context' => context_coursecat::instance($category->id)->id)); 54 // Run the function. 55 $groupid = enrol_cohort_create_new_group($course->id, $cohort->id); 56 // Check the results. 57 $group = $DB->get_record('groups', array('id' => $groupid)); 58 // The group name should match the cohort name. 59 $this->assertEquals($cohort->name . ' cohort', $group->name); 60 // Group course id should match the course id. 61 $this->assertEquals($course->id, $group->courseid); 62 63 // Create a group that will have the same name as the cohort. 64 $groupdata = new stdClass(); 65 $groupdata->courseid = $course2->id; 66 $groupdata->name = $cohort->name . ' cohort'; 67 groups_create_group($groupdata); 68 // Create a group for the cohort in course 2. 69 $groupid = enrol_cohort_create_new_group($course2->id, $cohort->id); 70 $groupinfo = $DB->get_record('groups', array('id' => $groupid)); 71 // Check that the group name has been changed. 72 $this->assertEquals($cohort->name . ' cohort (2)', $groupinfo->name); 73 74 // Create another group that will have the same name as a generated cohort. 75 $groupdata = new stdClass(); 76 $groupdata->courseid = $course2->id; 77 $groupdata->name = $cohort->name . ' cohort (2)'; 78 groups_create_group($groupdata); 79 // Create a group for the cohort in course 2. 80 $groupid = enrol_cohort_create_new_group($course2->id, $cohort->id); 81 $groupinfo = $DB->get_record('groups', array('id' => $groupid)); 82 // Check that the group name has been changed. 83 $this->assertEquals($cohort->name . ' cohort (3)', $groupinfo->name); 84 85 } 86 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |