Differences Between: [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 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 $filter = urlencode('filters[]'); 81 $actionurl = helper::question_history_url( 82 $this->questiondata->questionbankentryid, 83 $this->returnurl, 84 $this->courseid, 85 $filter, 86 ); 87 $params = [ 88 'entryid' => $this->questiondata->questionbankentryid, 89 'returnurl' => $this->returnurl, 90 'courseid' => $this->courseid, 91 'filter' => $filter, 92 ]; 93 $expectedurl = new \moodle_url('/question/bank/history/history.php', $params); 94 $this->assertEquals($expectedurl, $actionurl); 95 } 96 97 /** 98 * Test the history action url when the filter parameter is null. 99 * 100 * @covers ::question_history_url 101 */ 102 public function test_question_history_url_null_filter() { 103 $this->resetAfterTest(); 104 $actionurl = helper::question_history_url( 105 $this->questiondata->questionbankentryid, 106 $this->returnurl, 107 $this->courseid, 108 null, 109 ); 110 $params = [ 111 'entryid' => $this->questiondata->questionbankentryid, 112 'returnurl' => $this->returnurl, 113 'courseid' => $this->courseid, 114 ]; 115 $expectedurl = new \moodle_url('/question/bank/history/history.php', $params); 116 $this->assertEquals($expectedurl, $actionurl); 117 } 118 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body