diff --git a/testswarm_forms/testswarm_forms.module b/testswarm_forms/testswarm_forms.module index 1bf2614..85c5321 100644 --- a/testswarm_forms/testswarm_forms.module +++ b/testswarm_forms/testswarm_forms.module @@ -358,6 +358,15 @@ function testswarm_forms_test_states() { 'value', ), ), + 'operators_tested' => array( + '#theme' => 'item_list', + '#title' => t('The following operators are tested:'), + '#items' => array( + 'AND', + 'OR', + 'XOR', + ), + ), ); $form['text1'] = array( '#type' => 'textfield', @@ -502,7 +511,101 @@ function testswarm_forms_test_states() { '#description' => t("Type 'expand' to expand Fieldset2."), ); + $form['fieldset_or'] = array( + '#type' => 'fieldset', + '#title' => t('Test OR operator'), + '#description' => t('Check one or both of the checkboxes to show the textfield'), + ); + $form['fieldset_or']['or_checkbox_1'] = array( + '#type' => 'checkbox', + '#title' => t('Check me'), + ); + + $form['fieldset_or']['or_checkbox_2'] = array( + '#type' => 'checkbox', + '#title' => t('Or me'), + ); + + $form['fieldset_or']['or_textfield'] = array( + '#type' => 'textfield', + '#title' => t('Or condition'), + '#default_value' => t('The or condition is true!'), + '#states' => array( + 'visible' => array( + array( + array( + ':input[name="or_checkbox_1"]' => array('checked' => TRUE), + ), + array( + ':input[name="or_checkbox_2"]' => array('checked' => TRUE), + ), + ), + ), + ), + ); + $form['fieldset_xor'] = array( + '#type' => 'fieldset', + '#title' => t('Test XOR operator'), + '#description' => t('Check one of the checkboxes to show the textfield'), + ); + + $form['fieldset_xor']['xor_checkbox_1'] = array( + '#type' => 'checkbox', + '#title' => t('Check me'), + ); + + $form['fieldset_xor']['xor_checkbox_2'] = array( + '#type' => 'checkbox', + '#title' => t('X-Or me'), + ); + + $form['fieldset_xor']['xor_textfield'] = array( + '#type' => 'textfield', + '#title' => t('X-Or condition'), + '#default_value' => t('The x-or condition is true!'), + '#states' => array( + 'visible' => array( + array( + array( + ':input[name="xor_checkbox_1"]' => array('checked' => TRUE), + ), + 'xor', + array( + ':input[name="xor_checkbox_2"]' => array('checked' => TRUE), + ), + ), + ), + ), + ); + + $form['fieldset_and'] = array( + '#type' => 'fieldset', + '#title' => t('Test AND operator'), + '#description' => t('Check both of the checkboxes to show the textfield'), + ); + + $form['fieldset_and']['and_checkbox_1'] = array( + '#type' => 'checkbox', + '#title' => t('Check me'), + ); + + $form['fieldset_and']['and_checkbox_2'] = array( + '#type' => 'checkbox', + '#title' => t('And me'), + ); + + $form['fieldset_and']['and_textfield'] = array( + '#type' => 'textfield', + '#title' => t('And condition'), + '#default_value' => t('The and condition is true!'), + '#states' => array( + 'visible' => array( + ':input[name="and_checkbox_1"]' => array('checked' => TRUE), + ':input[name="and_checkbox_2"]' => array('checked' => TRUE), + ), + ), + ); return $form; } diff --git a/testswarm_forms/testswarm_forms.states.test.js b/testswarm_forms/testswarm_forms.states.test.js index b572a65..3f1e9c8 100644 --- a/testswarm_forms/testswarm_forms.states.test.js +++ b/testswarm_forms/testswarm_forms.states.test.js @@ -224,6 +224,84 @@ Drupal.tests.testswarm_forms_states = { }, collapseDelay); }, collapseDelay); } + }, + states_or: function ($, Drupal, window, document, undefined) { + return function() { + expect(5); + // Check if the textfield is hidden on page load. + ok(!$('#edit-or-textfield').is(':visible'), Drupal.t('Textfield hidden on page load')); + // Check one checkbox + $(':input[name="or_checkbox_1"]').click().trigger('change'); + // Check if the textfield is visible + ok($('#edit-or-textfield').is(':visible'), Drupal.t('Textfield visible')); + // Uncheck the first checkbox and check the second checkbox + $(':input[name="or_checkbox_1"]').click().trigger('change'); + $(':input[name="or_checkbox_2"]').click().trigger('change'); + // Check if the textfield is visible + ok($('#edit-or-textfield').is(':visible'), Drupal.t('Textfield visible')); + // Check the first checkbox so both checkboxes are checked + $(':input[name="or_checkbox_1"]').click().trigger('change'); + // Check if the textfield is visible + ok($('#edit-or-textfield').is(':visible'), Drupal.t('Textfield visible')); + // Uncheck both checkboxes. + $(':input[name="or_checkbox_1"]').click().trigger('change'); + $(':input[name="or_checkbox_2"]').click().trigger('change'); + // Check if the textfield is visible + ok(!$('#edit-or-textfield').is(':visible'), Drupal.t('Textfield invisible')); + + } + }, + states_xor: function ($, Drupal, window, document, undefined) { + return function() { + expect(5); + // Check if the textfield is hidden on page load. + ok(!$('#edit-xor-textfield').is(':visible'), Drupal.t('Textfield hidden on page load')); + // Check one checkbox + $(':input[name="xor_checkbox_1"]').click().trigger('change'); + // Check if the textfield is visible + ok($('#edit-xor-textfield').is(':visible'), Drupal.t('Textfield visible')); + // Uncheck the first checkbox and check the second checkbox + $(':input[name="xor_checkbox_1"]').click().trigger('change'); + $(':input[name="xor_checkbox_2"]').click().trigger('change'); + // Check if the textfield is visible + ok($('#edit-xor-textfield').is(':visible'), Drupal.t('Textfield visible')); + // Check the first checkbox so both checkboxes are checked + $(':input[name="xor_checkbox_1"]').click().trigger('change'); + // Check if the textfield is visible + ok(!$('#edit-or-textfield').is(':visible'), Drupal.t('Textfield invisible')); + // Uncheck both checkboxes. + $(':input[name="xor_checkbox_1"]').click().trigger('change'); + $(':input[name="xor_checkbox_2"]').click().trigger('change'); + // Check if the textfield is visible + ok(!$('#edit-xor-textfield').is(':visible'), Drupal.t('Textfield invisible')); + + } + }, + states_and: function ($, Drupal, window, document, undefined) { + return function() { + expect(5); + // Check if the textfield is hidden on page load. + ok(!$('#edit-and-textfield').is(':visible'), Drupal.t('Textfield hidden on page load')); + // Check one checkbox + $(':input[name="and_checkbox_1"]').click().trigger('change'); + // Check if the textfield is visible + ok(!$('#edit-and-textfield').is(':visible'), Drupal.t('Textfield invisible')); + // Uncheck the first checkbox and check the second checkbox + $(':input[name="and_checkbox_1"]').click().trigger('change'); + $(':input[name="and_checkbox_2"]').click().trigger('change'); + // Check if the textfield is visible + ok(!$('#edit-and-textfield').is(':visible'), Drupal.t('Textfield invisible')); + // Check the first checkbox so both checkboxes are checked + $(':input[name="and_checkbox_1"]').click().trigger('change'); + // Check if the textfield is visible + ok($('#edit-and-textfield').is(':visible'), Drupal.t('Textfield visible')); + // Uncheck both checkboxes. + $(':input[name="and_checkbox_1"]').click().trigger('change'); + $(':input[name="and_checkbox_2"]').click().trigger('change'); + // Check if the textfield is visible + ok(!$('#edit-and-textfield').is(':visible'), Drupal.t('Textfield invisible')); + + } } } };