public function SmsValidWebTest::testSmsValidSettingsForm in SMS Framework 7
Tests the application of the sms_valid settings form and settings.
File
- modules/
sms_valid/ sms_valid.test, line 127 - 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 testSmsValidSettingsForm() {
// Create two rulesets for test.
$ruleset = $this
->randomRuleset();
$ruleset['prefix'] = '991';
$ruleset['rules'] = sms_valid_text_to_rules("23- # Explicit deny 23");
sms_valid_save_ruleset($ruleset);
$ruleset = $this
->randomRuleset();
$ruleset['prefix'] = '234';
$ruleset['rules'] = sms_valid_text_to_rules("56+ # Explicit allow 56");
sms_valid_save_ruleset($ruleset);
// Update settings.
$edit = array(
'mode' => 1,
'global_ruleset' => '64',
'local_number_prefix' => '0',
'local_number_ruleset' => '234',
'last_resort_enabled' => true,
'last_resort_ruleset' => '991',
);
$this
->drupalLogin($this->adminUser);
$this
->drupalPost('admin/smsframework/validation', $edit, t('Save settings'));
// Confirm settings were updated correctly.
$this
->assertTrue(variable_get('sms_valid_use_rulesets'), 'Use rulesets correctly set.');
$this
->assertFalse(variable_get('sms_valid_use_global_ruleset'), 'Use rulesets correctly set.');
$this
->assertEqual('64', variable_get('sms_valid_global_ruleset'), 'Global ruleset correctly set.');
$this
->assertEqual('0', variable_get('sms_valid_local_number_prefix', -1), 'Local number prefix correctly set.');
$this
->assertEqual('234', variable_get('sms_valid_local_number_ruleset'), 'Local number ruleset correctly set.');
$this
->assertTrue(variable_get('sms_valid_last_resort_enabled'), 'Last resort option correctly set.');
$this
->assertEqual('991', variable_get('sms_valid_last_resort_ruleset'), 'Last resort ruleset correctly set.');
// Use specific ruleset.
$result = sms_valid_validate('2345678901234', array(
'prefix' => '991',
));
$this
->assertFalse($result['pass'], 'Specific ruleset caused fail.');
$result = sms_valid_validate('2345678901234', array(
'prefix' => '234',
));
$this
->assertTrue($result['pass'], 'Specific ruleset caused pass.');
// Use global ruleset.
variable_set('sms_valid_use_global_ruleset', true);
variable_set('sms_valid_global_ruleset', '234');
$result = sms_valid_validate('2345678901234');
$this
->assertFalse($result['pass'], 'Global ruleset "234" applied to valid number');
$result = sms_valid_validate('9915678901234');
$this
->assertFalse($result['pass'], 'Global ruleset "234" applied to invalid number');
// Local number validation.
$ruleset = $this
->randomRuleset();
$ruleset['prefix'] = '419';
$ruleset['rules'] = sms_valid_text_to_rules("80- # Explicit deny 80\n90+ # Explicit allow 90");
sms_valid_save_ruleset($ruleset);
variable_set('sms_valid_local_number_prefix', '0');
variable_set('sms_valid_local_number_ruleset', '419');
variable_set('sms_valid_use_global_ruleset', false);
$result = sms_valid_validate('08078901234');
$this
->assertFalse($result['pass'], 'Local number validation failed as expected for 08078901234');
$result = sms_valid_validate('09078901234');
$this
->assertTrue($result['pass'], 'Local number validation passed as expected for 09078901234');
// Last resort ruleset.
$ruleset = sms_valid_get_ruleset('991');
$ruleset['rules'] = sms_valid_text_to_rules("2- # Explicit deny (2...)\n1+ # Explicit allow (1...)");
sms_valid_save_ruleset($ruleset);
variable_set('sms_valid_use_global_ruleset', false);
variable_set('sms_valid_last_resort_enabled', true);
variable_set('sms_valid_last_resort_ruleset', '991');
$result = sms_valid_validate('2189751234');
$this
->assertFalse($result['pass'], 'Fallback rule validation failed as expected for 2189751234');
$result = sms_valid_validate('1189751234');
$this
->assertTrue($result['pass'], 'Fallback rule validation passed as expected for 1189751234');
}