You are here

public function RulesFormsConditionsTestCase::testFormButtonClickedCondition in Rules Forms Support 7.2

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

Tests callback for Condition: Form button was clicked.

File

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

Class

RulesFormsConditionsTestCase
Tests Rules Forms conditions.

Code

public function testFormButtonClickedCondition() {
  $form = self::$form;
  $formState = self::$formState;
  $form['test_submit'] = array(
    '#name' => 'test_submit',
    '#type' => 'submit',
    '#value' => 'Submit',
    '#submit' => 'rules_forms_test_submit',
  );

  // Test for condition not met.
  $formState['triggering_element'] = array(
    '#name' => 'test_button',
    '#type' => 'button',
    '#value' => 'Test',
  );
  $condition1 = rules_condition('rules_forms_button_clicked', array(
    'element' => 'submit:test_submit',
  ));
  $result1 = $condition1
    ->executeByArgs(array(
    'form' => $form,
    'form_state' => $formState,
  ));
  $this
    ->assertFalse($result1, 'Clicked button condition not met.');

  // Test for condition met.
  $formState['triggering_element'] = $form['test_submit'];
  $condition2 = rules_condition('rules_forms_button_clicked', array(
    'element' => 'submit:test_submit',
  ));
  $result2 = $condition2
    ->executeByArgs(array(
    'form' => $form,
    'form_state' => $formState,
  ));
  $this
    ->assertTrue($result2, 'Clicked button condition met.');
}