Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/grade/simpletest/testgradescale.php
Go to the documentation of this file.
00001 <?php
00002 
00004 //                                                                       //
00005 // NOTICE OF COPYRIGHT                                                   //
00006 //                                                                       //
00007 // Moodle - Modular Object-Oriented Dynamic Learning Environment         //
00008 //          http://moodle.org                                            //
00009 //                                                                       //
00010 // Copyright (C) 1999 onwards Martin Dougiamas  http://dougiamas.com     //
00011 //                                                                       //
00012 // This program is free software; you can redistribute it and/or modify  //
00013 // it under the terms of the GNU General Public License as published by  //
00014 // the Free Software Foundation; either version 2 of the License, or     //
00015 // (at your option) any later version.                                   //
00016 //                                                                       //
00017 // This program is distributed in the hope that it will be useful,       //
00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of        //
00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
00020 // GNU General Public License for more details:                          //
00021 //                                                                       //
00022 //          http://www.gnu.org/copyleft/gpl.html                         //
00023 //                                                                       //
00025 
00034 if (!defined('MOODLE_INTERNAL')) {
00035     die('Direct access to this script is forbidden.');    
00036 }
00037 
00038 require_once($CFG->libdir.'/simpletest/fixtures/gradetest.php');
00039 
00040 class grade_scale_test extends grade_test {
00041 
00042     function test_grade_scale() {
00043         $this->sub_test_scale_construct();
00044         $this->sub_test_grade_scale_insert();
00045         $this->sub_test_grade_scale_update();
00046         $this->sub_test_grade_scale_delete();
00047         $this->sub_test_grade_scale_fetch();
00048         $this->sub_test_scale_load_items();
00049         $this->sub_test_scale_compact_items();
00050     }
00051 
00052     function sub_test_scale_construct() {
00053         $params = new stdClass();
00054 
00055         $params->name        = 'unittestscale3';
00056         $params->courseid    = $this->courseid;
00057         $params->userid      = $this->userid;
00058         $params->scale       = 'Distinction, Very Good, Good, Pass, Fail';
00059         $params->description = 'This scale is used to mark standard assignments.';
00060         $params->timemodified = mktime();
00061 
00062         $scale = new grade_scale($params, false);
00063 
00064         $this->assertEqual($params->name, $scale->name);
00065         $this->assertEqual($params->scale, $scale->scale);
00066         $this->assertEqual($params->description, $scale->description);
00067 
00068     }
00069 
00070     function sub_test_grade_scale_insert() {
00071         $grade_scale = new grade_scale();
00072         $this->assertTrue(method_exists($grade_scale, 'insert'));
00073 
00074         $grade_scale->name        = 'unittestscale3';
00075         $grade_scale->courseid    = $this->courseid;
00076         $grade_scale->userid      = $this->userid;
00077         $grade_scale->scale       = 'Distinction, Very Good, Good, Pass, Fail';
00078         $grade_scale->description = 'This scale is used to mark standard assignments.';
00079 
00080         $grade_scale->insert();
00081 
00082         $last_grade_scale = end($this->scale);
00083 
00084         $this->assertEqual($grade_scale->id, $last_grade_scale->id + 1);
00085         $this->assertTrue(!empty($grade_scale->timecreated));
00086         $this->assertTrue(!empty($grade_scale->timemodified));
00087     }
00088 
00089     function sub_test_grade_scale_update() {
00090         global $DB;
00091         $grade_scale = new grade_scale($this->scale[1]);
00092         $this->assertTrue(method_exists($grade_scale, 'update'));
00093 
00094         $grade_scale->name = 'Updated info for this unittest grade_scale';
00095         $this->assertTrue($grade_scale->update());
00096         $name = $DB->get_field('scale', 'name', array('id' => $this->scale[1]->id));
00097         $this->assertEqual($grade_scale->name, $name);
00098     }
00099 
00100     function sub_test_grade_scale_delete() {
00101         global $DB;
00102         $grade_scale = new grade_scale($this->scale[4]);//choose one we're not using elsewhere
00103         $this->assertTrue(method_exists($grade_scale, 'delete'));
00104 
00105         $this->assertTrue($grade_scale->delete());
00106         $this->assertFalse($DB->get_record('scale', array('id' => $grade_scale->id)));
00107 
00108         //keep the reference collection the same as what is in the database
00109         unset($this->scale[4]);
00110     }
00111 
00112     function sub_test_grade_scale_fetch() {
00113         $grade_scale = new grade_scale();
00114         $this->assertTrue(method_exists($grade_scale, 'fetch'));
00115 
00116         $grade_scale = grade_scale::fetch(array('id'=>$this->scale[0]->id));
00117         $this->assertEqual($this->scale[0]->id, $grade_scale->id);
00118         $this->assertEqual($this->scale[0]->name, $grade_scale->name);
00119     }
00120 
00121     function sub_test_scale_load_items() {
00122         $scale = new grade_scale($this->scale[0]);
00123         $this->assertTrue(method_exists($scale, 'load_items'));
00124 
00125         $scale->load_items();
00126         $this->assertEqual(7, count($scale->scale_items));
00127         $this->assertEqual('Fairly neutral', $scale->scale_items[2]);
00128 
00129     }
00130 
00131     function sub_test_scale_compact_items() {
00132         $scale = new grade_scale($this->scale[0]);
00133         $this->assertTrue(method_exists($scale, 'compact_items'));
00134 
00135         $scale->load_items();
00136         $scale->scale = null;
00137         $scale->compact_items();
00138 
00139         // The original string and the new string may have differences in whitespace around the delimiter, and that's OK
00140         $this->assertEqual(preg_replace('/\s*,\s*/', ',', $this->scale[0]->scale), $scale->scale);
00141     }
00142 }
 All Data Structures Namespaces Files Functions Variables Enumerations