PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/grade/simpletest/testgradescale.php

https://bitbucket.org/ceu/moodle_demo
PHP | 128 lines | 71 code | 27 blank | 30 comment | 1 complexity | 5edaa6acc0eaa41137d39d5f0d8a3511 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, LGPL-2.1
  1. <?php // $Id: testgradescale.php,v 1.2 2007/10/10 05:29:28 nicolasconnault Exp $
  2. ///////////////////////////////////////////////////////////////////////////
  3. // //
  4. // NOTICE OF COPYRIGHT //
  5. // //
  6. // Moodle - Modular Object-Oriented Dynamic Learning Environment //
  7. // http://moodle.org //
  8. // //
  9. // Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
  10. // //
  11. // This program is free software; you can redistribute it and/or modify //
  12. // it under the terms of the GNU General Public License as published by //
  13. // the Free Software Foundation; either version 2 of the License, or //
  14. // (at your option) any later version. //
  15. // //
  16. // This program is distributed in the hope that it will be useful, //
  17. // but WITHOUT ANY WARRANTY; without even the implied warranty of //
  18. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
  19. // GNU General Public License for more details: //
  20. // //
  21. // http://www.gnu.org/copyleft/gpl.html //
  22. // //
  23. ///////////////////////////////////////////////////////////////////////////
  24. /**
  25. * Unit tests for grade_scale object.
  26. *
  27. * @author nicolas@moodle.com
  28. * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
  29. * @package moodlecore
  30. */
  31. if (!defined('MOODLE_INTERNAL')) {
  32. die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
  33. }
  34. require_once($CFG->libdir.'/simpletest/fixtures/gradetest.php');
  35. class grade_scale_test extends grade_test {
  36. function test_scale_construct() {
  37. $params = new stdClass();
  38. $params->name = 'unittestscale3';
  39. $params->courseid = $this->courseid;
  40. $params->userid = $this->userid;
  41. $params->scale = 'Distinction, Very Good, Good, Pass, Fail';
  42. $params->description = 'This scale is used to mark standard assignments.';
  43. $params->timemodified = mktime();
  44. $scale = new grade_scale($params, false);
  45. $this->assertEqual($params->name, $scale->name);
  46. $this->assertEqual($params->scale, $scale->scale);
  47. $this->assertEqual($params->description, $scale->description);
  48. }
  49. function test_grade_scale_insert() {
  50. $grade_scale = new grade_scale();
  51. $this->assertTrue(method_exists($grade_scale, 'insert'));
  52. $grade_scale->name = 'unittestscale3';
  53. $grade_scale->courseid = $this->courseid;
  54. $grade_scale->userid = $this->userid;
  55. $grade_scale->scale = 'Distinction, Very Good, Good, Pass, Fail';
  56. $grade_scale->description = 'This scale is used to mark standard assignments.';
  57. $grade_scale->insert();
  58. $last_grade_scale = end($this->scale);
  59. $this->assertEqual($grade_scale->id, $last_grade_scale->id + 1);
  60. $this->assertTrue(!empty($grade_scale->timecreated));
  61. $this->assertTrue(!empty($grade_scale->timemodified));
  62. }
  63. function test_grade_scale_update() {
  64. $grade_scale = new grade_scale($this->scale[0]);
  65. $this->assertTrue(method_exists($grade_scale, 'update'));
  66. $grade_scale->name = 'Updated info for this unittest grade_scale';
  67. $this->assertTrue($grade_scale->update());
  68. $name = get_field('scale', 'name', 'id', $this->scale[0]->id);
  69. $this->assertEqual($grade_scale->name, $name);
  70. }
  71. function test_grade_scale_delete() {
  72. $grade_scale = new grade_scale($this->scale[0]);
  73. $this->assertTrue(method_exists($grade_scale, 'delete'));
  74. $this->assertTrue($grade_scale->delete());
  75. $this->assertFalse(get_record('scale', 'id', $grade_scale->id));
  76. }
  77. function test_grade_scale_fetch() {
  78. $grade_scale = new grade_scale();
  79. $this->assertTrue(method_exists($grade_scale, 'fetch'));
  80. $grade_scale = grade_scale::fetch(array('id'=>$this->scale[0]->id));
  81. $this->assertEqual($this->scale[0]->id, $grade_scale->id);
  82. $this->assertEqual($this->scale[0]->name, $grade_scale->name);
  83. }
  84. function test_scale_load_items() {
  85. $scale = new grade_scale($this->scale[0]);
  86. $this->assertTrue(method_exists($scale, 'load_items'));
  87. $scale->load_items();
  88. $this->assertEqual(7, count($scale->scale_items));
  89. $this->assertEqual('Fairly neutral', $scale->scale_items[2]);
  90. }
  91. function test_scale_compact_items() {
  92. $scale = new grade_scale($this->scale[0]);
  93. $this->assertTrue(method_exists($scale, 'compact_items'));
  94. $scale->load_items();
  95. $scale->scale = null;
  96. $scale->compact_items();
  97. // The original string and the new string may have differences in whitespace around the delimiter, and that's OK
  98. $this->assertEqual(preg_replace('/\s*,\s*/', ',', $this->scale[0]->scale), $scale->scale);
  99. }
  100. }
  101. ?>