You are here

public function WebformConditionalsTestCase::testWebformConditionals in Webform 7.4

Test that required fields with no default value can't be submitted as-is.

File

tests/WebformConditionalsTestCase.test, line 22

Class

WebformConditionalsTestCase
Webform module conditional tests.

Code

public function testWebformConditionals() {
  $this
    ->drupalLogin($this->webform_users['admin']);
  $this
    ->webformReset();
  $test_components = $this
    ->webformComponents();
  $test_specs = array(
    'match conditional values' => TRUE,
    'mismatch conditional values' => FALSE,
  );

  // Test each component, processing all 'match conditional values' for TRUE
  // and all 'mismatch conditional values for FALSE.
  foreach ($test_components as $key => $component_info) {
    foreach ($test_specs as $values_key => $result) {
      if (isset($component_info[$values_key])) {
        foreach ($component_info[$values_key] as $operator => $match_value) {
          $this
            ->webformTestConditionalComponent($component_info['component'], $component_info['sample values'], $operator, $match_value, $result);
        }
      }
    }
  }
  $this
    ->drupalLogout();

  // Test that the whole conditional is deleted when all source components are
  // deleted. Inital setup: Two components. One source (c1) one target (c2).
  $node = (object) array(
    'type' => 'webform',
    'title' => 'Conditional test',
  );
  $default = array(
    'type' => 'textfield',
    'pid' => 0,
  );
  webform_component_defaults($default);
  node_object_prepare($node);
  $node->webform['components'][1] = array(
    'cid' => 1,
    'form_key' => 'c1',
  ) + $default;
  $node->webform['components'][2] = array(
    'cid' => 2,
    'form_key' => 'c2',
  ) + $default;
  $node->webform['conditionals'][0] = array(
    'rgid' => 0,
    'andor' => NULL,
    'weight' => -1,
    'rules' => array(
      array(
        'source_type' => 'component',
        'source' => 1,
        'operator' => 'not_empty',
      ),
    ),
    'actions' => array(
      array(
        'target_type' => 'component',
        'target' => 2,
        'action' => 'show',
      ),
    ),
  );
  node_save($node);

  // Delete the source.
  unset($node->webform['components'][1]);
  node_save($node);
  $this
    ->assertEqual(array(), $node->webform['conditionals'], 'The whole conditional is deleted when all source components are deleted.');
}