phone.za.test 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. class ZAPhoneNumberTestCase extends DrupalWebTestCase {
  3. /**
  4. * Implementation of getInfo()
  5. *
  6. */
  7. public static function getInfo() {
  8. return array(
  9. 'name' => t('South Africa Phone number test'),
  10. 'description' => t('Tests various valid and invalid South African phone numbers for validity'),
  11. 'group' => t('Phone')
  12. );
  13. }
  14. public function testPhoneZAValid() {
  15. $this->assertTrue(valid_phone_number('za', '+27 11 888-8888'), t('Test valid - +27 11 888-8888'));
  16. $this->assertTrue(valid_phone_number('za', '0333872119'), t('Test valid - 0333872119'));
  17. $this->assertTrue(valid_phone_number('za', '074 101 2850'), t('Test valid - 074 101 2850'));
  18. $this->assertTrue(valid_phone_number('za', '27723376484'), t('Test valid - 27723376484'));
  19. $this->assertTrue(valid_phone_number('za', '0723376484'), t('Test valid - 0723376484'));
  20. $this->assertTrue(valid_phone_number('za', '0111231234'), t('Test valid - 0111231234'));
  21. $this->assertTrue(valid_phone_number('za', '011 123 1234'), t('Test valid - 011 123 1234'));
  22. $this->assertTrue(valid_phone_number('za', '011-123-1234'), t('Test valid - 011-123-1234'));
  23. $this->assertTrue(valid_phone_number('za', '0821231234'), t('Test valid - 0821231234'));
  24. $this->assertTrue(valid_phone_number('za', '082 123 1234'), t('Test valid - 082 123 1234'));
  25. $this->assertTrue(valid_phone_number('za', '+27821231234'), t('Test valid - +27821231234'));
  26. $this->assertTrue(valid_phone_number('za', '+2782-123-1234'), t('Test valid - +2782-123-1234'));
  27. $this->assertTrue(valid_phone_number('za', '+2782 123 1234'), t('Test valid - +2782 123 1234'));
  28. $this->assertTrue(valid_phone_number('za', '27111231234'), t('Test valid - 27111231234'));
  29. $this->assertTrue(valid_phone_number('za', '2711 123 1234'), t('Test valid - 2711 123 1234'));
  30. $this->assertTrue(valid_phone_number('za', '082 123 1234'), t('Test valid - 082 123 1234'));
  31. }
  32. public function testPhoneZAInvalid() {
  33. $this->assertFalse(valid_phone_number('za', '9723376484'), t('Test invalid - 9723376484'));
  34. $this->assertFalse(valid_phone_number('za', '26723376484'), t('Test invalid - 26723376484'));
  35. $this->assertFalse(valid_phone_number('za', '(011)1231234'), t('Test invalid - (011)1231234'));
  36. $this->assertFalse(valid_phone_number('za', '(+2711) 123 1234'), t('Test invalid - (+2711) 123 1234'));
  37. $this->assertFalse(valid_phone_number('za', '(011) 123-1234'), t('Test invalid - (011) 123-1234'));
  38. }
  39. public function testPhoneZAFormatting() {
  40. $this->assertEqual(format_phone_number('za', '082 123 1234', null), '082 123 1234', 'Formatting OK "082 123 1234" --> "082 123 1234"');
  41. }
  42. }