You are here

phone-pa.test in Phone 6

File

tests/phone-pa.test
View source
<?php

class PhonePanamanianTest extends DrupalWebTestCase {
  public static function getInfo() {
    return array(
      'name' => t('Panamanian phone'),
      'description' => t('Executes test suite for validating / formatting Panamanian phone number.'),
      'group' => t('Phone'),
    );
  }
  function setUp() {
    parent::setUp();
    include_once './' . drupal_get_path('module', 'phone') . '/phone.pa.inc';
  }
  function testValidatingPanamenianPhoneNumber() {
    $this
      ->assertTrue(valid_pa_phone_number('+507 260-4334'), '+507 260-4334 should be valid');
    $this
      ->assertTrue(valid_pa_phone_number('+507 2604334'), '+507 2604334 should be valid');
    $this
      ->assertTrue(valid_pa_phone_number('+507 260 4334'), '+507 260 4334 should be valid');
    $this
      ->assertTrue(valid_pa_phone_number('00507 2603133'), '00507 2603133 should be valid');
    $this
      ->assertTrue(valid_pa_phone_number('00507 260-3133'), '00507 260-3133 should be valid');
    $this
      ->assertTrue(valid_pa_phone_number('00507 260 4334'), '00507 260 4334 should be valid');
    $this
      ->assertTrue(valid_pa_phone_number('260 3133'), '260 3133 should be valid');
    $this
      ->assertTrue(valid_pa_phone_number('260-3133'), '260-3133 should be valid');
    $this
      ->assertTrue(valid_pa_phone_number('2603133'), '2603133 should be valid');

    //Cellphones
    $this
      ->assertTrue(valid_pa_phone_number('+507 6545-4345'), '+507 6545-4345 should be valid');
    $this
      ->assertTrue(valid_pa_phone_number('+507 65454345'), '+507 65454345 should be valid');
    $this
      ->assertTrue(valid_pa_phone_number('+507 6545 4345'), '+507 6545 4345 should be valid');
    $this
      ->assertTrue(valid_pa_phone_number('00507 6545-4345'), '00507 6545-4345 should be valid');
    $this
      ->assertTrue(valid_pa_phone_number('00507 6545 4345'), '00507 6545 4345 should be valid');
    $this
      ->assertTrue(valid_pa_phone_number('00507 65454345'), '00507 65454345 should be valid');
    $this
      ->assertTrue(valid_pa_phone_number('6545-4345'), '6545-4345 should be valid');
    $this
      ->assertTrue(valid_pa_phone_number('6545 4345'), '6545 4345 should be valid');
    $this
      ->assertTrue(valid_pa_phone_number('65454345'), '65454345 should be valid');

    //Invalid
    $this
      ->assertFalse(valid_pa_phone_number('35343'), '35343 should not be valid');
    $this
      ->assertFalse(valid_pa_phone_number('320-43'), '320-43 should not be valid');
    $this
      ->assertTrue(valid_pa_phone_number('(507) 435-3434'), '(507) 435-3434 should not be valid');
  }
  function testFormattingPanamenianPhoneNumber() {
    $this
      ->assertEqual(format_pa_phone_number('+507 260-4334'), '+507 260-4334', '+507 260-4334 format');
    $this
      ->assertEqual(format_pa_phone_number('+507 2604334'), '+507 260-4334', '+507 2604334 format');
    $this
      ->assertEqual(format_pa_phone_number('+507 260 4334'), '+507 260-4334', '+507 260 4334 format');
    $this
      ->assertEqual(format_pa_phone_number('00507 260-4334'), '+507 260-4334', '00507 260-4334 format');
    $this
      ->assertEqual(format_pa_phone_number('00507 2604334'), '+507 260-4334', '00507 2604334 format');
    $this
      ->assertEqual(format_pa_phone_number('00507 260 4334'), '+507 260-4334', '00507 260 4334 format');
    $this
      ->assertEqual(format_pa_phone_number('260-4334'), '260-4334', '260-4334 format');
    $this
      ->assertEqual(format_pa_phone_number('2604334'), '260-4334', '2604334 format');
    $this
      ->assertEqual(format_pa_phone_number('260 4334'), '260-4334', '260 4334 format');
    $this
      ->assertEqual(format_pa_phone_number('260 4334', array(
      'phone_country_code' => 1,
    )), '+507 260-4334', 'add +507 to 260 4334 format');

    //Cellphones
    $this
      ->assertEqual(format_pa_phone_number('00507 6464 4334'), '+507 6464-4334', '6464 4334 format');
    $this
      ->assertEqual(format_pa_phone_number('00507 6464-4334'), '+507 6464-4334', '00507 6464-4334 format');
    $this
      ->assertEqual(format_pa_phone_number('00507 64644334'), '+507 6464-4334', '00507 64644334 format');
    $this
      ->assertEqual(format_pa_phone_number('+507 6464 4334'), '+507 6464-4334', '+507 6464 4334 format');
    $this
      ->assertEqual(format_pa_phone_number('6464 4334'), '6464-4334', '6464 4334 format');
    $this
      ->assertEqual(format_pa_phone_number('64644334'), '6464-4334', '6464-4334 format');
    $this
      ->assertEqual(format_pa_phone_number('6464 4334', array(
      'phone_country_code' => 1,
    )), '+507 6464-4334', 'add +507 to 6464 4334 format');
  }

}

Classes