From 527459a4c7946454e0c8d620c371affea3f65c44 Mon Sep 17 00:00:00 2001 From: Davo Smith Date: Thu, 17 Aug 2017 14:47:44 +0100 Subject: [PATCH] MDL-53848 mod_assign, formslib: add hideIf to real form and adapt behat tests to use this --- lib/form/tests/behat/hideif.feature | 77 ++++----------- .../tests/fixtures/formhideiftestpage.php | 97 ------------------- mod/assign/mod_form.php | 6 +- 3 files changed, 20 insertions(+), 160 deletions(-) delete mode 100644 lib/form/tests/fixtures/formhideiftestpage.php diff --git a/lib/form/tests/behat/hideif.feature b/lib/form/tests/behat/hideif.feature index f4945129b97..04027bacd1b 100644 --- a/lib/form/tests/behat/hideif.feature +++ b/lib/form/tests/behat/hideif.feature @@ -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 | HideIfLink | 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" diff --git a/lib/form/tests/fixtures/formhideiftestpage.php b/lib/form/tests/fixtures/formhideiftestpage.php deleted file mode 100644 index 463d4b56d59..00000000000 --- a/lib/form/tests/fixtures/formhideiftestpage.php +++ /dev/null @@ -1,97 +0,0 @@ -. - -/** - * 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 "

Number of submitted form elements: " . count((array)$data) . "

"; - print_object($data); -} -$form->display(); -echo $OUTPUT->footer(); diff --git a/mod/assign/mod_form.php b/mod/assign/mod_form.php index 7f88c0738de..ffb9a159402 100644 --- a/mod/assign/mod_form.php +++ b/mod/assign/mod_form.php @@ -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'); }