public function SmsValidWebTest::testSmsValidFunctions in SMS Framework 7
Tests the internal sms_valid functions.
File
- modules/
sms_valid/ sms_valid.test, line 204 - 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 testSmsValidFunctions() {
// Clear all rulesets.
$count = count(sms_valid_get_all_rulesets());
$ruleset1 = $this
->randomRuleset();
$ruleset1['iso2'] = 'AU';
$ruleset1['rules'] = sms_valid_text_to_rules("80- # Test 1\n90+ # Test 2");
sms_valid_save_ruleset($ruleset1);
$ruleset2 = $this
->randomRuleset();
$ruleset2['iso2'] = 'AU';
$ruleset2['rules'] = sms_valid_text_to_rules("81- # Test 1\n91+ # Test 2");
sms_valid_save_ruleset($ruleset2);
$new_rulesets = sms_valid_get_all_rulesets();
$this
->assertEqual(2, count($new_rulesets) - $count, 'All new rulesets found.');
$this
->assertEqual($ruleset2, (array) $new_rulesets[$ruleset2['prefix']], 'sms_valid_get_all_rulesets() functional.');
$this
->assertEqual(sms_valid_get_ruleset($ruleset1['prefix']), $ruleset1, 'sms_valid_get_ruleset() functional.');
$rules = sms_valid_rules_to_text($ruleset2['rules']);
$this
->assertEqual($rules, "81- # Test 1\n91+ # Test 2", 'Rules converted to text.');
$rules = sms_valid_text_to_rules($rules);
$this
->assertEqual($rules, $ruleset2['rules'], 'Rules converted from text.');
$this
->assertEqual($ruleset2, sms_valid_get_ruleset_for_number($ruleset2['prefix'] . '98765432'), 'Found right ruleset for ' . $ruleset2['prefix'] . '98765432');
// @todo This test may fail at random times.
$this
->assertFalse(sms_valid_get_ruleset_for_number('876298765432'), 'No ruleset for 876298765432');
// php array comparison needs sorting.
$expected = array(
$ruleset1['prefix'],
$ruleset2['prefix'],
);
$actual = sms_valid_get_prefixes_for_iso2('AU');
sort($expected);
sort($actual);
$this
->assertEqual($expected, $actual, 'sms_valid_get_prefixes_for_iso2() functional.');
// Set status.
sms_valid_ruleset_set_status($ruleset1['prefix'], SMS_DIR_ALL);
$ruleset = sms_valid_get_ruleset($ruleset1['prefix']);
$this
->assertEqual(SMS_DIR_ALL, $ruleset['dirs_enabled'], 'sms_valid_ruleset_set_status() functional.');
// Local number check.
variable_set('sms_valid_local_number_prefix', '0');
$this
->assertTrue(sms_valid_is_local_number('08032149857'), 'Local number check passes.');
$this
->assertFalse(sms_valid_is_local_number('8032149857'), 'Local number check passes.');
}