rules_forms.test in Rules Forms Support 7.2
Same filename and directory in other branches
Rules Forms Support tests.
File
rules_forms.testView source
<?php
/**
* @file
* Rules Forms Support tests.
*/
/**
* Rules Forms Support test class.
*/
class RulesFormsInterfaceTestCase extends DrupalWebTestCase {
/**
* Provides a user with permissions to administer rules forms.
*/
protected $privilegeUser;
/**
* Defines test information.
*/
public static function getInfo() {
return array(
'name' => 'Form activation and interface',
'description' => 'Tests the administrative interface and form event activation process.',
'group' => 'Rules Forms',
);
}
/**
* Sets up the test.
*/
public function setUp() {
parent::setUp('rules_forms', 'rules');
$this->privileged_user = $this
->drupalCreateUser(array(
'administer nodes',
'access content',
'create article content',
'administer rules forms rules',
'administer rules forms',
));
$this
->drupalLogin($this->privileged_user);
}
/**
* Tests the administrative interface.
*/
public function testFormActivation() {
$this
->drupalGet(RULES_FORMS_ADMIN_PATH);
$this
->assertNoText(t('Events enabled forms'), t('No forms are activated yet.'));
$this
->assertNoText(t('Form elements'));
// Activate form event messages.
$edit = array();
$edit['enable_form_activation_message'] = 1;
$this
->drupalPost(RULES_FORMS_ADMIN_PATH, $edit, t('Save settings'));
$this
->assertText(t('The settings have been saved.'));
$this
->drupalGet(RULES_FORMS_ADMIN_PATH);
$this
->assertFieldChecked('edit-enable-form-activation-message');
$this
->drupalGet('node/add/article');
$this
->assertLink('article_node_form', 0, t('Article node form activation link is displayed.'));
// Activate the form.
$this
->clickLink('article_node_form');
$this
->assertText(t('Custom form label'));
$edit = array();
$edit['form_id_label'] = 'Article node form';
$this
->drupalPost('admin/config/workflow/rules/forms/article_node_form/activate/node%25252Fadd%25252Farticle', $edit, t('Activate'));
$this
->assertText('article_node_form ' . t('has been activated.'));
// Ensure that the newly activated form is shown in administration.
$this
->drupalGet(RULES_FORMS_ADMIN_PATH);
$this
->assertText(t('Events enabled forms'), t('Forms have been activated.'));
$this
->assertFieldByName('form_events[article_node_form]');
$this
->assertFieldByName('reset_form');
$this
->drupalGet('node/add/article');
$form_events = variable_get('rules_forms_event_info', array());
$this
->assertTrue(!empty($form_events['article_node_form']), t('Article node for was activated.'));
$this
->assertTrue(!empty($form_events['article_node_form']['path']), t('Article node form path was stored.'));
$this
->assertTrue(!empty($form_events['article_node_form']['elements']), t('Article node form elements were stored.'));
// Deactivate events for the form.
$edit = array();
$edit['form_events[article_node_form]'] = 1;
$this
->drupalPost(RULES_FORMS_ADMIN_PATH, $edit, t('Deactivate events'));
$this
->drupalGet(RULES_FORMS_ADMIN_PATH);
$this
->assertNoFieldByName('form_events[article_node_form]');
$this
->assertNoFieldByName('reset_form');
// Deactivate form event messages.
$edit = array();
$edit['enable_form_activation_message'] = FALSE;
$this
->drupalPost(RULES_FORMS_ADMIN_PATH, $edit, t('Save settings'));
$this
->drupalGet(RULES_FORMS_ADMIN_PATH);
$this
->assertNoFieldChecked('edit-enable-form-activation-message');
}
}
/**
* Base class for testing Rules Forms rules.
*/
class RulesFormsRulesTestCase extends DrupalWebTestCase {
/**
* Provides a user with permissions to administer rules forms.
*/
protected $privilegeUser;
/**
* A test form for passing as an argument in events.
*/
protected static $form = array(
'form_id' => array(
'#type' => 'value',
'#value' => 'test_form',
),
'title' => array(
'#type' => 'textfield',
'#title' => 'test title',
'#default_value' => 'test',
),
'body' => array(
LANGUAGE_NONE => array(
array(
'value' => array(
'#type' => 'textarea',
'#title' => 'test body',
'#default_value' => 'test',
),
),
),
),
'fieldset' => array(
'#type' => 'fieldset',
'#title' => 'test fieldset',
'select' => array(
'#type' => 'select',
'#title' => 'test select',
'#options' => array(
'first' => t('option1'),
'second' => t('option2'),
),
'#value' => 'test',
'#default_value' => 'test',
),
'checkboxes' => array(
'#type' => 'checkboxes',
'#title' => 'test checkboxes',
'#options' => array(
'frist' => t('1option'),
'sceond' => t('2option'),
),
'#value' => 'test',
'#default_value' => 'test',
),
),
);
/**
* A test form state array for passing as an argument in events.
*/
protected static $formState = array(
'values' => array(
'title' => 'test',
'body' => 'test',
),
);
/**
* Defines a form ID for a form whose events are activated in tests.
*/
protected static $formId = 'test_form';
/**
* Defines testable settings for the rules_forms_form_info variable.
*/
protected static $formInfo = array(
'test_form' => array(
'label' => 'Test form',
'elements' => array(
'textfield:title' => array(
'type' => 'textfield',
'label' => 'Title',
),
'textarea:body:und:0:value' => array(
'type' => 'textarea',
'label' => 'Body',
),
'select:fieldset:select' => array(
'type' => 'select',
'label' => 'Select',
),
'checkboxes:fieldset:checkboxes' => array(
'type' => 'checkboxes',
'label' => 'Checkboxes',
),
),
'path' => 'node/add/article',
'buttons' => FALSE,
'validate' => array(),
'submit' => array(),
'reset' => FALSE,
),
);
/**
* Sets up the test.
*/
public function setUp() {
parent::setUp('rules_forms', 'rules');
$this->privileged_user = $this
->drupalCreateUser(array(
'administer nodes',
'access content',
'create article content',
'administer rules forms rules',
'administer rules forms',
'administer site configuration',
));
$this
->drupalLogin($this->privileged_user);
}
/**
* Enables form events for the node add form via the interface.
*/
protected function enableNodeForm() {
$this
->drupalGet(RULES_FORMS_ADMIN_PATH);
$edit = array();
$edit['enable_form_activation_message'] = 1;
$this
->drupalPost(RULES_FORMS_ADMIN_PATH, $edit, t('Save settings'));
$this
->drupalGet('node/add/article');
$this
->clickLink('article_node_form');
$edit = array();
$edit['form_id_label'] = 'Article node form';
$edit['button_validate_submit'] = 1;
$this
->drupalPost('admin/config/workflow/rules/forms/article_node_form/activate/node%25252Fadd%25252Farticle', $edit, t('Activate'));
}
}
/**
* Tests Rules Forms events.
*/
class RulesFormsEventsTestCase extends RulesFormsRulesTestCase {
/**
* Defines test information.
*/
public static function getInfo() {
return array(
'name' => 'Rules Forms events',
'description' => 'Tests Rules Forms events.',
'group' => 'Rules Forms',
);
}
/**
* Enables modules and logs in the privileged user.
*/
public function setUp() {
parent::setUp();
$this
->enableNodeForm();
}
/**
* Tests the form built event.
*/
public function testFormBuilt() {
$rule = rules_reaction_rule();
$rule
->event('rules_forms_article_node_form_form_built')
->action('drupal_message', array(
'message' => 'Form built successful!',
));
$this
->drupalGet('node/add/article');
$this
->assertNoText('Form built successful!');
$rule
->save('test');
$this
->drupalGet('node/add/article');
$this
->assertText('Form built successful!');
}
/**
* Tests the form validate event.
*/
public function testFormValidate() {
// We use site information page to perform form validation since the node
// edit form uses button level validation.
$edit = array();
$edit['form_id_label'] = 'Article node form';
$edit['button_validate_submit'] = 1;
$this
->drupalPost('admin/config/workflow/rules/forms/system_site_information_settings/activate/admin%25252Fconfig%25252Fsystem%25252Fsite-information', $edit, t('Activate'));
$rule = rules_reaction_rule();
$rule
->event('rules_forms_system_site_information_settings_form_validate')
->action('drupal_message', array(
'message' => 'Form validate successful!',
));
$edit = array();
$edit['site_name'] = 'test';
$edit['site_mail'] = 'test@test.com';
$this
->drupalPost('admin/config/system/site-information', $edit, t('Save configuration'));
$this
->assertNoText('Form validate successful!');
$rule
->save('test');
$this
->drupalPost('admin/config/system/site-information', $edit, t('Save configuration'));
$this
->assertText('Form validate successful!');
}
/**
* Tests the form submit event.
*/
public function testFormSubmit() {
$rule = rules_reaction_rule();
$rule
->event('rules_forms_article_node_form_form_submit')
->action('drupal_message', array(
'message' => 'Form submit successful!',
));
$edit = array();
$edit['title'] = 'test';
$this
->drupalPost('node/add/article', $edit, t('Save'));
$this
->assertNoText('Form submit successful!');
$rule
->save('test');
$this
->drupalPost('node/add/article', $edit, t('Save'));
$this
->assertText('Form submit successful!');
}
/**
* Tests the button validate event.
*/
public function testButtonValidate() {
$rule = rules_reaction_rule();
$rule
->event('rules_forms_article_node_form_button_submit_actions_preview_validate')
->action('drupal_message', array(
'message' => 'Button level validate successful!',
));
$edit = array();
$edit['title'] = 'test';
$this
->drupalPost('node/add/article', $edit, t('Preview'));
$this
->assertNoText('Button level validate successful!');
$rule
->save('test');
$this
->drupalPost('node/add/article', $edit, t('Preview'));
$this
->assertText('Button level validate successful!');
}
/**
* Tests the button submit event.
*/
public function testButtonSubmit() {
$rule = rules_reaction_rule();
$rule
->event('rules_forms_article_node_form_button_submit_actions_submit_submit')
->action('drupal_message', array(
'message' => 'Button level submit successful!',
));
$edit = array();
$edit['title'] = 'test';
$this
->drupalPost('node/add/article', $edit, t('Save'));
$this
->assertNoText('Button level submit successful!');
$rule
->save('test');
$this
->drupalPost('node/add/article', $edit, t('Save'));
$this
->assertText('Button level submit successful!');
}
}
/**
* Tests Rules Forms conditions.
*/
class RulesFormsConditionsTestCase extends RulesFormsRulesTestCase {
/**
* Defines test information.
*/
public static function getInfo() {
return array(
'name' => 'Rules Forms conditions',
'description' => 'Tests Rules Forms condition callbacks.',
'group' => 'Rules Forms',
);
}
/**
* Enables modules and logs in the privileged user.
*/
public function setUp() {
parent::setUp();
}
/**
* Tests callback for Condition: Element has value.
*/
public function testElementValueCondition() {
// Test the condition with a regular value in the field.
$form = array();
$test_form['test'] = array(
'#type' => 'textfield',
'#value' => 'test',
'#default_value' => 'test',
);
$form = new ArrayObject($test_form);
$formState = new ArrayObject(array());
// Test with a correctly matching field value.
$condition1 = rules_condition('rules_forms_element_value', array(
'element' => 'textfield:test',
'value' => 'test',
'regex' => 0,
));
$result1 = $condition1
->executeByArgs(array(
'form' => $form,
'form_state' => $formState,
));
$this
->assertTrue($result1, t('Element values are equal.'));
// Test with an incorrectly matching field value.
$condition2 = rules_condition('rules_forms_element_value', array(
'element' => 'textfield:test',
'value' => 'test',
'regex' => 0,
));
$result2 = $condition2
->executeByArgs(array(
'form' => $form,
'form_state' => $formState,
));
$this
->assertFalse($result2, t('Element values are not equal.'));
// Test with a correctly matching regular expression.
$condition3 = rules_condition('rules_forms_element_value', array(
'element' => 'textfield:test',
'value' => '/se/',
'regex' => 1,
));
$result3 = $condition3
->executeByArgs(array(
'form' => $form,
'form_state' => $formState,
));
$this
->assertTrue($result3, t('Regular expression evaluation: value is equal.'));
// Test with a correctly matching regular expression.
$condition4 = rules_condition('rules_forms_element_value', array(
'element' => 'textfield:test',
'value' => '/es/',
'regex' => 1,
));
$result4 = $condition4
->executeByArgs(array(
'form' => $form,
'form_state' => $formState,
));
$this
->assertFalse($result4, t('Regular expression evaluation: value is not equal.'));
// Test the condition with only a default value in the field.
unset($test_form['test']['#value']);
$form = new ArrayObject($test_form);
// Test with a correctly matching default field value.
$condition5 = rules_condition('rules_forms_element_value', array(
'element' => 'textfield:test',
'value' => 'test',
'regex' => 0,
));
$result5 = $condition5
->executeByArgs(array(
'form' => $form,
'form_state' => $formState,
));
$this
->assertTrue($result5, t('Element values are equal.'));
// Test with an incorrectly matching default field value.
$condition6 = rules_condition('rules_forms_element_value', array(
'element' => 'textfield:test',
'value' => 'test',
'regex' => 0,
));
$result6 = $condition6
->executeByArgs(array(
'form' => $form,
'form_state' => $formState,
));
$this
->assertFalse($result6, t('Element values are not equal.'));
// Test with a correctly matching regular expression default value.
$condition7 = rules_condition('rules_forms_element_value', array(
'element' => 'textfield:test',
'value' => '/se/',
'regex' => 1,
));
$result7 = $condition7
->executeByArgs(array(
'form' => $form,
'form_state' => $formState,
));
$this
->assertTrue($result7, t('Regular expression evaluation: value is equal.'));
// Test with a correctly matching regular expression.
$condition8 = rules_condition('rules_forms_element_value', array(
'element' => 'textfield:test',
'value' => '/es/',
'regex' => 1,
));
$result8 = $condition8
->executeByArgs(array(
'form' => $form,
'form_state' => $formState,
));
$this
->assertFalse($result8, t('Regular expression evaluation: value is not equal.'));
}
/**
* Tests callback for Condition: Element value has changed.
*/
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.');
}
/**
* Tests callback for Condition: Form button was clicked.
*/
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.');
}
}
/**
* Tests Rules Forms actions.
*/
class RulesFormsActionsTestCase extends RulesFormsRulesTestCase {
/**
* Defines test information.
*/
public static function getInfo() {
return array(
'name' => 'Rules Forms actions',
'description' => 'Tests Rules Forms action callbacks.',
'group' => 'Rules Forms',
);
}
/**
* Enables modules and logs in the privileged user.
*/
public function setUp() {
parent::setUp();
}
/**
* Tests callback for Action: Set element title.
*/
public function testestTitleAction() {
$form = array();
$form['test'] = array(
'#type' => 'textfield',
'#title' => 'test',
);
$form = new ArrayObject($form);
$action = rules_action('rules_forms_set_title', array(
'element' => 'textfield:test',
'title' => 'test',
));
$action
->executeByArgs(array(
'form' => $form,
));
$this
->assertEqual($form['test']['#title'], 'test');
}
/**
* Tests callback for Action: Set element description.
*/
public function testestDescriptionAction() {
$form = array();
$form['test'] = array(
'#type' => 'textfield',
'#description' => t('test'),
);
$form = new ArrayObject($form);
$action = rules_action('rules_forms_set_description', array(
'element' => 'textfield:test',
'description' => 'test',
));
$action
->executeByArgs(array(
'form' => $form,
));
$this
->assertEqual($form['test']['#description'], 'test');
}
/**
* Tests callback for Action: Hide form element.
*/
public function testHideAction() {
$form = array();
$form['test'] = array(
'#type' => 'textfield',
'#access' => FALSE,
);
$form = new ArrayObject($form);
$action = rules_action('rules_forms_set_access', array(
'element' => 'textfield:test',
'access' => 1,
));
$action
->executeByArgs(array(
'form' => $form,
));
$this
->assertFalse($form['test']['#access']);
}
/**
* Tests callback for Action: Disable form element.
*/
public function testestDisabledAction() {
$form = array();
$form['test'] = array(
'#type' => 'textfield',
'#disabled' => FALSE,
);
$form = new ArrayObject($form);
$action = rules_action('rules_forms_set_disabled', array(
'element' => 'textfield:test',
'disabled' => 1,
));
$action
->executeByArgs(array(
'form' => $form,
));
$this
->assertTrue($form['test']['#disabled']);
}
/**
* Tests callback for Action: Require form element.
*/
public function testestRequiredAction() {
$form = array();
$form['test'] = array(
'#type' => 'textfield',
'#required' => FALSE,
);
$form = new ArrayObject($form);
$action = rules_action('rules_forms_set_required', array(
'element' => 'textfield:test',
'require' => 1,
));
$action
->executeByArgs(array(
'form' => $form,
));
$this
->assertTrue($form['test']['#required']);
}
/**
* Tests callback for Action: Set multiple value options.
*/
public function testestOptionsAction() {
$form = array();
$form['test'] = array(
'#type' => 'textfield',
'#options' => array(
'first' => 'test',
),
);
$form = new ArrayObject($form);
$action = rules_action('rules_forms_set_options', array(
'element' => 'textfield:test',
'options' => 'first|test' . "\r\n" . 'second|test',
));
$action
->executeByArgs(array(
'form' => $form,
));
$this
->assertEqual($form['test']['#options'], array(
'first' => 'test',
'second' => 'test',
));
}
/**
* Tests callback for Action: Set default value of a form element.
*/
public function testestDefaultAction() {
$form = array();
$form['test'] = array(
'#type' => 'textfield',
'#default_value' => 'test',
);
$form = new ArrayObject($form);
$action = rules_action('rules_forms_set_default', array(
'element' => 'textfield:test',
'value' => 'test',
));
$action
->executeByArgs(array(
'form' => $form,
));
$this
->assertEqual($form['test']['#default_value'], 'test');
}
/**
* Tests callback for Action: Set element weight.
*/
public function testestWeightAction() {
$form = array();
$form['test'] = array(
'#type' => 'textfield',
'#weight' => 0,
);
$form = new ArrayObject($form);
$action = rules_action('rules_forms_set_weight', array(
'element' => 'textfield:test',
'weight' => 20,
));
$action
->executeByArgs(array(
'form' => $form,
));
$this
->assertEqual($form['test']['#weight'], 20);
}
/**
* Tests callback for Action: Set element prefix/suffix HTML.
*/
public function testestPrefixSuffixAction() {
$form = array();
$form['test'] = array(
'#type' => 'textfield',
'#prefix' => 'test',
'#suffix' => 'test',
);
$form = new ArrayObject($form);
$action = rules_action('rules_forms_set_prefix_suffix', array(
'element' => 'textfield:test',
'prefix' => '<div id="test">',
'suffix' => '</div>',
));
$action
->executeByArgs(array(
'form' => $form,
));
$this
->assertEqual($form['test']['#prefix'], '<div id="test">');
$this
->assertEqual($form['test']['#suffix'], '</div>');
}
}
/**
* Tests Rules Forms actions.
*/
class RulesFormsAPITestCase extends RulesFormsRulesTestCase {
/**
* Defines test information.
*/
public static function getInfo() {
return array(
'name' => 'API functions',
'description' => 'Tests Rules Forms API functions.',
'group' => 'Rules Forms',
);
}
/**
* Enables modules and logs in the privileged user.
*/
public function setUp() {
variable_set('rules_forms_form_info', self::$formInfo);
parent::setUp();
}
/**
* Tests _rules_forms_get_element().
*/
public function testGetElement() {
// Test retrieving the element.
$form = self::$form;
$element_id = 'select:fieldset:select';
$element =& _rules_forms_get_element($form, $element_id);
$this
->assertEqual($element, array(
'#type' => 'select',
'#title' => 'test select',
'#options' => array(
'first' => t('option1'),
'second' => t('option2'),
),
'#value' => 'test',
'#default_value' => 'test',
));
// Test the reference.
$element['#title'] = 'test select';
$this
->assertEqual($form['fieldset']['select']['#title'], 'test select');
}
/**
* Tests _rules_forms_get_elements().
*/
public function testGetElements() {
variable_set('rules_forms_form_info', self::$formInfo);
$form = self::$form;
$elements =& _rules_forms_get_elements($form);
foreach ($elements as &$element) {
$element['test'] = 'test';
}
// Ensure that references are preserved by _rules_forms_get_elements().
$message = 'Ensure the reference to $form is preserved.';
$this
->assertTrue(isset($form['title']['test']) && $form['title']['test'] == 'test', $message);
$this
->assertTrue(isset($form['body'][LANGUAGE_NONE][0]['value']['test']) && $form['body'][LANGUAGE_NONE][0]['value']['test'] == 'test', $message);
$this
->assertTrue(isset($form['fieldset']['select']['test']) && $form['fieldset']['select']['test'] == 'test', $message);
$this
->assertTrue(isset($form['fieldset']['checkboxes']['test']) && $form['fieldset']['checkboxes']['test'] == 'test', $message);
$form = array(
'form_id' => array(
'#value' => 'test',
),
);
$array =& _rules_forms_get_elements($form);
$this
->assertTrue(empty($array));
}
/**
* Tests rules_forms_get_form_info().
*/
public function testGetFormInfo() {
variable_set('rules_forms_form_info', self::$formInfo);
// Test getting all form info.
$info = rules_forms_get_form_info();
$this
->assertEqual($info, self::$formInfo);
// Test getting info by form ID.
$formId = key(self::$formInfo);
$formInfo = rules_forms_get_form_info($formId);
$this
->assertEqual($formInfo, self::$formInfo[$formId]);
// Test getting info by $form array.
$formInfo = rules_forms_get_form_info(self::$form);
$this
->assertEqual($formInfo, self::$formInfo[self::$form['form_id']['#value']]);
}
/**
* Tests rules_forms_save_form_info().
*/
public function testSaveFormInfo() {
variable_set('rules_forms_form_info', self::$formInfo);
$formInfo = self::$formInfo;
$formInfo['label'] = 'save test';
rules_forms_save_form_info(self::$formId, $formInfo);
$result = variable_get('rules_forms_form_info', array());
$this
->assertTrue($result[self::$formId]['label'] == 'save test');
}
/**
* Tests rules_forms_get_element_info().
*/
public function testGetElementInfo() {
variable_set('rules_forms_form_info', self::$formInfo);
$element_info = rules_forms_get_element_info(self::$formId);
$this
->assertEqual($element_info, self::$formInfo[self::$formId]['elements']);
}
/**
* Tests rules_forms_get_element_ids().
*/
public function testGetElementIds() {
variable_set('rules_forms_form_info', self::$formInfo);
$element_ids = rules_forms_get_element_ids(self::$formId);
$this
->assertEqual($element_ids, array_keys(self::$formInfo[self::$formId]['elements']));
}
/**
* Tests rules_forms_activate_form().
*/
public function testActivateForm() {
variable_set('rules_forms_form_info', self::$formInfo);
$formId = 'activate_test';
$formInfo = array(
'label' => 'Activate test',
'elements' => array(),
'buttons' => FALSE,
);
rules_forms_activate_form($formId, $formInfo);
$info = variable_get('rules_forms_form_info', array());
$this
->assertEqual($info[$formId], $formInfo, 'Ensure the form was activated.');
}
/**
* Tests rules_forms_deactivate_form().
*/
public function testDeactivateForm() {
$this
->testActivateForm();
$info = variable_get('rules_forms_form_info', array());
$this
->assertTrue(isset($info['activate_test']), 'Ensure the form was activated.');
rules_forms_deactivate_form('activate_test');
$new_info = variable_get('rules_forms_form_info', array());
$this
->assertTrue(!isset($new_info['activate_test']), 'Ensure the form was deactivated.');
}
/**
* Tests rules_forms_event_build().
*/
public function testEventBuild() {
variable_set('rules_forms_form_info', self::$formInfo);
$formId = self::$form['form_id']['#value'];
rules_forms_event_build(self::$form, self::$formState, $formId);
foreach (self::$formInfo[$formId]['elements'] as $element_id => $info) {
$this
->assertTrue(isset($_SESSION['rules_forms_form_values'][$formId][$element_id]), 'Ensure the session variable was set for the element.');
// Values should always be 'test' whether it came from.
$this
->assertTrue($_SESSION['rules_forms_form_values'][$formId][$element_id] == 'test');
}
}
/**
* Tests rules_forms_event_submit().
*/
public function testEventSubmit() {
variable_set('rules_forms_form_info', self::$formInfo);
// Ensure that the session variables are unset for the form.
$formId = self::$form['form_id']['#value'];
$_SESSION['rules_forms_form_values'][$formId] = array(
'textfield:title' => 'test',
'textarea:body:und:0:value' => 'test',
);
rules_forms_event_submit(self::$form, self::$formState);
$this
->assertFalse(isset($_SESSION['rules_forms_form_values'][$formId]), 'Ensure the session variable is unset.');
}
/**
* Tests rules_forms_event_button_submit().
*/
public function testEventButtonSubmit() {
// Add the button to the $formInfo array.
$formInfo = self::$formInfo;
$formInfo[self::$formId]['submit']['fieldset:button:test'] = array();
variable_set('rules_forms_form_info', $formInfo);
// Indicate that this button was clicked.
$formId = self::$form['form_id']['#value'];
$formState = self::$formState;
$formState['triggering_element'] = array(
'#rules_forms_element_id' => 'fieldset:button:test',
);
// Ensure that the session variables are unset for the form.
$_SESSION['rules_forms_form_values'][$formId] = array(
'textfield:title' => 'test',
'textarea:body:und:0:value' => 'test',
);
rules_forms_event_button_submit(self::$form, $formState);
$this
->assertFalse(isset($_SESSION['rules_forms_form_values'][$formId]), 'Ensure the session variable is unset.');
}
}
Classes
Name | Description |
---|---|
RulesFormsActionsTestCase | Tests Rules Forms actions. |
RulesFormsAPITestCase | Tests Rules Forms actions. |
RulesFormsConditionsTestCase | Tests Rules Forms conditions. |
RulesFormsEventsTestCase | Tests Rules Forms events. |
RulesFormsInterfaceTestCase | Rules Forms Support test class. |
RulesFormsRulesTestCase | Base class for testing Rules Forms rules. |