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 401 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  namespace qbank_history;
  18  
  19  use question_bank;
  20  
  21  /**
  22   * Helper class test.
  23   *
  24   * @package    qbank_history
  25   * @copyright  2022 Catalyst IT Australia Pty Ltd
  26   * @author     Safat Shahin <safatshahin@catalyst-au.net>
  27   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  28   * @coversDefaultClass \qbank_history\helper
  29   */
  30  class helper_test extends \advanced_testcase {
  31      /**
  32       * @var bool|\context|\context_course $context
  33       */
  34      public $context;
  35  
  36      /**
  37       * @var object $questiondata;
  38       */
  39      public $questiondata;
  40  
  41      /**
  42       * @var \moodle_url $returnurl
  43       */
  44      public $returnurl;
  45  
  46      /**
  47       * @var int $courseid
  48       */
  49      public $courseid;
  50  
  51      /**
  52       * Test set up.
  53       *
  54       * This is executed before running any test in this file.
  55       */
  56      public function setUp(): void {
  57          $this->setAdminUser();
  58          $generator = $this->getDataGenerator();
  59          $questiongenerator = $generator->get_plugin_generator('core_question');
  60          // Create a course.
  61          $course = $generator->create_course();
  62          $this->courseid = $course->id;
  63          $this->context = \context_course::instance($course->id);
  64          // Create a question in the default category.
  65          $contexts = new \core_question\local\bank\question_edit_contexts($this->context);
  66          $cat = question_make_default_categories($contexts->all());
  67          $question = $questiongenerator->create_question('numerical', null,
  68              ['name' => 'Example question', 'category' => $cat->id]);
  69          $this->questiondata = question_bank::load_question($question->id);
  70          $this->returnurl = new \moodle_url('/question/edit.php');
  71      }
  72  
  73      /**
  74       * Test the history action url from the helper class.
  75       *
  76       * @covers ::question_history_url
  77       */
  78      public function test_question_history_url() {
  79          $this->resetAfterTest();
  80          $actionurl = helper::question_history_url($this->questiondata->questionbankentryid, $this->returnurl, $this->courseid);
  81          $params = [
  82              'entryid' => $this->questiondata->questionbankentryid,
  83              'returnurl' => $this->returnurl,
  84              'courseid' => $this->courseid
  85          ];
  86          $expectedurl = new \moodle_url('/question/bank/history/history.php', $params);
  87          $this->assertEquals($expectedurl, $actionurl);
  88      }
  89  
  90  }