Skip to content

Commit

Permalink
MDL-43926 Unit tests shouldn't assume only one category on install
Browse files Browse the repository at this point in the history
  • Loading branch information
timhunt committed Jan 31, 2014
1 parent 183515d commit e06bb5f
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/tests/coursecatlib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,16 +370,18 @@ public function test_get_children() {
* Test the countall function
*/
public function test_count_all() {
// There should be just the default category.
$this->assertEquals(1, coursecat::count_all());
global $DB;
// Dont assume there is just one. An add-on might create a category as part of the install.
$numcategories = $DB->count_records('course_categories');
$this->assertEquals($numcategories, coursecat::count_all());
$category1 = coursecat::create(array('name' => 'Cat1'));
$category2 = coursecat::create(array('name' => 'Cat2', 'parent' => $category1->id));
$category3 = coursecat::create(array('name' => 'Cat3', 'parent' => $category2->id, 'visible' => 0));
// Now we've got four.
$this->assertEquals(4, coursecat::count_all());
// Now we've got three more.
$this->assertEquals($numcategories + 3, coursecat::count_all());
cache_helper::purge_by_event('changesincoursecat');
// We should still have 4.
$this->assertEquals(4, coursecat::count_all());
$this->assertEquals($numcategories + 3, coursecat::count_all());
}

/**
Expand Down

0 comments on commit e06bb5f

Please sign in to comment.