Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [Versions 400 and 403] [Versions 401 and 403] [Versions 402 and 403]

   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  /**
  18   * The testable assign class.
  19   *
  20   * @package   mod_assign
  21   * @copyright 2014 Adrian Greeve <adrian@moodle.com>
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  global $CFG;
  28  require_once($CFG->dirroot . '/mod/assign/locallib.php');
  29  
  30  /**
  31   * Test subclass that makes all the protected methods we want to test public.
  32   */
  33  class mod_assign_testable_assign extends assign {
  34  
  35      public function testable_show_intro() {
  36          return parent::show_intro();
  37      }
  38  
  39      public function testable_delete_grades() {
  40          return parent::delete_grades();
  41      }
  42  
  43      public function testable_apply_grade_to_user($formdata, $userid, $attemptnumber) {
  44          return parent::apply_grade_to_user($formdata, $userid, $attemptnumber);
  45      }
  46  
  47      public function testable_get_grading_userid_list() {
  48          return parent::get_grading_userid_list();
  49      }
  50  
  51      public function testable_is_graded($userid) {
  52          return parent::is_graded($userid);
  53      }
  54  
  55      public function testable_update_submission(stdClass $submission, $userid, $updatetime, $teamsubmission) {
  56          return parent::update_submission($submission, $userid, $updatetime, $teamsubmission);
  57      }
  58  
  59      public function testable_process_add_attempt($userid = 0) {
  60          return parent::process_add_attempt($userid);
  61      }
  62  
  63      public function testable_process_save_quick_grades($postdata) {
  64          // Ugly hack to get something into the method.
  65          global $_POST;
  66          $_POST = $postdata;
  67          return parent::process_save_quick_grades();
  68      }
  69  
  70      public function testable_process_set_batch_marking_allocation($selectedusers, $markerid) {
  71          global $CFG;
  72          require_once($CFG->dirroot . '/mod/assign/batchsetallocatedmarkerform.php');
  73  
  74          // Simulate the form submission.
  75          $data = array();
  76          $data['id'] = $this->get_course_module()->id;
  77          $data['selectedusers'] = $selectedusers;
  78          $data['allocatedmarker'] = $markerid;
  79          $data['action'] = 'setbatchmarkingallocation';
  80          mod_assign_batch_set_allocatedmarker_form::mock_submit($data);
  81  
  82          return parent::process_set_batch_marking_allocation();
  83      }
  84  
  85      public function testable_process_set_batch_marking_workflow_state($selectedusers, $state) {
  86          global $CFG;
  87          require_once($CFG->dirroot . '/mod/assign/batchsetmarkingworkflowstateform.php');
  88  
  89          // Simulate the form submission.
  90          $data = array();
  91          $data['id'] = $this->get_course_module()->id;
  92          $data['selectedusers'] = $selectedusers;
  93          $data['markingworkflowstate'] = $state;
  94          $data['action'] = 'setbatchmarkingworkflowstate';
  95          mod_assign_batch_set_marking_workflow_state_form::mock_submit($data);
  96  
  97          return parent::process_set_batch_marking_workflow_state();
  98      }
  99  
 100      public function testable_submissions_open($userid = 0) {
 101          return parent::submissions_open($userid);
 102      }
 103  
 104      public function testable_save_user_extension($userid, $extensionduedate) {
 105          return parent::save_user_extension($userid, $extensionduedate);
 106      }
 107  
 108      public function testable_get_graders($userid) {
 109          // Changed method from protected to public.
 110          return parent::get_graders($userid);
 111      }
 112  
 113      public function testable_get_notifiable_users($userid) {
 114          return parent::get_notifiable_users($userid);
 115      }
 116  
 117      public function testable_view_batch_set_workflow_state($selectedusers) {
 118          global $PAGE;
 119          $PAGE->set_url('/mod/assign/view.php');
 120          $mform = $this->testable_grading_batch_operations_form('setmarkingworkflowstate', $selectedusers);
 121          return parent::view_batch_set_workflow_state($mform);
 122      }
 123  
 124      public function testable_view_batch_markingallocation($selectedusers) {
 125          global $PAGE;
 126          $PAGE->set_url('/mod/assign/view.php');
 127          $mform = $this->testable_grading_batch_operations_form('setmarkingallocation', $selectedusers);
 128          return parent::view_batch_markingallocation($mform);
 129      }
 130  
 131      public function testable_grading_batch_operations_form($operation, $selectedusers) {
 132          global $CFG;
 133  
 134          require_once($CFG->dirroot . '/mod/assign/gradingbatchoperationsform.php');
 135  
 136          // Mock submit the grading operations form.
 137          $data = array();
 138          $data['id'] = $this->get_course_module()->id;
 139          $data['selectedusers'] = $selectedusers;
 140          $data['returnaction'] = 'grading';
 141          $data['operation'] = $operation;
 142          mod_assign_grading_batch_operations_form::mock_submit($data);
 143  
 144          // Set required variables in the form.
 145          $formparams = array();
 146          $formparams['submissiondrafts'] = 1;
 147          $formparams['duedate'] = 1;
 148          $formparams['attemptreopenmethod'] = ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL;
 149          $formparams['feedbackplugins'] = array();
 150          $formparams['markingworkflow'] = 1;
 151          $formparams['markingallocation'] = 1;
 152          $formparams['cm'] = $this->get_course_module()->id;
 153          $formparams['context'] = $this->get_context();
 154          $mform = new mod_assign_grading_batch_operations_form(null, $formparams);
 155  
 156          return $mform;
 157      }
 158  
 159      public function testable_update_activity_completion_records($teamsubmission,
 160                                                            $requireallteammemberssubmit,
 161                                                            $submission,
 162                                                            $userid,
 163                                                            $complete,
 164                                                            $completion) {
 165          return parent::update_activity_completion_records($teamsubmission,
 166                                                            $requireallteammemberssubmit,
 167                                                            $submission,
 168                                                            $userid,
 169                                                            $complete,
 170                                                            $completion);
 171      }
 172  }