Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
require_once(__DIR__ . '/../../../../../config.php');
18
 
19
defined('BEHAT_SITE_RUNNING') || die();
20
 
21
global $CFG, $PAGE, $OUTPUT;
22
require_once($CFG->libdir . '/formslib.php');
23
$PAGE->set_url('/lib/form/tests/behat/fixtures/filemanager_hideif_disabledif_form.php');
24
$PAGE->add_body_class('limitedwidth');
25
require_login();
26
$PAGE->set_context(core\context\system::instance());
27
 
28
/**
29
 * Test class for disabling and hiding a filemanager element.
30
 *
31
 * @copyright 2024 David Woloszyn <david.woloszyn@moodle.com>
32
 * @package   core_form
33
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
 */
35
class test_filemanager_hideif_disabledif_form extends moodleform {
36
 
37
    /**
38
     * Form definition.
39
     */
40
    public function definition(): void {
41
        $mform = $this->_form;
42
 
43
        $attributes = [];
44
        $attributes['maxbytes'] = '1024';
45
        $attributes['accepted_types'] = array_map('trim', explode(',', '.odt, .pdf'));
46
        $attributes['subdirs'] = false;
47
        $attributes['maxfiles'] = 3;
48
 
49
        // Radio buttons.
50
        $radiogroup = [
51
            $mform->createElement('radio', 'some_radios', '', 'Enable', '1'),
52
            $mform->createElement('radio', 'some_radios', '', 'Disable', '2'),
53
            $mform->createElement('radio', 'some_radios', '', 'Hide', '3'),
54
        ];
55
 
56
        $mform->addGroup($radiogroup, 'some_radios_group', 'Enable/Disable/Hide', ' ', false);
57
        $mform->setDefault('some_radios', 1);
58
 
59
        // Standard file manager.
60
        $mform->addElement('filemanager', 'some_filemanager', 'Standard filemanager', '', $attributes);
61
        $mform->disabledIf('some_filemanager', 'some_radios', 'eq', '2');
62
        $mform->hideIf('some_filemanager', 'some_radios', 'eq', '3');
63
 
64
        // File manager nested in group.
65
        $filemanagergroup = [];
66
        $filemanagergroup[] = $mform->createElement('filemanager', 'some_filemanager_group', '', null, $attributes);
67
        $mform->addGroup($filemanagergroup, 'filemanager_group', 'Group filemanager');
68
        $mform->disabledIf('filemanager_group', 'some_radios', 'eq', '2');
69
 
70
        $this->add_action_buttons();
71
    }
72
}
73
 
74
$form = new test_filemanager_hideif_disabledif_form();
75
 
76
echo $OUTPUT->header();
77
$form->display();
78
echo $OUTPUT->footer();