~ubuntu-branches/ubuntu/trusty/moodle/trusty-proposed

« back to all changes in this revision

Viewing changes to lib/grade/simpletest/testgradescale.php

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2013-07-19 08:52:46 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20130719085246-yebwditc2exoap2r
Tags: 2.5.1-1
* New upstream version: 2.5.1.
  - Fixes security issues:
    CVE-2013-2242 CVE-2013-2243 CVE-2013-2244 CVE-2013-2245
    CVE-2013-2246
* Depend on apache2 instead of obsolete apache2-mpm-prefork.
* Use packaged libphp-phpmailer (closes: #429339), adodb,
  HTMLPurifier, PclZip.
* Update debconf translations, thanks Salvatore Merone, Pietro Tollot,
  Joe Hansen, Yuri Kozlov, Holger Wansing, Américo Monteiro,
  Adriano Rafael Gomes, victory, Michał Kułach.
  (closes: #716972, #716986, #717080, #717108, #717278)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
 
3
 
///////////////////////////////////////////////////////////////////////////
4
 
//                                                                       //
5
 
// NOTICE OF COPYRIGHT                                                   //
6
 
//                                                                       //
7
 
// Moodle - Modular Object-Oriented Dynamic Learning Environment         //
8
 
//          http://moodle.org                                            //
9
 
//                                                                       //
10
 
// Copyright (C) 1999 onwards Martin Dougiamas  http://dougiamas.com     //
11
 
//                                                                       //
12
 
// This program is free software; you can redistribute it and/or modify  //
13
 
// it under the terms of the GNU General Public License as published by  //
14
 
// the Free Software Foundation; either version 2 of the License, or     //
15
 
// (at your option) any later version.                                   //
16
 
//                                                                       //
17
 
// This program is distributed in the hope that it will be useful,       //
18
 
// but WITHOUT ANY WARRANTY; without even the implied warranty of        //
19
 
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
20
 
// GNU General Public License for more details:                          //
21
 
//                                                                       //
22
 
//          http://www.gnu.org/copyleft/gpl.html                         //
23
 
//                                                                       //
24
 
///////////////////////////////////////////////////////////////////////////
25
 
 
26
 
/**
27
 
 * Unit tests for grade_scale object.
28
 
 *
29
 
 * @author nicolas@moodle.com
30
 
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
31
 
 * @package moodlecore
32
 
 */
33
 
 
34
 
if (!defined('MOODLE_INTERNAL')) {
35
 
    die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page
36
 
}
37
 
 
38
 
require_once($CFG->libdir.'/simpletest/fixtures/gradetest.php');
39
 
 
40
 
class grade_scale_test extends grade_test {
41
 
 
42
 
    function test_grade_scale() {
43
 
        $this->sub_test_scale_construct();
44
 
        $this->sub_test_grade_scale_insert();
45
 
        $this->sub_test_grade_scale_update();
46
 
        $this->sub_test_grade_scale_delete();
47
 
        $this->sub_test_grade_scale_fetch();
48
 
        $this->sub_test_scale_load_items();
49
 
        $this->sub_test_scale_compact_items();
50
 
    }
51
 
 
52
 
    function sub_test_scale_construct() {
53
 
        $params = new stdClass();
54
 
 
55
 
        $params->name        = 'unittestscale3';
56
 
        $params->courseid    = $this->courseid;
57
 
        $params->userid      = $this->userid;
58
 
        $params->scale       = 'Distinction, Very Good, Good, Pass, Fail';
59
 
        $params->description = 'This scale is used to mark standard assignments.';
60
 
        $params->timemodified = mktime();
61
 
 
62
 
        $scale = new grade_scale($params, false);
63
 
 
64
 
        $this->assertEqual($params->name, $scale->name);
65
 
        $this->assertEqual($params->scale, $scale->scale);
66
 
        $this->assertEqual($params->description, $scale->description);
67
 
 
68
 
    }
69
 
 
70
 
    function sub_test_grade_scale_insert() {
71
 
        $grade_scale = new grade_scale();
72
 
        $this->assertTrue(method_exists($grade_scale, 'insert'));
73
 
 
74
 
        $grade_scale->name        = 'unittestscale3';
75
 
        $grade_scale->courseid    = $this->courseid;
76
 
        $grade_scale->userid      = $this->userid;
77
 
        $grade_scale->scale       = 'Distinction, Very Good, Good, Pass, Fail';
78
 
        $grade_scale->description = 'This scale is used to mark standard assignments.';
79
 
 
80
 
        $grade_scale->insert();
81
 
 
82
 
        $last_grade_scale = end($this->scale);
83
 
 
84
 
        $this->assertEqual($grade_scale->id, $last_grade_scale->id + 1);
85
 
        $this->assertTrue(!empty($grade_scale->timecreated));
86
 
        $this->assertTrue(!empty($grade_scale->timemodified));
87
 
    }
88
 
 
89
 
    function sub_test_grade_scale_update() {
90
 
        global $DB;
91
 
        $grade_scale = new grade_scale($this->scale[1]);
92
 
        $this->assertTrue(method_exists($grade_scale, 'update'));
93
 
 
94
 
        $grade_scale->name = 'Updated info for this unittest grade_scale';
95
 
        $this->assertTrue($grade_scale->update());
96
 
        $name = $DB->get_field('scale', 'name', array('id' => $this->scale[1]->id));
97
 
        $this->assertEqual($grade_scale->name, $name);
98
 
    }
99
 
 
100
 
    function sub_test_grade_scale_delete() {
101
 
        global $DB;
102
 
        $grade_scale = new grade_scale($this->scale[4]);//choose one we're not using elsewhere
103
 
        $this->assertTrue(method_exists($grade_scale, 'delete'));
104
 
 
105
 
        $this->assertTrue($grade_scale->delete());
106
 
        $this->assertFalse($DB->get_record('scale', array('id' => $grade_scale->id)));
107
 
 
108
 
        //keep the reference collection the same as what is in the database
109
 
        unset($this->scale[4]);
110
 
    }
111
 
 
112
 
    function sub_test_grade_scale_fetch() {
113
 
        $grade_scale = new grade_scale();
114
 
        $this->assertTrue(method_exists($grade_scale, 'fetch'));
115
 
 
116
 
        $grade_scale = grade_scale::fetch(array('id'=>$this->scale[0]->id));
117
 
        $this->assertEqual($this->scale[0]->id, $grade_scale->id);
118
 
        $this->assertEqual($this->scale[0]->name, $grade_scale->name);
119
 
    }
120
 
 
121
 
    function sub_test_scale_load_items() {
122
 
        $scale = new grade_scale($this->scale[0]);
123
 
        $this->assertTrue(method_exists($scale, 'load_items'));
124
 
 
125
 
        $scale->load_items();
126
 
        $this->assertEqual(7, count($scale->scale_items));
127
 
        $this->assertEqual('Fairly neutral', $scale->scale_items[2]);
128
 
 
129
 
    }
130
 
 
131
 
    function sub_test_scale_compact_items() {
132
 
        $scale = new grade_scale($this->scale[0]);
133
 
        $this->assertTrue(method_exists($scale, 'compact_items'));
134
 
 
135
 
        $scale->load_items();
136
 
        $scale->scale = null;
137
 
        $scale->compact_items();
138
 
 
139
 
        // The original string and the new string may have differences in whitespace around the delimiter, and that's OK
140
 
        $this->assertEqual(preg_replace('/\s*,\s*/', ',', $this->scale[0]->scale), $scale->scale);
141
 
    }
142
 
}