mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
MDL-53848 mod_assign, formslib: add hideIf to real form and adapt behat tests to use this
This commit is contained in:
parent
8dff6c78bd
commit
527459a4c7
@ -5,68 +5,25 @@ Feature: hideIf functionality in forms
|
||||
If I trigger the hideIf condition then the form elements will be hidden
|
||||
|
||||
Background:
|
||||
Given the following "activities" exist:
|
||||
| activity | name | intro | course | section | idnumber |
|
||||
| label | L1 | <a href="lib/form/tests/fixtures/formhideiftestpage.php">HideIfLink</a> | Acceptance test site | 1 | L1 |
|
||||
Given the following "courses" exist:
|
||||
| fullname | shortname |
|
||||
| Course 1 | C1 |
|
||||
And I log in as "admin"
|
||||
And I am on site homepage
|
||||
And I wait "5" seconds
|
||||
And I follow "HideIfLink"
|
||||
And I am on "Course 1" course homepage
|
||||
And I turn editing mode on
|
||||
|
||||
Scenario: When 'eq' hideIf conditions are not met, the relevant elements are shown
|
||||
When I set the field "Select yesno example" to "Yes"
|
||||
Then I should see "Test eq hideif"
|
||||
And "#id_testeqhideif" "css_element" should be visible
|
||||
And I press "Submit"
|
||||
And I should see "Number of submitted form elements: 7"
|
||||
And I should see "[testeqhideif] =>"
|
||||
When I add a "Assignment" to section "1"
|
||||
And I expand all fieldsets
|
||||
And I set the field "Students submit in groups" to "Yes"
|
||||
Then I should see "Require group to make submission"
|
||||
And I should see "Require all group members submit"
|
||||
And I should see "Grouping for student groups"
|
||||
|
||||
Scenario: When 'eq' hideIf conditions are met, the relevant elements are hidden
|
||||
When I set the field "Select yesno example" to "No"
|
||||
Then I should not see "Test eq hideif"
|
||||
And "#id_testeqhideif" "css_element" should not be visible
|
||||
And I press "Submit"
|
||||
And I should see "Number of submitted form elements: 6"
|
||||
And I should not see "[testeqhideif] =>"
|
||||
|
||||
Scenario: When 'checked' hideIf conditions are not met, the relevant elements are shown
|
||||
When I set the field "Checkbox example" to "0"
|
||||
Then I should see "Test checked hideif"
|
||||
And I should not see "Test not checked hideif"
|
||||
And "#id_testcheckedhideif" "css_element" should be visible
|
||||
And "#id_testnotcheckedhideif" "css_element" should not be visible
|
||||
And I press "Submit"
|
||||
And I should see "Number of submitted form elements: 6"
|
||||
And I should see "[testcheckedhideif] =>"
|
||||
And I should not see "[testnotcheckedhideif] =>"
|
||||
|
||||
Scenario: When 'checked' hideIf conditions are met, the relevant elements are hidden
|
||||
When I set the field "Checkbox example" to "1"
|
||||
Then I should not see "Test checked hideif"
|
||||
And I should see "Test not checked hideif"
|
||||
And "#id_testcheckedhideif" "css_element" should not be visible
|
||||
And "#id_testnotcheckedhideif" "css_element" should be visible
|
||||
And I press "Submit"
|
||||
And I should see "Number of submitted form elements: 6"
|
||||
And I should not see "[testcheckedhideif] =>"
|
||||
And I should see "[testnotcheckedhideif] =>"
|
||||
|
||||
Scenario: When 'in' hideIf conditions are not met, the relevant elements are shown
|
||||
When I set the field "Select example" to "3"
|
||||
Then I should see "Test in hideif"
|
||||
And I should see "Date time example"
|
||||
And I should see "Files"
|
||||
And "#id_testinhideif" "css_element" should be visible
|
||||
And I press "Submit"
|
||||
And I should see "Number of submitted form elements: 8"
|
||||
And I should see "[testinhideif] =>"
|
||||
|
||||
Scenario: When 'in' hideIf conditions are met, the relevant elements are hidden
|
||||
When I set the field "Select example" to "2"
|
||||
Then I should not see "Test in hideif"
|
||||
And I should not see "Date time example"
|
||||
And I should not see "Files"
|
||||
And "#id_testinhideif" "css_element" should not be visible
|
||||
And I press "Submit"
|
||||
And I should see "Number of submitted form elements: 6"
|
||||
And I should not see "[testinhideif] =>"
|
||||
When I add a "Assignment" to section "1"
|
||||
And I expand all fieldsets
|
||||
And I set the field "Students submit in groups" to "No"
|
||||
Then I should not see "Require group to make submission"
|
||||
And I should not see "Require all group members to submit"
|
||||
And I should not see "Grouping for student groups"
|
||||
|
97
lib/form/tests/fixtures/formhideiftestpage.php
vendored
97
lib/form/tests/fixtures/formhideiftestpage.php
vendored
@ -1,97 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* To support behat tests for hideif functionality (which is not yet used by any core forms).
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2016 Davo Smith, Synergy Learning
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once(__DIR__.'/../../../../config.php');
|
||||
global $CFG, $PAGE, $OUTPUT;
|
||||
require_once($CFG->libdir.'/formslib.php');
|
||||
|
||||
// Behat test fixture only.
|
||||
defined('BEHAT_SITE_RUNNING') || die('Only available on Behat test server');
|
||||
require_login();
|
||||
if (!is_siteadmin()) {
|
||||
die('Admin only');
|
||||
}
|
||||
|
||||
/**
|
||||
* Class hideif_form
|
||||
* @copyright 2016 Davo Smith, Synergy Learning
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class hideif_form extends moodleform {
|
||||
|
||||
/**
|
||||
* Form definition.
|
||||
*/
|
||||
protected function definition() {
|
||||
$mform = $this->_form;
|
||||
|
||||
// Use 'selectyesno' to show/hide element.
|
||||
$mform->addElement('selectyesno', 'selectyesnoexample', 'Select yesno example');
|
||||
$mform->setDefault('selectyesnoexample', 0);
|
||||
|
||||
$mform->addElement('text', 'testeqhideif', 'Test eq hideif');
|
||||
$mform->setType('testeqhideif', PARAM_TEXT);
|
||||
$mform->hideIf('testeqhideif', 'selectyesnoexample', 'eq', 0);
|
||||
|
||||
// Use 'checkbox' to show/hide element.
|
||||
$mform->addElement('advcheckbox', 'checkboxexample', 'Checkbox example');
|
||||
$mform->setDefault('checkboxexample', 0);
|
||||
|
||||
$mform->addElement('text', 'testcheckedhideif', 'Test checked hideif');
|
||||
$mform->setType('testcheckedhideif', PARAM_TEXT);
|
||||
$mform->hideIf('testcheckedhideif', 'checkboxexample', 'checked');
|
||||
|
||||
$mform->addElement('text', 'testnotcheckedhideif', 'Test not checked hideif');
|
||||
$mform->setType('testnotcheckedhideif', PARAM_TEXT);
|
||||
$mform->hideIf('testnotcheckedhideif', 'checkboxexample', 'notchecked');
|
||||
|
||||
// Use 'select' to show/hide element.
|
||||
$opts = [1, 2, 3, 4, 5];
|
||||
$opts = array_combine($opts, $opts);
|
||||
$mform->addElement('select', 'selectexample', 'Select example', $opts);
|
||||
$mform->setDefault('selectexample', 1);
|
||||
|
||||
$mform->addElement('text', 'testinhideif', 'Test in hideif');
|
||||
$mform->setType('testinhideif', PARAM_TEXT);
|
||||
$mform->hideIf('testinhideif', 'selectexample', 'in', [1, 2, 5]);
|
||||
$mform->addElement('date_time_selector', 'testdatetime', 'Date time example', array('optional' => true));
|
||||
$mform->hideIf('testdatetime', 'selectexample', 'in', [1, 2, 5]);
|
||||
$mform->addElement('filemanager', 'files_filemanager', 'Files', null, array());
|
||||
$mform->hideIf('files_filemanager', 'selectexample', 'in', [1, 2, 5]);
|
||||
|
||||
$mform->addElement('submit', 'submitform', 'Submit');
|
||||
}
|
||||
}
|
||||
|
||||
$PAGE->set_url('/lib/form/tests/fixtures/formhideiftestpage.php');
|
||||
$PAGE->set_context(context_system::instance());
|
||||
$form = new hideif_form();
|
||||
|
||||
echo $OUTPUT->header();
|
||||
if ($data = $form->get_data()) {
|
||||
echo "<p>Number of submitted form elements: " . count((array)$data) . "</p>";
|
||||
print_object($data);
|
||||
}
|
||||
$form->display();
|
||||
echo $OUTPUT->footer();
|
@ -148,12 +148,12 @@ class mod_assign_mod_form extends moodleform_mod {
|
||||
'preventsubmissionnotingroup',
|
||||
'assign');
|
||||
$mform->setType('preventsubmissionnotingroup', PARAM_BOOL);
|
||||
$mform->disabledIf('preventsubmissionnotingroup', 'teamsubmission', 'eq', 0);
|
||||
$mform->hideIf('preventsubmissionnotingroup', 'teamsubmission', 'eq', 0);
|
||||
|
||||
$name = get_string('requireallteammemberssubmit', 'assign');
|
||||
$mform->addElement('selectyesno', 'requireallteammemberssubmit', $name);
|
||||
$mform->addHelpButton('requireallteammemberssubmit', 'requireallteammemberssubmit', 'assign');
|
||||
$mform->disabledIf('requireallteammemberssubmit', 'teamsubmission', 'eq', 0);
|
||||
$mform->hideIf('requireallteammemberssubmit', 'teamsubmission', 'eq', 0);
|
||||
$mform->disabledIf('requireallteammemberssubmit', 'submissiondrafts', 'eq', 0);
|
||||
|
||||
$groupings = groups_get_all_groupings($assignment->get_course()->id);
|
||||
@ -166,7 +166,7 @@ class mod_assign_mod_form extends moodleform_mod {
|
||||
$name = get_string('teamsubmissiongroupingid', 'assign');
|
||||
$mform->addElement('select', 'teamsubmissiongroupingid', $name, $options);
|
||||
$mform->addHelpButton('teamsubmissiongroupingid', 'teamsubmissiongroupingid', 'assign');
|
||||
$mform->disabledIf('teamsubmissiongroupingid', 'teamsubmission', 'eq', 0);
|
||||
$mform->hideIf('teamsubmissiongroupingid', 'teamsubmission', 'eq', 0);
|
||||
if ($assignment->has_submissions_or_grades()) {
|
||||
$mform->freeze('teamsubmissiongroupingid');
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user