PageRenderTime 53ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/grade/tests/grade_outcome_test.php

https://bitbucket.org/synergylearning/campusconnect
PHP | 106 lines | 63 code | 22 blank | 21 comment | 1 complexity | 65add4f86a539fb10a944b977f1bc483 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, Apache-2.0, BSD-3-Clause, AGPL-3.0
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * @package core_grades
  18. * @category phpunit
  19. * @copyright nicolas@moodle.com
  20. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  21. */
  22. defined('MOODLE_INTERNAL') || die();
  23. require_once(__DIR__.'/fixtures/lib.php');
  24. class core_grade_outcome_testcase extends grade_base_testcase {
  25. public function test_grade_outcome() {
  26. $this->sub_test_grade_outcome_construct();
  27. $this->sub_test_grade_outcome_insert();
  28. $this->sub_test_grade_outcome_update();
  29. $this->sub_test_grade_outcome_delete();
  30. //$this->sub_test_grade_outcome_fetch();
  31. $this->sub_test_grade_outcome_fetch_all();
  32. }
  33. protected function sub_test_grade_outcome_construct() {
  34. $params = new stdClass();
  35. $params->courseid = $this->courseid;
  36. $params->shortname = 'Team work';
  37. $grade_outcome = new grade_outcome($params, false);
  38. $this->assertEquals($params->courseid, $grade_outcome->courseid);
  39. $this->assertEquals($params->shortname, $grade_outcome->shortname);
  40. }
  41. protected function sub_test_grade_outcome_insert() {
  42. $grade_outcome = new grade_outcome();
  43. $this->assertTrue(method_exists($grade_outcome, 'insert'));
  44. $grade_outcome->courseid = $this->courseid;
  45. $grade_outcome->shortname = 'tw';
  46. $grade_outcome->fullname = 'Team work';
  47. $grade_outcome->insert();
  48. $last_grade_outcome = end($this->grade_outcomes);
  49. $this->assertEquals($grade_outcome->id, $last_grade_outcome->id + 1);
  50. $this->assertFalse(empty($grade_outcome->timecreated));
  51. $this->assertFalse(empty($grade_outcome->timemodified));
  52. }
  53. protected function sub_test_grade_outcome_update() {
  54. global $DB;
  55. $grade_outcome = new grade_outcome($this->grade_outcomes[0], false);
  56. $this->assertTrue(method_exists($grade_outcome, 'update'));
  57. $grade_outcome->shortname = 'Team work';
  58. $this->assertTrue($grade_outcome->update());
  59. $shortname = $DB->get_field('grade_outcomes', 'shortname', array('id' => $this->grade_outcomes[0]->id));
  60. $this->assertEquals($grade_outcome->shortname, $shortname);
  61. }
  62. protected function sub_test_grade_outcome_delete() {
  63. global $DB;
  64. $grade_outcome = new grade_outcome($this->grade_outcomes[0], false);
  65. $this->assertTrue(method_exists($grade_outcome, 'delete'));
  66. $this->assertTrue($grade_outcome->delete());
  67. $this->assertFalse($DB->get_record('grade_outcomes', array('id' => $grade_outcome->id)));
  68. }
  69. protected function sub_test_grade_outcome_fetch() {
  70. $grade_outcome = new grade_outcome();
  71. $this->assertTrue(method_exists($grade_outcome, 'fetch'));
  72. $grade_outcome = grade_outcome::fetch(array('id'=>$this->grade_outcomes[0]->id));
  73. $grade_outcome->load_scale();
  74. $this->assertEquals($this->grade_outcomes[0]->id, $grade_outcome->id);
  75. $this->assertEquals($this->grade_outcomes[0]->shortname, $grade_outcome->shortname);
  76. $this->assertEquals($this->scale[2]->id, $grade_outcome->scale->id);
  77. }
  78. protected function sub_test_grade_outcome_fetch_all() {
  79. $grade_outcome = new grade_outcome();
  80. $this->assertTrue(method_exists($grade_outcome, 'fetch_all'));
  81. $grade_outcomes = grade_outcome::fetch_all(array());
  82. $this->assertEquals(count($this->grade_outcomes), count($grade_outcomes));
  83. }
  84. }