PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/grade/simpletest/testgradeoutcome.php

https://bitbucket.org/ceu/moodle_demo
PHP | 107 lines | 57 code | 21 blank | 29 comment | 1 complexity | cbe77657b31694f07fe7a49b0245cf3a MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, LGPL-2.1
  1. <?php // $Id: testgradeoutcome.php,v 1.2.2.1 2008/03/06 13:44:47 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_outcome 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_outcome_test extends grade_test {
  36. function test_grade_outcome_construct() {
  37. $params = new stdClass();
  38. $params->courseid = $this->courseid;
  39. $params->shortname = 'Team work';
  40. $grade_outcome = new grade_outcome($params, false);
  41. $this->assertEqual($params->courseid, $grade_outcome->courseid);
  42. $this->assertEqual($params->shortname, $grade_outcome->shortname);
  43. }
  44. function test_grade_outcome_insert() {
  45. $grade_outcome = new grade_outcome();
  46. $this->assertTrue(method_exists($grade_outcome, 'insert'));
  47. $grade_outcome->courseid = $this->courseid;
  48. $grade_outcome->shortname = 'tw';
  49. $grade_outcome->fullname = 'Team work';
  50. $grade_outcome->insert();
  51. $last_grade_outcome = end($this->grade_outcomes);
  52. $this->assertEqual($grade_outcome->id, $last_grade_outcome->id + 1);
  53. $this->assertFalse(empty($grade_outcome->timecreated));
  54. $this->assertFalse(empty($grade_outcome->timemodified));
  55. }
  56. function test_grade_outcome_update() {
  57. $grade_outcome = new grade_outcome($this->grade_outcomes[0]);
  58. $this->assertTrue(method_exists($grade_outcome, 'update'));
  59. $grade_outcome->shortname = 'Team work';
  60. $this->assertTrue($grade_outcome->update());
  61. $shortname = get_field('grade_outcomes', 'shortname', 'id', $this->grade_outcomes[0]->id);
  62. $this->assertEqual($grade_outcome->shortname, $shortname);
  63. }
  64. function test_grade_outcome_delete() {
  65. $grade_outcome = new grade_outcome($this->grade_outcomes[0]);
  66. $this->assertTrue(method_exists($grade_outcome, 'delete'));
  67. $this->assertTrue($grade_outcome->delete());
  68. $this->assertFalse(get_record('grade_outcomes', 'id', $grade_outcome->id));
  69. }
  70. function test_grade_outcome_fetch() {
  71. $grade_outcome = new grade_outcome();
  72. $this->assertTrue(method_exists($grade_outcome, 'fetch'));
  73. $grade_outcome = grade_outcome::fetch(array('id'=>$this->grade_outcomes[0]->id));
  74. $grade_outcome->load_scale();
  75. $this->assertEqual($this->grade_outcomes[0]->id, $grade_outcome->id);
  76. $this->assertEqual($this->grade_outcomes[0]->shortname, $grade_outcome->shortname);
  77. $this->assertEqual($this->scale[2]->id, $grade_outcome->scale->id);
  78. }
  79. function test_grade_outcome_fetch_all() {
  80. $grade_outcome = new grade_outcome();
  81. $this->assertTrue(method_exists($grade_outcome, 'fetch_all'));
  82. $grade_outcomes = grade_outcome::fetch_all(array());
  83. $this->assertEqual(count($this->grade_outcomes), count($grade_outcomes));
  84. }
  85. }
  86. ?>