MDL-10689:
[moodle-linuxchix.git] / group / simpletest / test_basicgrouplib.php
blob33ead9d9ff605d6bc6dd5ce3d3887a004425bc8a
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 //TODO: rewrite me
23 class basicgrouplib_test /*extends UnitTestCase*/ {
25 var $courseid= 0;
26 var $userid = 0;
27 var $userid_2= 0;
28 var $groupid = 0;
30 function __construct() {
31 parent::UnitTestCase();
34 function test_get_user() {
35 $this->assertTrue($user = groups_get_user(2)); //Primary admin.
36 if (isset($user)) {
37 $this->userid = $user->id;
39 $this->assertTrue($user_2 = groups_get_user(1)); //Guest.
40 if (isset($user_2)) {
41 $this->userid_2 = $user_2->id;
45 function test_get_course_info() {
46 $this->assertTrue($course = groups_get_course_info(1));
47 if (isset($course)) {
48 $this->courseid = $course->id;
52 function test_create_group() {
53 $this->assertTrue($this->groupid = groups_create_group($this->courseid));
54 $this->assertTrue(groups_group_exists($this->groupid));
55 $this->assertTrue(groups_group_belongs_to_course($this->groupid, $this->courseid));
56 $this->assertTrue($groupids = groups_get_groups($this->courseid));
57 //array...
58 $this->assertTrue($groupinfo = groups_set_default_group_settings());
59 $groupinfo->name = 'Group '. $this->getLabel(); //'Temporary Group Name'
60 $this->assertTrue(groups_set_group_settings($this->groupid, $groupinfo));
61 $this->assertTrue($groupinfo->name == groups_get_group_name($this->groupid));
62 $this->assertTrue($this->courseid == groups_get_course($this->groupid));
65 function test_group_matches(){
66 $groupinfo->name = 'Group Testname:' . $this->getLabel();
67 $groupinfo->description = 'Group Test Description:' . $this->getLabel();
69 $this->assertTrue($this->groupid = groups_create_group($this->courseid, $groupinfo));
70 $this->assertTrue(groups_group_matches($this->courseid, $groupinfo->name, $groupinfo->description));
74 function test_add_member() {
75 // NOTE, interface change on add_member, remove_member.
76 $this->assertTrue(groups_add_member($this->groupid, $this->userid));
77 $this->assertTrue(groups_is_member($this->groupid, $this->userid));
78 $this->assertTrue($userids = groups_get_members($this->groupid));
79 //...
80 $this->assertTrue($groupids= groups_get_groups_for_user($this->userid, $this->courseid));
81 //...
82 $this->assertTrue(1 == groups_count_group_members($this->groupid)); //Utillib.
85 function test_remove_member() {
86 $this->assertTrue(groups_remove_member($this->groupid, $this->userid));
87 $this->assertFalse(groups_is_member($this->groupid, $this->userid));
90 function test_delete_group() {
91 $this->assertTrue(groups_delete_group($this->groupid));
92 $this->assertFalse(groups_group_exists($this->groupid));