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 * Fixture for testing the functionality of read-only forms. 19 * 20 * @package core 21 * @copyright 2018 The Open University 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 require_once(__DIR__ . '/../../../config.php'); 26 require_once($CFG->libdir . '/formslib.php'); 27 28 $sections = optional_param('sections', 2, PARAM_INT); 29 require_login(); 30 31 32 /** 33 * The form used for testing. 34 */ 35 class test_read_only_form extends moodleform { 36 protected function definition() { 37 $mform = $this->_form; 38 39 $sections = $this->_customdata; 40 41 $mform->addElement('header', 'sectionheader', 'First section'); 42 43 $mform->addElement('text', 'name', 'Name'); 44 $mform->setDefault('name', 'Important information'); 45 $mform->setType('name', PARAM_RAW); 46 47 $mform->setExpanded('sectionheader', false); 48 49 if ($sections > 1) { 50 $mform->addElement('header', 'secondsection', 'Other section header'); 51 52 $mform->addElement('text', 'other', 'Other'); 53 $mform->setDefault('other', 'Other information'); 54 $mform->setType('other', PARAM_RAW); 55 56 $mform->setExpanded('secondsection', false); 57 } 58 59 $this->add_action_buttons(); 60 } 61 } 62 63 $PAGE->set_context(context_system::instance()); 64 $PAGE->set_url('/lib/tests/fixtures/readonlyform.php'); 65 66 $form = new test_read_only_form(null, $sections, 'post', '', null, false); // The false here is $editable. 67 68 echo $OUTPUT->header(); 69 echo $form->render(); 70 echo $OUTPUT->footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body