⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testgradecategory.php

📁 很棒的在线教学系统
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php // $Id: testgradecategory.php,v 1.7.2.2 2008/03/06 13:44:47 nicolasconnault Exp $/////////////////////////////////////////////////////////////////////////////                                                                       //// NOTICE OF COPYRIGHT                                                   ////                                                                       //// Moodle - Modular Object-Oriented Dynamic Learning Environment         ////          http://moodle.org                                            ////                                                                       //// Copyright (C) 1999 onwards Martin Dougiamas  http://dougiamas.com     ////                                                                       //// This program is free software; you can redistribute it and/or modify  //// it under the terms of the GNU General Public License as published by  //// the Free Software Foundation; either version 2 of the License, or     //// (at your option) any later version.                                   ////                                                                       //// This program is distributed in the hope that it will be useful,       //// but WITHOUT ANY WARRANTY; without even the implied warranty of        //// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //// GNU General Public License for more details:                          ////                                                                       ////          http://www.gnu.org/copyleft/gpl.html                         ////                                                                       //////////////////////////////////////////////////////////////////////////////** * Unit tests for grade_category object. * * @author nicolas@moodle.com * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @package moodlecore */if (!defined('MOODLE_INTERNAL')) {    die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page}require_once($CFG->libdir.'/simpletest/fixtures/gradetest.php');class grade_category_test extends grade_test {    function test_grade_category_construct() {        $course_category = grade_category::fetch_course_category($this->courseid);        $params = new stdClass();        $params->courseid = $this->courseid;        $params->fullname = 'unittestcategory4';        $grade_category = new grade_category($params, false);        $grade_category->insert();        $this->assertEqual($params->courseid, $grade_category->courseid);        $this->assertEqual($params->fullname, $grade_category->fullname);        $this->assertEqual(2, $grade_category->depth);        $this->assertEqual("/$course_category->id/$grade_category->id/", $grade_category->path);        $parentpath = $grade_category->path;        // Test a child category        $params->parent = $grade_category->id;        $params->fullname = 'unittestcategory5';        $grade_category = new grade_category($params, false);        $grade_category->insert();        $this->assertEqual(3, $grade_category->depth);        $this->assertEqual($parentpath.$grade_category->id."/", $grade_category->path);        $parentpath = $grade_category->path;        // Test a third depth category        $params->parent = $grade_category->id;        $params->fullname = 'unittestcategory6';        $grade_category = new grade_category($params, false);        $grade_category->insert();        $this->assertEqual(4, $grade_category->depth);        $this->assertEqual($parentpath.$grade_category->id."/", $grade_category->path);    }    function test_grade_category_build_path() {        $grade_category = new grade_category($this->grade_categories[1]);        $this->assertTrue(method_exists($grade_category, 'build_path'));        $path = grade_category::build_path($grade_category);        $this->assertEqual($grade_category->path, $path);    }    function test_grade_category_fetch() {        $grade_category = new grade_category();        $this->assertTrue(method_exists($grade_category, 'fetch'));        $grade_category = grade_category::fetch(array('id'=>$this->grade_categories[0]->id));        $this->assertEqual($this->grade_categories[0]->id, $grade_category->id);        $this->assertEqual($this->grade_categories[0]->fullname, $grade_category->fullname);    }    function test_grade_category_fetch_all() {        $grade_category = new grade_category();        $this->assertTrue(method_exists($grade_category, 'fetch_all'));        $grade_categories = grade_category::fetch_all(array('courseid'=>$this->courseid));        $this->assertEqual(count($this->grade_categories), count($grade_categories)-1);    }    function test_grade_category_update() {        $grade_category = new grade_category($this->grade_categories[0]);        $this->assertTrue(method_exists($grade_category, 'update'));        $grade_category->fullname = 'Updated info for this unittest grade_category';        $grade_category->path = null; // path must be recalculated if missing        $grade_category->depth = null;        $grade_category->aggregation = GRADE_AGGREGATE_MAX; // should force regrading        $grade_item = $grade_category->get_grade_item();        $this->assertEqual(0, $grade_item->needsupdate);        $this->assertTrue($grade_category->update());        $fullname = get_field('grade_categories', 'fullname', 'id', $this->grade_categories[0]->id);        $this->assertEqual($grade_category->fullname, $fullname);        $path = get_field('grade_categories', 'path', 'id', $this->grade_categories[0]->id);        $this->assertEqual($grade_category->path, $path);        $depth = get_field('grade_categories', 'depth', 'id', $this->grade_categories[0]->id);        $this->assertEqual($grade_category->depth, $depth);        $grade_item = $grade_category->get_grade_item();        $this->assertEqual(1, $grade_item->needsupdate);    }    function test_grade_category_delete() {        $grade_category = new grade_category($this->grade_categories[0]);        $this->assertTrue(method_exists($grade_category, 'delete'));        $this->assertTrue($grade_category->delete());        $this->assertFalse(get_record('grade_categories', 'id', $grade_category->id));    }    function test_grade_category_insert() {        $course_category = grade_category::fetch_course_category($this->courseid);        $grade_category = new grade_category();        $this->assertTrue(method_exists($grade_category, 'insert'));        $grade_category->fullname    = 'unittestcategory4';        $grade_category->courseid    = $this->courseid;        $grade_category->aggregation = GRADE_AGGREGATE_MEAN;        $grade_category->aggregateonlygraded = 1;        $grade_category->keephigh    = 100;        $grade_category->droplow     = 10;        $grade_category->hidden      = 0;        $grade_category->parent      = $this->grade_categories[0]->id;        $grade_category->insert();        $this->assertEqual('/'.$course_category->id.'/'.$this->grade_categories[0]->id.'/'.$grade_category->id.'/', $grade_category->path);        $this->assertEqual(3, $grade_category->depth);        $last_grade_category = end($this->grade_categories);        $this->assertFalse(empty($grade_category->grade_item));        $this->assertEqual($grade_category->id, $grade_category->grade_item->iteminstance);        $this->assertEqual('category', $grade_category->grade_item->itemtype);        $this->assertEqual($grade_category->id, $last_grade_category->id + 1);        $this->assertFalse(empty($grade_category->timecreated));        $this->assertFalse(empty($grade_category->timemodified));    }    function test_grade_category_insert_course_category() {        $grade_category = new grade_category();        $this->assertTrue(method_exists($grade_category, 'insert_course_category'));        $id = $grade_category->insert_course_category($this->courseid);        $this->assertNotNull($id);        $this->assertEqual('?', $grade_category->fullname);        $this->assertEqual(GRADE_AGGREGATE_WEIGHTED_MEAN2, $grade_category->aggregation);        $this->assertEqual("/$id/", $grade_category->path);        $this->assertEqual(1, $grade_category->depth);        $this->assertNull($grade_category->parent);    }    function test_grade_category_qualifies_for_regrading() {        $grade_category = new grade_category($this->grade_categories[0]);        $this->assertTrue(method_exists($grade_category, 'qualifies_for_regrading'));        $this->assertFalse($grade_category->qualifies_for_regrading());        $grade_category->aggregation = GRADE_AGGREGATE_MAX;        $this->assertTrue($grade_category->qualifies_for_regrading());        $grade_category = new grade_category($this->grade_categories[0]);        $grade_category->droplow = 99;        $this->assertTrue($grade_category->qualifies_for_regrading());        $grade_category = new grade_category($this->grade_categories[0]);        $grade_category->keephigh = 99;        $this->assertTrue($grade_category->qualifies_for_regrading());    }    function test_grade_category_force_regrading() {        $grade_category = new grade_category($this->grade_categories[1]);        $this->assertTrue(method_exists($grade_category, 'force_regrading'));        $grade_category->load_grade_item();        $this->assertEqual(0, $grade_category->grade_item->needsupdate);        $grade_category->force_regrading();        $grade_category->grade_item = null;        $grade_category->load_grade_item();        $this->assertEqual(1, $grade_category->grade_item->needsupdate);    }    /*     * I am disabling this test until we implement proper mock objects. This is meant     * to be a private method called from within a grade_item method.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -