You are here

public function SmsValidWebTest::testSmsValidValidate in SMS Framework 7

Tests the sms_valid_validate() function.

File

modules/sms_valid/sms_valid.test, line 34
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 testSmsValidValidate() {

  // Test that the default rulesets are added already.
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet('admin/smsframework/validation/rulesets');
  $this
    ->assertText('New Zealand', 'Default ruleset found in list view.');
  $test_numbers = array(
    '1234567890' => false,
    '123458767890' => false,
    '64219427-9238' => true,
    '6425=-,x2-4n292' => false,
    '6429;ajklf a/s,MFA' => true,
    '] W[OPQIRW' => false,
    '6429996789065' => true,
    '6428156789098765' => true,
  );

  // Test direct validation.
  $options = array(
    'test' => true,
  );
  foreach ($test_numbers as $number => $valid) {
    $result = sms_valid_validate($number, $options);
    $this
      ->assertEqual($valid, empty($result['errors']), 'Direct test: Number validation ok for ' . $number);
  }

  // Test through hook_sms_validate_number().
  foreach ($test_numbers as $number => $valid) {
    $errors = sms_validate_number($number, $options);
    $this
      ->assertEqual($valid, empty($errors), 'Hook test: Number validation ok for ' . $number);
  }
}