MDL-71325 grade: final removal of deprecated category external method.
This commit is contained in:
@@ -274,83 +274,4 @@ class grades_external_test extends \externallib_advanced_testcase {
|
||||
$grades = grade_get_grades($course->id, 'mod', 'assign', $assignment->id);
|
||||
$this->assertTrue($grades->items[0]->hidden == 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test create_gradecategory.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_create_gradecategory() {
|
||||
global $DB;
|
||||
$this->resetAfterTest(true);
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$this->setAdminUser();
|
||||
|
||||
// Test the most basic gradecategory creation.
|
||||
$status1 = core_grades_external::create_gradecategory($course->id, 'Test Category 1', []);
|
||||
|
||||
$courseparentcat = new \grade_category(['courseid' => $course->id, 'depth' => 1], true);
|
||||
$record1 = $DB->get_record('grade_categories', ['id' => $status1['categoryid']]);
|
||||
$this->assertEquals('Test Category 1', $record1->fullname);
|
||||
// Confirm that the parent category for this category is the top level category for the course.
|
||||
$this->assertEquals($courseparentcat->id, $record1->parent);
|
||||
$this->assertEquals(2, $record1->depth);
|
||||
|
||||
// Now create a category as a child of the newly created category.
|
||||
$status2 = core_grades_external::create_gradecategory($course->id, 'Test Category 2', ['parentcategoryid' => $record1->id]);
|
||||
$record2 = $DB->get_record('grade_categories', ['id' => $status2['categoryid']]);
|
||||
$this->assertEquals($record1->id, $record2->parent);
|
||||
$this->assertEquals(3, $record2->depth);
|
||||
// Check the path is correct.
|
||||
$this->assertEquals('/' . implode('/', [$courseparentcat->id, $record1->id, $record2->id]) . '/', $record2->path);
|
||||
|
||||
// Now create a category with some customised data and check the returns. This customises every value.
|
||||
$customopts = [
|
||||
'aggregation' => GRADE_AGGREGATE_MEAN,
|
||||
'aggregateonlygraded' => 0,
|
||||
'aggregateoutcomes' => 1,
|
||||
'droplow' => 1,
|
||||
'itemname' => 'item',
|
||||
'iteminfo' => 'info',
|
||||
'idnumber' => 'idnumber',
|
||||
'gradetype' => GRADE_TYPE_TEXT,
|
||||
'grademax' => 5,
|
||||
'grademin' => 2,
|
||||
'gradepass' => 3,
|
||||
'display' => GRADE_DISPLAY_TYPE_LETTER,
|
||||
// Hack. This must be -2 to use the default setting.
|
||||
'decimals' => 3,
|
||||
'hiddenuntil' => time(),
|
||||
'locktime' => time(),
|
||||
'weightoverride' => 1,
|
||||
'aggregationcoef2' => 20,
|
||||
'parentcategoryid' => $record2->id
|
||||
];
|
||||
|
||||
$status3 = core_grades_external::create_gradecategory($course->id, 'Test Category 3', $customopts);
|
||||
$cat3 = new \grade_category(['courseid' => $course->id, 'id' => $status3['categoryid']], true);
|
||||
$cat3->load_grade_item();
|
||||
|
||||
// Lets check all of the data is in the right shape.
|
||||
$this->assertEquals(GRADE_AGGREGATE_MEAN, $cat3->aggregation);
|
||||
$this->assertEquals(0, $cat3->aggregateonlygraded);
|
||||
$this->assertEquals(1, $cat3->aggregateoutcomes);
|
||||
$this->assertEquals(1, $cat3->droplow);
|
||||
$this->assertEquals('item', $cat3->grade_item->itemname);
|
||||
$this->assertEquals('info', $cat3->grade_item->iteminfo);
|
||||
$this->assertEquals('idnumber', $cat3->grade_item->idnumber);
|
||||
$this->assertEquals(GRADE_TYPE_TEXT, $cat3->grade_item->gradetype);
|
||||
$this->assertEquals(5, $cat3->grade_item->grademax);
|
||||
$this->assertEquals(2, $cat3->grade_item->grademin);
|
||||
$this->assertEquals(3, $cat3->grade_item->gradepass);
|
||||
$this->assertEquals(GRADE_DISPLAY_TYPE_LETTER, $cat3->grade_item->display);
|
||||
$this->assertEquals(3, $cat3->grade_item->decimals);
|
||||
$this->assertGreaterThanOrEqual($cat3->grade_item->hidden, time());
|
||||
$this->assertGreaterThanOrEqual($cat3->grade_item->locktime, time());
|
||||
$this->assertEquals(1, $cat3->grade_item->weightoverride);
|
||||
// Coefficient is converted to percentage.
|
||||
$this->assertEquals(0.2, $cat3->grade_item->aggregationcoef2);
|
||||
$this->assertEquals($record2->id, $cat3->parent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user