PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/grade/simpletest/testgradeoutcome.php

http://github.com/moodle/moodle
PHP | 117 lines | 65 code | 22 blank | 30 comment | 1 complexity | 8fa24fb726977b55e02c1bb01f6e78b0 MD5 | raw file
Possible License(s): MIT, AGPL-3.0, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, Apache-2.0, LGPL-2.1, BSD-3-Clause
  1. <?php
  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() {
  37. $this->sub_test_grade_outcome_construct();
  38. $this->sub_test_grade_outcome_insert();
  39. $this->sub_test_grade_outcome_update();
  40. $this->sub_test_grade_outcome_delete();
  41. //$this->sub_test_grade_outcome_fetch();
  42. $this->sub_test_grade_outcome_fetch_all();
  43. }
  44. function sub_test_grade_outcome_construct() {
  45. $params = new stdClass();
  46. $params->courseid = $this->courseid;
  47. $params->shortname = 'Team work';
  48. $grade_outcome = new grade_outcome($params, false);
  49. $this->assertEqual($params->courseid, $grade_outcome->courseid);
  50. $this->assertEqual($params->shortname, $grade_outcome->shortname);
  51. }
  52. function sub_test_grade_outcome_insert() {
  53. $grade_outcome = new grade_outcome();
  54. $this->assertTrue(method_exists($grade_outcome, 'insert'));
  55. $grade_outcome->courseid = $this->courseid;
  56. $grade_outcome->shortname = 'tw';
  57. $grade_outcome->fullname = 'Team work';
  58. $grade_outcome->insert();
  59. $last_grade_outcome = end($this->grade_outcomes);
  60. $this->assertEqual($grade_outcome->id, $last_grade_outcome->id + 1);
  61. $this->assertFalse(empty($grade_outcome->timecreated));
  62. $this->assertFalse(empty($grade_outcome->timemodified));
  63. }
  64. function sub_test_grade_outcome_update() {
  65. global $DB;
  66. $grade_outcome = new grade_outcome($this->grade_outcomes[0]);
  67. $this->assertTrue(method_exists($grade_outcome, 'update'));
  68. $grade_outcome->shortname = 'Team work';
  69. $this->assertTrue($grade_outcome->update());
  70. $shortname = $DB->get_field('grade_outcomes', 'shortname', array('id' => $this->grade_outcomes[0]->id));
  71. $this->assertEqual($grade_outcome->shortname, $shortname);
  72. }
  73. function sub_test_grade_outcome_delete() {
  74. global $DB;
  75. $grade_outcome = new grade_outcome($this->grade_outcomes[0]);
  76. $this->assertTrue(method_exists($grade_outcome, 'delete'));
  77. $this->assertTrue($grade_outcome->delete());
  78. $this->assertFalse($DB->get_record('grade_outcomes', array('id' => $grade_outcome->id)));
  79. }
  80. function sub_test_grade_outcome_fetch() {
  81. $grade_outcome = new grade_outcome();
  82. $this->assertTrue(method_exists($grade_outcome, 'fetch'));
  83. $grade_outcome = grade_outcome::fetch(array('id'=>$this->grade_outcomes[0]->id));
  84. $grade_outcome->load_scale();
  85. $this->assertEqual($this->grade_outcomes[0]->id, $grade_outcome->id);
  86. $this->assertEqual($this->grade_outcomes[0]->shortname, $grade_outcome->shortname);
  87. $this->assertEqual($this->scale[2]->id, $grade_outcome->scale->id);
  88. }
  89. function sub_test_grade_outcome_fetch_all() {
  90. $grade_outcome = new grade_outcome();
  91. $this->assertTrue(method_exists($grade_outcome, 'fetch_all'));
  92. $grade_outcomes = grade_outcome::fetch_all(array());
  93. $this->assertEqual(count($this->grade_outcomes), count($grade_outcomes));
  94. }
  95. }