Skip to content

Commit

Permalink
MDL-10078 unit tests for grade category failing on set_as_parent()
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Jun 10, 2007
1 parent 1898cca commit 9f9afbd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 9 additions & 10 deletions lib/grade/grade_category.php
Expand Up @@ -750,22 +750,26 @@ function set_as_parent($children) {
// Check type and sortorder of first child
$first_child = current($children);
$first_child_type = get_class($first_child);
$first_child_courseid = $first_child->courseid;

// If this->courseid is not set, set it to the first child's courseid
if (empty($this->courseid)) {
$this->courseid = $first_child->courseid;
}

$grade_tree = new grade_tree();

foreach ($children as $child) {
if (get_class($child) != $first_child_type) {
debugging("Violated constraint: Attempted to set a category as a parent over children of 2 different types.");
return false;
}

$grade_tree = new grade_tree();

if ($grade_tree->get_element_type($child) == 'topcat') {
debugging("Violated constraint: Attempted to set a category over children which are already top categories.");
return false;
}

if ($first_child_type == 'grade_category') {
if ($first_child_type == 'grade_category' or $first_child_type == 'grade_item') {
if (!empty($child->parent)) {
debugging("Violated constraint: Attempted to set a category over children that already have a top category.");
return false;
Expand All @@ -775,7 +779,7 @@ function set_as_parent($children) {
return false;
}

if ($child->courseid != $first_child_courseid) {
if ($child->courseid != $this->courseid) {
debugging("Attempted to set a category over children which do not belong to the same course.");
return false;
}
Expand All @@ -795,11 +799,6 @@ function set_as_parent($children) {
$this->load_grade_item();
$this->grade_item->sortorder = $first_child->get_sortorder();

// If this->courseid is not set, set it to the first child's courseid
if (empty($this->courseid)) {
$this->courseid = $first_child_courseid;
}

if (!$this->update()) {
debugging("Could not update this category's sortorder in DB.");
return false;
Expand Down
2 changes: 2 additions & 0 deletions lib/simpletest/grade/simpletest/testgradecategory.php
Expand Up @@ -262,6 +262,8 @@ function test_grade_category_set_as_parent() {
$child2->itemname = 'new grade_item';
$child1->sortorder = 1;
$child2->sortorder = 2;
$child1->courseid = $grade_category->courseid;
$child2->courseid = $grade_category->courseid;
$child1->insert();
$child2->insert();
$this->assertTrue($grade_category->set_as_parent(array($child1, $child2)));
Expand Down

0 comments on commit 9f9afbd

Please sign in to comment.