rules_forms.test in Rules Forms Support 7
Same filename and directory in other branches
Stores tests related to Rules Form.
File
rules_forms.testView source
<?php
/**
* @file
* Stores tests related to Rules Form.
*/
/**
* Class that tests Rules Forms.
*/
class RulesFormsInterfaceTestCase extends DrupalWebTestCase {
/**
* Provides a user with permissions to administer rules forms.
*
* @var user
*/
protected $user;
/**
* 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->user = $this
->drupalCreateUser(array(
'administer nodes',
'access content',
'create article content',
'administer rules forms rules',
'administer rules forms',
));
$this
->drupalLogin($this->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.
*
* @var user
*/
protected $user;
/**
* A test form for passing as an argument in events.
*
* @var array
*/
protected static $form = array(
'form_id' => array(
'#type' => 'value',
'#value' => 'test_form',
),
'title' => array(
'#type' => 'textfield',
'#title' => 'test title',
'#default_value' => 'tset',
),
'body' => array(
LANGUAGE_NONE => array(
array(
'value' => array(
'#type' => 'textarea',
'#title' => 'test body',
'#default_value' => 'tset',
),
),
),
),
'fieldset' => array(
'#type' => 'fieldset',
'#title' => 'test fieldset',
'select' => array(
'#type' => 'select',
'#title' => 'tset select',
'#options' => array(
'first' => t('option1'),
'second' => t('option2'),
),
'#value' => 'tset',
'#default_value' => 'test',
),
'checkboxes' => array(
'#type' => 'checkboxes',
'#title' => 'test checkboxes',
'#options' => array(
'frist' => t('1option'),
'sceond' => t('2option'),
),
'#value' => 'tset',
'#default_value' => 'test',
),
),
);
/**
* A test form state array for passing as an argument in events.
*
* @var array
*/
protected static $formState = array(
'values' => array(
'title' => 'tset',
'body' => 'tset',
),
);
/**
* Defines a form ID for a form whose events are activated in tests.
*
* @var string
*/
protected static $formId = 'test_form';
/**
* Defines testable settings for the rules_forms_form_info variable.
*
* @var array
*/
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->user = $this
->drupalCreateUser(array(
'administer nodes',
'access content',
'create article content',
'administer rules forms rules',
'administer rules forms',
'administer site configuration',
));
$this
->drupalLogin($this->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 the 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',
);
}
/**
* 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' => 'tset',
'#default_value' => 'tset',
);
$form = new ArrayObject($test_form);
$form_state = new ArrayObject(array());
// Test with a correctly matching field value.
$condition1 = rules_condition('rules_forms_element_value', array(
'element' => 'textfield:test',
'value' => 'tset',
'regex' => 0,
));
$result1 = $condition1
->executeByArgs(array(
'form' => $form,
'form_state' => $form_state,
));
$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' => $form_state,
));
$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' => $form_state,
));
$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' => $form_state,
));
$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' => 'tset',
'regex' => 0,
));
$result5 = $condition5
->executeByArgs(array(
'form' => $form,
'form_state' => $form_state,
));
$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' => $form_state,
));
$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' => $form_state,
));
$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' => $form_state,
));
$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;
$form_state = self::$formState;
// rules_forms_event_build will set build information variables.
variable_set('rules_forms_form_info', self::$formInfo);
rules_forms_event_build($form, $form_state, self::$formId);
// Execute condition without changing the value.
$form_state['values']['title'] = 'tset';
$condition1 = rules_condition('rules_forms_element_changed', array(
'element' => 'textfield:title',
));
$result1 = $condition1
->executeByArgs(array(
'form' => $form,
'form_state' => $form_state,
));
$this
->assertFalse($result1, 'Form value has not changed.');
// Execute condition with changing the value.
$form_state['values']['title'] = 'test';
$condition2 = rules_condition('rules_forms_element_changed', array(
'element' => 'textfield:title',
));
$result2 = $condition2
->executeByArgs(array(
'form' => $form,
'form_state' => $form_state,
));
$this
->assertTrue($result2, 'Form value has changed.');
}
/**
* Tests callback for Condition: Form button was clicked.
*/
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.');
}
}
/**
* 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',
);
}
/**
* Tests callback for Action: Set element title.
*/
public function testSetTitleAction() {
$form = array();
$form['test'] = array(
'#type' => 'textfield',
'#title' => 'tset',
);
$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 testSetDescriptionAction() {
$form = array();
$form['test'] = array(
'#type' => 'textfield',
'#description' => t('tset'),
);
$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 testSetDisabledAction() {
$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 testSetRequiredAction() {
$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 testSetOptionsAction() {
$form = array();
$form['test'] = array(
'#type' => 'textfield',
'#options' => array(
'first' => 'tset',
),
);
$form = new ArrayObject($form);
$action = rules_action('rules_forms_set_options', array(
'element' => 'textfield:test',
'options' => 'first|test' . "\r\n" . 'second|tset',
));
$action
->executeByArgs(array(
'form' => $form,
));
$this
->assertEqual($form['test']['#options'], array(
'first' => 'test',
'second' => 'tset',
));
}
/**
* Tests callback for Action: Set default value of a form element.
*/
public function testSetDefaultAction() {
$form = array();
$form['test'] = array(
'#type' => 'textfield',
'#default_value' => 'tset',
);
$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 testSetWeightAction() {
$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 testSetPrefixSuffixAction() {
$form = array();
$form['test'] = array(
'#type' => 'textfield',
'#prefix' => 'tset',
'#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' => 'tset select',
'#options' => array(
'first' => t('option1'),
'second' => t('option2'),
),
'#value' => 'tset',
'#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.
$form_id = key(self::$formInfo);
$form_info = rules_forms_get_form_info($form_id);
$this
->assertEqual($form_info, self::$formInfo[$form_id]);
// Test getting info by $form array.
$form_info = rules_forms_get_form_info(self::$form);
$this
->assertEqual($form_info, self::$formInfo[self::$form['form_id']['#value']]);
}
/**
* Tests rules_forms_save_form_info().
*/
public function testSaveFormInfo() {
variable_set('rules_forms_form_info', self::$formInfo);
$form_info = self::$formInfo;
$form_info['label'] = 'save test';
rules_forms_save_form_info(self::$formId, $form_info);
$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);
$form_id = 'activate_test';
$form_info = array(
'label' => 'Activate test',
'elements' => array(),
'buttons' => FALSE,
);
rules_forms_activate_form($form_id, $form_info);
$info = variable_get('rules_forms_form_info', array());
$this
->assertEqual($info[$form_id], $form_info, '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);
$form_id = self::$form['form_id']['#value'];
rules_forms_event_build(self::$form, self::$formState, $form_id);
foreach (self::$formInfo[$form_id]['elements'] as $element_id => $info) {
$this
->assertTrue(isset(self::$formState['rules_forms']['form_values'][$element_id]), 'Ensure the build information variable was set for the element.');
// Values should always be set to 'tset' regardless if it came from
// #value or #default_value.
$this
->assertTrue(self::$formState['rules_forms']['form_values'][$element_id] == 'tset');
}
}
/**
* Tests rules_forms_event_submit().
*/
public function testEventSubmit() {
variable_set('rules_forms_form_info', self::$formInfo);
// Ensure that the build information variables are unset for the form.
self::$formState['rules_forms']['form_values'] = array(
'textfield:title' => 'tset',
'textarea:body:und:0:value' => 'tset',
);
rules_forms_event_submit(self::$form, self::$formState);
$this
->assertFalse(isset(self::$formState['rules_forms']), 'Ensure the form build info is unset.');
}
/**
* Tests rules_forms_event_button_submit().
*/
public function testEventButtonSubmit() {
// Add the button to the $form_info array.
$form_info = self::$formInfo;
$form_info[self::$formId]['submit']['fieldset:button:test'] = array();
variable_set('rules_forms_form_info', $form_info);
// Indicate that this button was clicked.
$form_state = self::$formState;
$form_state['triggering_element'] = array(
'#rules_forms_element_id' => 'fieldset:button:test',
);
// Ensure that the build information variables are unset for the form.
self::$formState['rules_forms']['form_values'] = array(
'textfield:title' => 'tset',
'textarea:body:und:0:value' => 'tset',
);
rules_forms_event_button_submit(self::$form, $form_state);
$this
->assertFalse(isset(self::$formState['rules_forms']), 'Ensure the form build info 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 | Class that tests Rules Forms. |
RulesFormsRulesTestCase | Base class for testing Rules Forms rules. |