gradetest.php

来自「很棒的在线教学系统」· PHP 代码 · 共 1,205 行 · 第 1/5 页

PHP
1,205
字号
<?php // $Id: gradetest.php,v 1.23.2.3 2008/04/02 06:36:36 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                         ////                                                                       /////////////////////////////////////////////////////////////////////////////if (!defined('MOODLE_INTERNAL')) {    die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page}/** * Shared code for all grade related tests. * * @author nicolas@moodle.com * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @package moodlecore */require_once($CFG->libdir . '/gradelib.php');require_once($CFG->libdir . '/dmllib.php');require_once($CFG->libdir . '/ddllib.php');Mock::generate('grade_item', 'mock_grade_item');Mock::generate('grade_scale', 'mock_grade_scale');Mock::generate('grade_category', 'mock_grade_category');Mock::generate('grade_grade', 'mock_grade_grade');Mock::generate('grade_outcome', 'mock_grade_outcome');Mock::generate('grade_lib_wrapper', 'mock_lib_wrapper');Mock::generate('ADODB_' . $CFG->dbtype, 'mock_db');Mock::generate('ADORecordSet_' . $CFG->dbtype, 'mock_rs');// Prepare partial mocks for the static grade object instancesMock::generatePartial('grade_category', 'mock_grade_category_partial', array('fetch', 'fetch_all'));Mock::generatePartial('grade_item', 'mock_grade_item_partial', array('fetch', 'fetch_all'));Mock::generatePartial('grade_grade', 'mock_grade_grade_partial', array('fetch', 'fetch_all'));Mock::generatePartial('grade_outcome', 'mock_grade_outcome_partial', array('fetch', 'fetch_all'));Mock::generatePartial('grade_scale', 'mock_grade_scale_partial', array('fetch', 'fetch_all'));/** * Here is a brief explanation of the test data set up in these unit tests. * category1 => array(category2 => array(grade_item1, grade_item2), category3 => array(grade_item3)) * 3 users for 3 grade_items */class grade_test extends UnitTestCase {    /**     * Each database table receives a number of test entries. These are saved as     * arrays of stcClass objects available to this class. This means that     * every test has access to these test data. The order of the following array is     * crucial, because of the interrelationships between objects.     */    var $tables = array('grade_categories',                        'scale',                        'grade_items',                        'grade_grades',                        'grade_outcomes');    var $grade_items = array();    var $grade_categories = array();    var $grade_grades = array();    var $grade_outcomes = array();    var $scale = array();    var $activities = array();    var $courseid = 1;    var $userid = 1;    /**     * Create temporary test tables and entries in the database for these tests.     * These tests have to work on a brand new site.     * Override $CFG->prefix while these tests run.     */    function setUp() {        // Set global category settings to -1 (not force)        global $CFG;        $CFG->grade_droplow = -1;        $CFG->grade_keephigh = -1;        $CFG->grade_aggregation = -1;        $CFG->grade_aggregateonlygraded = -1;        $CFG->grade_aggregateoutcomes = -1;        $CFG->grade_aggregatesubcats = -1;        $CFG->old_prefix = $CFG->prefix;        $CFG->prefix .= 'unittest_';        if (!$this->prepare_test_tables()) {            die("Could not create all the test tables!");        }        if (!$this->prepare_test_history_tables()) {            die("Could not create all the test tables!");        }        foreach ($this->tables as $table) {            $function = "load_$table";            $this->$function();        }    }    function prepare_test_tables() {        $result = true;        /// Define table course_modules to be created        $table = new XMLDBTable('course_modules');        if (!table_exists($table)) {            /// Adding fields to table course_modules            $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);            $table->addFieldInfo('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');            $table->addFieldInfo('module', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');            $table->addFieldInfo('instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');            $table->addFieldInfo('section', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');            $table->addFieldInfo('idnumber', XMLDB_TYPE_CHAR, '100', null, null, null, null, null, null);            $table->addFieldInfo('added', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');            $table->addFieldInfo('score', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null, null, '0');            $table->addFieldInfo('indent', XMLDB_TYPE_INTEGER, '5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');            $table->addFieldInfo('visible', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, '1');            $table->addFieldInfo('visibleold', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, '1');            $table->addFieldInfo('groupmode', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null, null, '0');            $table->addFieldInfo('groupingid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');            $table->addFieldInfo('groupmembersonly', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');            /// Adding keys to table course_modules            $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));            $table->addKeyInfo('groupingid', XMLDB_KEY_FOREIGN, array('groupingid'), 'groupings', array('id'));            /// Adding indexes to table course_modules            $table->addIndexInfo('visible', XMLDB_INDEX_NOTUNIQUE, array('visible'));            $table->addIndexInfo('course', XMLDB_INDEX_NOTUNIQUE, array('course'));            $table->addIndexInfo('module', XMLDB_INDEX_NOTUNIQUE, array('module'));            $table->addIndexInfo('instance', XMLDB_INDEX_NOTUNIQUE, array('instance'));            $table->addIndexInfo('idnumber-course', XMLDB_INDEX_NOTUNIQUE, array('idnumber', 'course'));            /// Launch create table for course_modules            $result = $result && create_table($table, true, false);        } else {            delete_records($table->name);        }        /// Define table modules to be created        $table = new XMLDBTable('modules');        if (!table_exists($table)) {            /// Adding fields to table modules            $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);            $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, null);            $table->addFieldInfo('version', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');            $table->addFieldInfo('cron', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');            $table->addFieldInfo('lastcron', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');            $table->addFieldInfo('search', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);            $table->addFieldInfo('visible', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, '1');            /// Adding keys to table modules            $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));            /// Adding indexes to table modules            $table->addIndexInfo('name', XMLDB_INDEX_NOTUNIQUE, array('name'));            /// Launch create table for modules            $result = $result && create_table($table, true, false);        } else {            delete_records($table->name);        }        /// Define table grade_items to be created        $table = new XMLDBTable('grade_items');        if (!table_exists($table)) {            $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);            $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);            $table->addFieldInfo('categoryid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);            $table->addFieldInfo('itemname', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);            $table->addFieldInfo('itemtype', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, null);            $table->addFieldInfo('itemmodule', XMLDB_TYPE_CHAR, '30', null, null, null, null, null, null);            $table->addFieldInfo('iteminstance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);            $table->addFieldInfo('itemnumber', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);            $table->addFieldInfo('iteminfo', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);            $table->addFieldInfo('idnumber', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);            $table->addFieldInfo('calculation', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);            $table->addFieldInfo('gradetype', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null, null, '1');            $table->addFieldInfo('grademax', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '100');            $table->addFieldInfo('grademin', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');            $table->addFieldInfo('scaleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);            $table->addFieldInfo('outcomeid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, null, null);            $table->addFieldInfo('gradepass', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');            $table->addFieldInfo('multfactor', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '1.0');            $table->addFieldInfo('plusfactor', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null, null, '0');            $table->addFieldInfo('sortorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');            $table->addFieldInfo('display', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');            $table->addFieldInfo('decimals', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null, null, null);            $table->addFieldInfo('hidden', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');            $table->addFieldInfo('locked', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');            $table->addFieldInfo('locktime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');            $table->addFieldInfo('deleted', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');            $table->addFieldInfo('needsupdate', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '0');            $table->addFieldInfo('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);            $table->addFieldInfo('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);            $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));            $table->addKeyInfo('courseid', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));            $table->addKeyInfo('categoryid', XMLDB_KEY_FOREIGN, array('categoryid'), 'grade_categories', array('id'));            $table->addKeyInfo('scaleid', XMLDB_KEY_FOREIGN, array('scaleid'), 'scale', array('id'));            $table->addKeyInfo('outcomeid', XMLDB_KEY_FOREIGN, array('outcomeid'), 'grade_outcomes', array('id'));            /// Launch create table for grade_items            $result = $result && create_table($table, true, false);        } else {            delete_records($table->name);        }        /// Define table grade_categories to be created        $table = new XMLDBTable('grade_categories');        if ($result && !table_exists($table)) {            $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);            $table->addFieldInfo('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);            $table->addFieldInfo('parent', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null);            $table->addFieldInfo('depth', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');            $table->addFieldInfo('path', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null);            $table->addFieldInfo('fullname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);

⌨️ 快捷键说明

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