From f3da329da4b0923a8d030a0109749b5e30fd8306 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Fri, 27 Jan 2017 10:11:25 +0800 Subject: [PATCH] MDL-53848 forms: additions to the behat test --- lib/form/tests/behat/hideif.feature | 32 +++++++++++++------ .../tests/fixtures/formhideiftestpage.php | 10 ++++-- lib/formslib.php | 4 +-- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/lib/form/tests/behat/hideif.feature b/lib/form/tests/behat/hideif.feature index 864216a8fa7..26314cf5932 100644 --- a/lib/form/tests/behat/hideif.feature +++ b/lib/form/tests/behat/hideif.feature @@ -15,38 +15,52 @@ Feature: hideIf functionality in forms 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: 6" + And I should see "[testeqhideif] =>" 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: 5" + 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: 5" + 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 - - Scenario: When 'notchecked' hideIf conditions are not met, the relevant elements are shown - When I set the field "Checkbox example" to "1" - Then I should see "Test not checked hideif" And "#id_testnotcheckedhideif" "css_element" should be visible - - Scenario: When 'notchecked' hideIf conditions are met, the relevant elements are hidden - When I set the field "Checkbox example" to "0" - Then I should not see "Test not checked hideif" - And "#id_testnotcheckedhideif" "css_element" should not be visible + And I press "Submit" + And I should see "Number of submitted form elements: 5" + 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 "#id_testinhideif" "css_element" should be visible + And I press "Submit" + And I should see "Number of submitted form elements: 6" + 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 "#id_testinhideif" "css_element" should not be visible + And I press "Submit" + And I should see "Number of submitted form elements: 5" + And I should not see "[testinhideif] =>" diff --git a/lib/form/tests/fixtures/formhideiftestpage.php b/lib/form/tests/fixtures/formhideiftestpage.php index 86a856ed0f7..722d1b09833 100644 --- a/lib/form/tests/fixtures/formhideiftestpage.php +++ b/lib/form/tests/fixtures/formhideiftestpage.php @@ -22,7 +22,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -require_once(dirname(__FILE__).'/../../../../config.php'); +require_once(__DIR__.'/../../../../config.php'); global $CFG, $PAGE, $OUTPUT; require_once($CFG->libdir.'/formslib.php'); @@ -71,13 +71,19 @@ class hideif_form extends moodleform { $mform->addElement('text', 'testinhideif', 'Test in hideif'); $mform->setType('testinhideif', PARAM_TEXT); $mform->hideIf('testinhideif', 'selectexample', 'in', [1, 2, 5]); + + $mform->addElement('submit', 'submitform', 'Submit'); } } -$PAGE->set_url('/lib/tests/fixtures/form_hideif.php'); +$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/lib/formslib.php b/lib/formslib.php index 5c41ad2d9d9..146a389cf84 100644 --- a/lib/formslib.php +++ b/lib/formslib.php @@ -2448,7 +2448,7 @@ require(["core/event", "jquery"], function(Event, $) { if ($element == $dependentOn) { continue; } - $result[$dependentOn][$condition][$value][0][] = $element; + $result[$dependentOn][$condition][$value][self::DEP_DISABLE][] = $element; } } } @@ -2470,7 +2470,7 @@ require(["core/event", "jquery"], function(Event, $) { if ($element == $dependenton) { continue; } - $result[$dependenton][$condition][$value][1][] = $element; + $result[$dependenton][$condition][$value][self::DEP_HIDE][] = $element; } } }