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 namespace mod_quiz; 18 19 use core_question\local\bank\question_edit_contexts; 20 use mod_quiz\question\bank\custom_view; 21 22 defined('MOODLE_INTERNAL') || die(); 23 24 global $CFG; 25 require_once($CFG->dirroot . '/question/editlib.php'); 26 27 /** 28 * Unit tests for the quiz's own question bank view class. 29 * 30 * @package mod_quiz 31 * @category test 32 * @copyright 2018 the Open University 33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 34 */ 35 class quiz_question_bank_view_test extends \advanced_testcase { 36 37 public function test_viewing_question_bank_should_not_load_individual_questions() { 38 $this->resetAfterTest(); 39 $this->setAdminUser(); 40 $generator = $this->getDataGenerator(); 41 /** @var core_question_generator $questiongenerator */ 42 $questiongenerator = $generator->get_plugin_generator('core_question'); 43 44 // Create a course and a quiz. 45 $course = $generator->create_course(); 46 $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id]); 47 $context = \context_module::instance($quiz->cmid); 48 $cm = get_coursemodule_from_instance('quiz', $quiz->id); 49 50 // Create a question in the default category. 51 $contexts = new question_edit_contexts($context); 52 question_make_default_categories($contexts->all()); 53 $cat = question_get_default_category($context->id); 54 $questiondata = $questiongenerator->create_question('numerical', null, 55 ['name' => 'Example question', 'category' => $cat->id]); 56 57 // Ensure the question is not in the cache. 58 $cache = \cache::make('core', 'questiondata'); 59 $cache->delete($questiondata->id); 60 61 // Generate the view. 62 $params = [ 63 'qpage' => 0, 64 'qperpage' => 20, 65 'cat' => $cat->id . ',' . $context->id, 66 'recurse' => false, 67 'showhidden' => false, 68 'qbshowtext' => false, 69 'tabname' => 'editq' 70 ]; 71 $extraparams = ['cmid' => $cm->id]; 72 $view = new custom_view($contexts, new \moodle_url('/'), $course, $cm, $params, $extraparams); 73 ob_start(); 74 $view->display(); 75 $html = ob_get_clean(); 76 77 // Verify the output includes the expected question. 78 $this->assertStringContainsString('Example question', $html); 79 80 // Verify the question has not been loaded into the cache. 81 $this->assertFalse($cache->has($questiondata->id)); 82 } 83 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body