See Release Notes
Long Term Support Release
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 * Unit tests for the drag-and-drop markers edit form. 19 * 20 * @package qtype_ddmarker 21 * @copyright 2019 The Open University 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 defined('MOODLE_INTERNAL') || die(); 26 global $CFG; 27 28 require_once($CFG->dirroot . '/question/engine/tests/helpers.php'); 29 require_once($CFG->dirroot . '/question/type/edit_question_form.php'); 30 require_once($CFG->dirroot . '/question/type/ddmarker/edit_ddmarker_form.php'); 31 32 /** 33 * Unit tests for the drag-and-drop markers edit form. 34 * 35 * @copyright 2019 The Open University 36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 37 */ 38 class qtype_ddmarker_edit_form_test extends advanced_testcase { 39 /** 40 * Helper method. 41 * 42 * @return array with two elements: 43 * question_edit_form great a question form instance that can be tested. 44 * stdClass the question category. 45 */ 46 protected function get_form() { 47 $this->setAdminUser(); 48 $this->resetAfterTest(); 49 50 $syscontext = context_system::instance(); 51 $category = question_make_default_categories(array($syscontext)); 52 $fakequestion = new stdClass(); 53 $fakequestion->qtype = 'ddmarker'; 54 $fakequestion->contextid = $syscontext->id; 55 $fakequestion->createdby = 2; 56 $fakequestion->category = $category->id; 57 $fakequestion->questiontext = 'Test question'; 58 $fakequestion->options = new stdClass(); 59 $fakequestion->options->answers = array(); 60 $fakequestion->formoptions = new stdClass(); 61 $fakequestion->formoptions->movecontext = null; 62 $fakequestion->formoptions->repeatelements = true; 63 $fakequestion->inputs = null; 64 65 $form = new qtype_ddmarker_edit_form(new moodle_url('/'), $fakequestion, $category, 66 new question_edit_contexts($syscontext)); 67 68 return [$form, $category]; 69 } 70 71 /** 72 * Test the form correctly validates the HTML allowed in items. 73 */ 74 public function test_item_validation() { 75 list($form, $category) = $this->get_form(); 76 77 $submitteddata = [ 78 'category' => $category->id, 79 'bgimage' => 0, 80 'nodropzone' => 0, 81 'noitems' => 4, 82 'drags' => [ 83 ['label' => 'frog'], 84 ['label' => '<b>toad</b>'], 85 ['label' => '<span lang="fr"><em>chien</em></span>'], 86 ['label' => '<textarea>evil!</textarea>'], 87 ], 88 ]; 89 90 $errors = $form->validation($submitteddata, []); 91 92 $this->assertArrayNotHasKey('drags[0]', $errors); 93 $this->assertArrayNotHasKey('drags[1]', $errors); 94 $this->assertArrayNotHasKey('drags[2]', $errors); 95 $this->assertEquals('Only "<br><i><em><b><strong>' . 96 '<sup><sub><u><span>" tags are allowed in the label for a marker.', 97 $errors['drags[3]']); 98 } 99 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body