3 * Unit tests for new Moodle Groups - basicgrouplib.php and some of utillib.php.
5 * /admin/report/simpletest/index.php?showpasses=1&showsearch=1&path=course%2Fgroups
7 * @copyright © 2006 The Open University
8 * @author N.D.Freear AT open.ac.uk
9 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
12 * Window - Preferences - PHPeclipse - PHP - Code Templates
15 if (!defined('MOODLE_INTERNAL')) {
16 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
19 require_once($CFG->dirroot
. '/group/lib/basicgrouplib.php');
20 require_once($CFG->dirroot
. '/group/lib/utillib.php');
22 class basicgrouplib_test
extends UnitTestCase
{
29 function __construct() {
30 parent
::UnitTestCase();
33 function test_get_user() {
34 $this->assertTrue($user = groups_get_user(2)); //Primary admin.
36 $this->userid
= $user->id
;
38 $this->assertTrue($user_2 = groups_get_user(1)); //Guest.
40 $this->userid_2
= $user_2->id
;
44 function test_get_course_info() {
45 $this->assertTrue($course = groups_get_course_info(1));
47 $this->courseid
= $course->id
;
51 function test_create_group() {
52 $this->assertTrue($this->groupid
= groups_create_group($this->courseid
));
53 $this->assertTrue(groups_group_exists($this->groupid
));
54 $this->assertTrue(groups_group_belongs_to_course($this->groupid
, $this->courseid
));
55 $this->assertTrue($groupids = groups_get_groups($this->courseid
));
57 $this->assertTrue($groupinfo = groups_set_default_group_settings());
58 $groupinfo->name
= 'Group '. $this->getLabel(); //'Temporary Group Name'
59 $this->assertTrue(groups_set_group_settings($this->groupid
, $groupinfo));
60 $this->assertTrue($groupinfo->name
== groups_get_group_name($this->groupid
));
61 $this->assertTrue($this->courseid
== groups_get_course($this->groupid
));
64 function test_group_matches(){
65 $groupinfo->name
= 'Group Testname:' . $this->getLabel();
66 $groupinfo->description
= 'Group Test Description:' . $this->getLabel();
68 $this->assertTrue($this->groupid
= groups_create_group($this->courseid
, $groupinfo));
69 $this->assertTrue(groups_group_matches($this->courseid
, $groupinfo->name
, $groupinfo->description
));
73 function test_add_member() {
74 // NOTE, interface change on add_member, remove_member.
75 $this->assertTrue(groups_add_member($this->groupid
, $this->userid
));
76 $this->assertTrue(groups_is_member($this->groupid
, $this->userid
));
77 $this->assertTrue($userids = groups_get_members($this->groupid
));
79 $this->assertTrue($groupids= groups_get_groups_for_user($this->userid
, $this->courseid
));
81 $this->assertTrue(1 == groups_count_group_members($this->groupid
)); //Utillib.
84 function test_remove_member() {
85 $this->assertTrue(groups_remove_member($this->groupid
, $this->userid
));
86 $this->assertFalse(groups_is_member($this->groupid
, $this->userid
));
89 function test_delete_group() {
90 $this->assertTrue(groups_delete_group($this->groupid
));
91 $this->assertFalse(groups_group_exists($this->groupid
));