Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / group / simpletest / test_basicgrouplib.php
blob0a7960bdc95c842984ddb88102865662dc6efba9
1 <?php
2 /**
3 * Unit tests for new Moodle Groups - basicgrouplib.php and some of utillib.php.
4 *
5 * /admin/report/simpletest/index.php?showpasses=1&showsearch=1&path=course%2Fgroups
7 * @copyright &copy; 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
10 * @package groups
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 {
24 var $courseid= 0;
25 var $userid = 0;
26 var $userid_2= 0;
27 var $groupid = 0;
29 function __construct() {
30 parent::UnitTestCase();
33 function test_get_user() {
34 $this->assertTrue($user = groups_get_user(2)); //Primary admin.
35 if (isset($user)) {
36 $this->userid = $user->id;
38 $this->assertTrue($user_2 = groups_get_user(1)); //Guest.
39 if (isset($user_2)) {
40 $this->userid_2 = $user_2->id;
44 function test_get_course_info() {
45 $this->assertTrue($course = groups_get_course_info(1));
46 if (isset($course)) {
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));
56 //array...
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));
78 //...
79 $this->assertTrue($groupids= groups_get_groups_for_user($this->userid, $this->courseid));
80 //...
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));