public function SmsValidWebTest::testCrudSmsValidRulesets in SMS Framework 7
Tests the creation, update and deletion of sms_valid rulesets.
File
- modules/
sms_valid/ sms_valid.test, line 68 - Contains tests for the functions in sms.module and core sms framework.
Class
- SmsValidWebTest
- Provides unit tests for SMS Valid validation functions.
Code
public function testCrudSmsValidRulesets() {
$this
->drupalLogin($this->adminUser);
// Create a new ruleset.
$edit = array(
'prefix' => (string) rand(1, 999),
'name' => $this
->randomName(15),
'iso2' => 'AU',
'out' => true,
'in' => true,
'rules' => "80+\n90-\n70\n65+\n",
);
$this
->drupalPost('admin/smsframework/validation/ruleset', $edit, t('Save Ruleset'));
// Confirm that ruleset was correctly saved.
$ruleset = sms_valid_get_ruleset($edit['prefix']);
$original = array(
'rules' => sms_valid_text_to_rules($edit['rules']),
'dirs_enabled' => sms_dir($edit['out'], $edit['in']),
) + $edit;
unset($original['in'], $original['out']);
$this
->assertEqual($original, $ruleset, 'Ruleset ' . $edit['prefix'] . ' correctly saved.');
// Update ruleset.
$edit['in'] = false;
$edit['out'] = false;
$this
->drupalPost('admin/smsframework/validation/ruleset/' . $edit['prefix'], $edit, t('Save Ruleset'));
$ruleset = sms_valid_get_ruleset($edit['prefix']);
$this
->assertEqual('0', $ruleset['dirs_enabled'], 'Ruleset ' . $edit['prefix'] . ' updated');
// Change direction settings from list page.
$direction_change = array(
$edit['prefix'] . '_in' => true,
$edit['prefix'] . '_out' => true,
);
$this
->drupalPost('admin/smsframework/validation/rulesets', $direction_change, t('Save Changes'));
$ruleset = sms_valid_get_ruleset($edit['prefix']);
$this
->assertEqual($ruleset['dirs_enabled'], SMS_DIR_ALL, 'Directionality for ' . $edit['prefix'] . ' changed from list page');
// Add another test ruleset and then check the ruleset load button.
$edit1 = array(
'prefix' => (string) rand(1, 999),
'name' => $this
->randomName(15),
) + $edit;
$this
->drupalPost('admin/smsframework/validation/ruleset', $edit1, t('Save Ruleset'));
$this
->drupalPost('admin/smsframework/validation/ruleset', array(
'select_prefix' => $edit1['prefix'],
), t('Refresh Editor (below)'));
$this
->assertText($edit1['name'], 'Editor refresh button works.');
// Delete ruleset.
$delete = array(
$edit['prefix'] . '_delete' => true,
);
$this
->drupalPost('admin/smsframework/validation/rulesets', $delete, t('Save Changes'));
$this
->assertFalse(sms_valid_get_ruleset($edit['prefix']), 'Ruleset ' . $edit['prefix'] . ' deleted');
}