public function RulesFormsConditionsTestCase::testFormButtonClickedCondition in Rules Forms Support 7
Same name and namespace in other branches
- 7.2 rules_forms.test \RulesFormsConditionsTestCase::testFormButtonClickedCondition()
Tests callback for Condition: Form button was clicked.
File
- ./
rules_forms.test, line 482 - Stores tests related to Rules Form.
Class
- RulesFormsConditionsTestCase
- Tests Rules Forms conditions.
Code
public function testFormButtonClickedCondition() {
$form = self::$form;
$form_state = self::$formState;
$form['test_submit'] = array(
'#name' => 'test_submit',
'#type' => 'submit',
'#value' => 'Submit',
'#submit' => 'rules_forms_test_submit',
);
// Test for condition not met.
$form_state['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' => $form_state,
));
$this
->assertFalse($result1, 'Clicked button condition not met.');
// Test for condition met.
$form_state['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' => $form_state,
));
$this
->assertTrue($result2, 'Clicked button condition met.');
}