From: poltawski Date: Tue, 1 May 2007 12:03:45 +0000 (+0000) Subject: MDL-9660 - Fixed groups matches functions and added unit tests for them.. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=5fe855d1781fdfda6295b0794216eef8ec2bbd5c;p=moodle.git MDL-9660 - Fixed groups matches functions and added unit tests for them.. --- diff --git a/group/db/dbbasicgrouplib.php b/group/db/dbbasicgrouplib.php index c8ffb1e4f3..30faeade51 100644 --- a/group/db/dbbasicgrouplib.php +++ b/group/db/dbbasicgrouplib.php @@ -205,7 +205,7 @@ function groups_db_group_matches($courseid, $grp_name, $grp_description) { $records = get_records_sql($sql); $group = false; if ($records) { - $group = $records[0]; + $group = array_shift($records); } return $group; } diff --git a/group/lib/groupinglib.php b/group/lib/groupinglib.php index e741a5a50c..c882a8a95f 100644 --- a/group/lib/groupinglib.php +++ b/group/lib/groupinglib.php @@ -323,7 +323,7 @@ function groups_grouping_matches($courseid, $gg_name, $gg_description) { $records = get_records_sql($sql); $grouping = false; if ($records) { - $grouping = $records[0]; + $grouping = array_shift($records); } return $grouping; } diff --git a/group/simpletest/test_basicgrouplib.php b/group/simpletest/test_basicgrouplib.php index 74f029d35a..fb55d2e2fe 100644 --- a/group/simpletest/test_basicgrouplib.php +++ b/group/simpletest/test_basicgrouplib.php @@ -60,6 +60,15 @@ class basicgrouplib_test extends UnitTestCase { $this->assertTrue($this->courseid == groups_get_course($this->groupid)); } + function test_group_matches(){ + $groupinfo->name = 'Group Testname:' . $this->getLabel(); + $groupinfo->description = 'Group Test Description:' . $this->getLabel(); + + $this->assertTrue($this->groupid = groups_create_group($this->courseid, $groupinfo)); + $this->assertTrue(groups_group_matches($this->courseid, $groupinfo->name, $groupinfo->description)); + + } + function test_add_member() { // NOTE, interface change on add_member, remove_member. $this->assertTrue(groups_add_member($this->groupid, $this->userid)); @@ -82,4 +91,4 @@ class basicgrouplib_test extends UnitTestCase { } } -?> \ No newline at end of file +?> diff --git a/group/simpletest/test_groupinglib.php b/group/simpletest/test_groupinglib.php index 04881e6957..1cbf4d6e70 100644 --- a/group/simpletest/test_groupinglib.php +++ b/group/simpletest/test_groupinglib.php @@ -64,6 +64,15 @@ class groupinglib_test extends UnitTestCase { $this->assertTrue(groups_set_grouping_settings($this->groupingid, $groupinginfo)); } + function test_groups_grouping_matches(){ + $groupinginfo->name = 'Grouping Testname:' . $this->getLabel(); + $groupinginfo->description = 'Grouing Test Description:' . $this->getLabel(); + + $this->assertTrue($this->groupingid = groups_create_grouping($this->courseid, $groupinginfo)); + $this->assertTrue(groups_grouping_matches($this->courseid, $groupinginfo->name, $groupinginfo->description)); + + } + function test_add_group_to_grouping() { $this->assertTrue(groups_add_group_to_grouping($this->groupid, $this->groupingid)); $this->assertTrue(groups_belongs_to_grouping($this->groupid, $this->groupingid)); @@ -85,4 +94,4 @@ class groupinglib_test extends UnitTestCase { } } -?> \ No newline at end of file +?>