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 311 and 401] [Versions 39 and 401] [Versions 400 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  require_once($CFG->dirroot . '/grade/import/csv/classes/load_data.php');
  18  require_once($CFG->dirroot . '/grade/import/lib.php');
  19  
  20  /**
  21   * Class to open up private methods in gradeimport_csv_load_data().
  22   */
  23  class phpunit_gradeimport_csv_load_data extends gradeimport_csv_load_data {
  24  
  25      /**
  26       * Method to open up the appropriate method for unit testing.
  27       *
  28       * @param object $record
  29       * @param int $studentid
  30       * @param grade_item $gradeitem
  31       */
  32      public function test_insert_grade_record($record, $studentid, grade_item $gradeitem) {
  33          $this->importcode = 00001;
  34          $this->insert_grade_record($record, $studentid, $gradeitem);
  35      }
  36  
  37      /**
  38       * Method to open up the appropriate method for unit testing.
  39       */
  40      public function get_importcode() {
  41          return $this->importcode;
  42      }
  43  
  44      /**
  45       * Method to open up the appropriate method for unit testing.
  46       *
  47       * @param array $header The column headers from the CSV file.
  48       * @param int $key Current row identifier.
  49       * @param string $value The value for this row (final grade).
  50       * @return array new grades that are ready for commiting to the gradebook.
  51       */
  52      public function test_import_new_grade_item($header, $key, $value) {
  53          $this->newgradeitems = null;
  54          $this->importcode = 00001;
  55          return $this->import_new_grade_item($header, $key, $value);
  56      }
  57  
  58      /**
  59       * Method to open up the appropriate method for unit testing.
  60       *
  61       * @param string $value The value, from the csv file, being mapped to identify the user.
  62       * @param array $userfields Contains the field and label being mapped from.
  63       * @return int Returns the user ID if it exists, otherwise null.
  64       */
  65      public function test_check_user_exists($value, $userfields) {
  66          return $this->check_user_exists($value, $userfields);
  67      }
  68  
  69      /**
  70       * Method to open up the appropriate method for unit testing.
  71       *
  72       * @param int $courseid The course ID.
  73       * @param int $itemid The ID of the grade item that the feedback relates to.
  74       * @param string $value The actual feedback being imported.
  75       * @return object Creates a feedback object with the item ID and the feedback value.
  76       */
  77      public function test_create_feedback($courseid, $itemid, $value) {
  78          return $this->create_feedback($courseid, $itemid, $value);
  79      }
  80  
  81      /**
  82       * Method to open up the appropriate method for unit testing.
  83       */
  84      public function test_update_grade_item($courseid, $map, $key, $verbosescales, $value) {
  85          return $this->update_grade_item($courseid, $map, $key, $verbosescales, $value);
  86      }
  87  
  88      /**
  89       * Method to open up the appropriate method for unit testing.
  90       *
  91       * @param int $courseid The course ID.
  92       * @param array $map Mapping information provided by the user.
  93       * @param int $key The line that we are currently working on.
  94       * @param bool $verbosescales Form setting for grading with scales.
  95       * @param string $value The grade value .
  96       * @return array grades to be updated.
  97       */
  98      public function test_map_user_data_with_value($mappingidentifier, $value, $header, $map, $key, $courseid, $feedbackgradeid,
  99              $verbosescales) {
 100          // Set an import code.
 101          $this->importcode = 00001;
 102          $this->map_user_data_with_value($mappingidentifier, $value, $header, $map, $key, $courseid, $feedbackgradeid,
 103                  $verbosescales);
 104  
 105          switch ($mappingidentifier) {
 106              case 'userid':
 107              case 'useridnumber':
 108              case 'useremail':
 109              case 'username':
 110                  return $this->studentid;
 111              break;
 112              case 'new':
 113                  return $this->newgrades;
 114              break;
 115              case 'feedback':
 116                  return $this->newfeedbacks;
 117              break;
 118              default:
 119                  return $this->newgrades;
 120              break;
 121          }
 122      }
 123  }