You are here

public function RulesFormsConditionsTestCase::testElementValueChangedCondition in Rules Forms Support 7.2

Same name and namespace in other branches
  1. 7 rules_forms.test \RulesFormsConditionsTestCase::testElementValueChangedCondition()

Tests callback for Condition: Element value has changed.

File

./rules_forms.test, line 476
Rules Forms Support tests.

Class

RulesFormsConditionsTestCase
Tests Rules Forms conditions.

Code

public function testElementValueChangedCondition() {
  $form = self::$form;
  $formState = self::$formState;

  // rules_forms_event_build will set session variables.
  variable_set('rules_forms_form_info', self::$formInfo);
  rules_forms_event_build($form, $formState, self::$formId);

  // Execute condition without changing the value.
  $formState['values']['title'] = 'test';
  $condition1 = rules_condition('rules_forms_element_changed', array(
    'element' => 'textfield:title',
  ));
  $result1 = $condition1
    ->executeByArgs(array(
    'form' => $form,
    'form_state' => $formState,
  ));
  $this
    ->assertFalse($result1, 'Form value has not changed.');

  // Execute condition with changing the value.
  $formState['values']['title'] = 'test';
  $condition2 = rules_condition('rules_forms_element_changed', array(
    'element' => 'textfield:title',
  ));
  $result2 = $condition2
    ->executeByArgs(array(
    'form' => $form,
    'form_state' => $formState,
  ));
  $this
    ->assertTrue($result2, 'Form value has changed.');
}