Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 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
 * Test for setting date fields in behat
19
 *
20
 * @package    core_form
21
 * @copyright  Marina Glancy
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
require_once(__DIR__ . '/../../../../../config.php');
26
 
27
defined('BEHAT_SITE_RUNNING') || die();
28
 
29
global $CFG, $PAGE, $OUTPUT;
30
require_once($CFG->libdir . '/formslib.php');
31
$PAGE->set_url('/lib/form/tests/behat/fixtures/dates_form.php');
32
$PAGE->add_body_class('limitedwidth');
33
require_login();
34
$PAGE->set_context(context_system::instance());
35
 
36
/**
37
 * Test form class adding all types of date elements
38
 *
39
 * @package core_form
40
 */
41
class test_dates_form extends moodleform {
42
    /**
43
     * Define the form.
44
     */
45
    public function definition() {
46
        $mform = $this->_form;
47
 
48
        $mform->addElement('date_selector', 'simpledateonly', 'Simple only date');
49
        $mform->addElement('date_selector', 'simpleoptionaldateonly', 'Simple optional only date', ['optional' => true]);
50
        $mform->addElement('date_time_selector', 'simpledatetime', 'Simple date and time');
51
        $mform->addElement('date_time_selector', 'simpleoptionaldatetime', 'Simple optional date and time', ['optional' => true]);
52
 
53
        $group = [];
54
        $group[] = $mform->createElement('date_selector', 'group1dateonly', 'Group1 only date');
55
        $group[] = $mform->createElement('date_selector', 'group1optionaldateonly', 'Group1 optional only date',
56
            ['optional' => true]);
57
        $group[] = $mform->createElement('date_time_selector', 'group1datetime', 'Group1 date and time');
58
        $group[] = $mform->createElement('date_time_selector', 'group1optionaldatetime', 'Group1 optional date and time',
59
            ['optional' => true]);
60
        $mform->addGroup($group, 'dategroup1', 'Date group1', '', false);
61
 
62
        $group = [];
63
        $group[] = $mform->createElement('date_selector', 'group2dateonly', 'Group2 only date');
64
        $group[] = $mform->createElement('date_selector', 'group2optionaldateonly', 'Group2 optional only date',
65
            ['optional' => true]);
66
        $group[] = $mform->createElement('date_time_selector', 'group2datetime', 'Group2 date and time');
67
        $group[] = $mform->createElement('date_time_selector', 'group2optionaldatetime', 'Group2 optional date and time',
68
            ['optional' => true]);
69
        $mform->addGroup($group, 'dategroup2', 'Date group2', '', true);
70
 
71
        $this->add_action_buttons(false, 'Send form');
72
    }
73
}
74
 
75
echo $OUTPUT->header();
76
 
77
echo "<h2>Quickform integration test</h2>";
78
 
79
$form = new test_dates_form();
80
 
81
$data = $form->get_data();
82
if ($data) {
83
    echo "<h3>Submitted data</h3>";
84
    echo '<div id="submitted_data"><ul>';
85
    $data = (array) $data;
86
    foreach ($data as $field => $value) {
87
        if (is_array($value)) {
88
            foreach ($value as $key => $v) {
89
                echo "<li id=\"sumbmitted_{$field}_$key\">{$field}[$key]: $v</li>";
90
            }
91
        } else {
92
            echo "<li id=\"sumbmitted_{$field}\">$field: $value</li>";
93
        }
94
    }
95
    echo '</ul></div>';
96
}
97
$form->display();
98
 
99
echo $OUTPUT->footer();