3 * Unit tests for new Moodle Groups - groupinglib.php
5 * @copyright © 2006 The Open University
6 * @author N.D.Freear AT open.ac.uk
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
11 if (!defined('MOODLE_INTERNAL')) {
12 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
15 require_once($CFG->dirroot
. '/group/lib/groupinglib.php');
17 class groupinglib_test
extends UnitTestCase
{
24 function __construct() {
25 parent
::UnitTestCase();
28 function __destruct() {
29 //$this->tearDownOnce();
33 * setUp/tearDown: Better in a constructor/destructor, but PHP4 doesn't do destructors :(
38 if ($course = groups_get_course_info(1)) {
39 $this->courseid
= $course->id
;
41 if ($user = groups_get_user(2)) { //Primary admin.
42 $this->userid
= $user->id
;
45 $this->groupid
= groups_create_group($this->courseid
);
46 $groupinfo = groups_set_default_group_settings();
47 $bok = groups_set_group_settings($this->groupid
, $groupinfo);
48 $bok = groups_add_member($this->groupid
, $this->userid
);
54 $bok = groups_remove_member($this->groupid
, $this->userid
);
55 $bok = groups_delete_group($this->groupid
);
58 function test_create_grouping() {
59 $this->assertTrue($this->groupingid
= groups_create_grouping($this->courseid
));
60 $this->assertTrue(groups_grouping_exists($this->groupingid
));
61 $this->assertTrue(groups_grouping_belongs_to_course($this->groupingid
, $this->courseid
));
63 $this->assertTrue($groupinginfo = groups_set_default_grouping_settings());
64 $groupinginfo->name
= 'Grouping '. $this->getLabel();
65 $this->assertTrue(groups_set_grouping_settings($this->groupingid
, $groupinginfo));
68 function test_groups_grouping_matches(){
69 $groupinginfo->name
= 'Grouping Testname:' . $this->getLabel();
70 $groupinginfo->description
= 'Grouing Test Description:' . $this->getLabel();
72 $this->assertTrue($this->groupingid
= groups_create_grouping($this->courseid
, $groupinginfo));
73 $this->assertTrue(groups_grouping_matches($this->courseid
, $groupinginfo->name
, $groupinginfo->description
));
77 function test_add_group_to_grouping() {
78 $this->assertTrue(groups_add_group_to_grouping($this->groupid
, $this->groupingid
));
79 $this->assertTrue(groups_belongs_to_grouping($this->groupid
, $this->groupingid
));
81 $this->assertTrue($groupings = groups_get_groupings_for_group($this->groupid
));
83 $this->assertTrue($groups = groups_get_groups_in_grouping($this->groupingid
));
87 function test_remove_group_from_grouping() {
88 $this->assertTrue(groups_remove_group_from_grouping($this->groupid
, $this->groupingid
));
89 $this->assertFalse(groups_belongs_to_grouping($this->groupid
, $this->groupingid
));
92 function test_delete_grouping() {
93 $this->assertTrue(groups_delete_grouping($this->groupingid
));
94 $this->assertFalse(groups_grouping_exists($this->groupingid
));