Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 39 and 401]

   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  namespace core;
  18  
  19  defined('MOODLE_INTERNAL') || die();
  20  
  21  require_once (__DIR__.'/fixtures/lib.php');
  22  
  23  /**
  24   * Unit tests for grade_outcome
  25   *
  26   * @package    core
  27   * @category   test
  28   * @copyright  nicolas@moodle.com
  29   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  30   */
  31  class grade_outcome_test extends \grade_base_testcase {
  32  
  33      public function test_grade_outcome() {
  34          $this->sub_test_grade_outcome_construct();
  35          $this->sub_test_grade_outcome_insert();
  36          $this->sub_test_grade_outcome_update();
  37          $this->sub_test_grade_outcome_delete();
  38          //$this->sub_test_grade_outcome_fetch();
  39          $this->sub_test_grade_outcome_fetch_all();
  40      }
  41  
  42      protected function sub_test_grade_outcome_construct() {
  43          $params = new \stdClass();
  44  
  45          $params->courseid = $this->courseid;
  46          $params->shortname = 'Team work';
  47  
  48          $grade_outcome = new \grade_outcome($params, false);
  49          $this->assertEquals($params->courseid, $grade_outcome->courseid);
  50          $this->assertEquals($params->shortname, $grade_outcome->shortname);
  51      }
  52  
  53      protected function sub_test_grade_outcome_insert() {
  54          $grade_outcome = new \grade_outcome();
  55          $this->assertTrue(method_exists($grade_outcome, 'insert'));
  56  
  57          $grade_outcome->courseid = $this->courseid;
  58          $grade_outcome->shortname = 'tw';
  59          $grade_outcome->fullname = 'Team work';
  60  
  61          $grade_outcome->insert();
  62  
  63          $last_grade_outcome = end($this->grade_outcomes);
  64  
  65          $this->assertEquals($grade_outcome->id, $last_grade_outcome->id + 1);
  66          $this->assertFalse(empty($grade_outcome->timecreated));
  67          $this->assertFalse(empty($grade_outcome->timemodified));
  68      }
  69  
  70      protected function sub_test_grade_outcome_update() {
  71          global $DB;
  72          $grade_outcome = new \grade_outcome($this->grade_outcomes[0], false);
  73          $this->assertTrue(method_exists($grade_outcome, 'update'));
  74          $grade_outcome->shortname = 'Team work';
  75          $this->assertTrue($grade_outcome->update());
  76          $shortname = $DB->get_field('grade_outcomes', 'shortname', array('id' => $this->grade_outcomes[0]->id));
  77          $this->assertEquals($grade_outcome->shortname, $shortname);
  78      }
  79  
  80      protected function sub_test_grade_outcome_delete() {
  81          global $DB;
  82          $grade_outcome = new \grade_outcome($this->grade_outcomes[0], false);
  83          $this->assertTrue(method_exists($grade_outcome, 'delete'));
  84  
  85          $this->assertTrue($grade_outcome->delete());
  86          $this->assertFalse($DB->get_record('grade_outcomes', array('id' => $grade_outcome->id)));
  87      }
  88  
  89      protected function sub_test_grade_outcome_fetch() {
  90          $grade_outcome = new \grade_outcome();
  91          $this->assertTrue(method_exists($grade_outcome, 'fetch'));
  92  
  93          $grade_outcome = \grade_outcome::fetch(array('id'=>$this->grade_outcomes[0]->id));
  94          $grade_outcome->load_scale();
  95          $this->assertEquals($this->grade_outcomes[0]->id, $grade_outcome->id);
  96          $this->assertEquals($this->grade_outcomes[0]->shortname, $grade_outcome->shortname);
  97  
  98          $this->assertEquals($this->scale[2]->id, $grade_outcome->scale->id);
  99      }
 100  
 101      protected function sub_test_grade_outcome_fetch_all() {
 102          $grade_outcome = new \grade_outcome();
 103          $this->assertTrue(method_exists($grade_outcome, 'fetch_all'));
 104  
 105          $grade_outcomes = \grade_outcome::fetch_all(array());
 106          $this->assertEquals(count($this->grade_outcomes), count($grade_outcomes));
 107      }
 108  }