phone.fr.test 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. // Copyright 2009 Thierry GUEGAN http://www.arvoriad.com
  3. /**
  4. /**
  5. * Unit tests for Phone module.
  6. */
  7. class PhoneFrenchTest extends DrupalWebTestCase {
  8. public static function getInfo() {
  9. return array(
  10. 'name' => t('France Phone number test'),
  11. 'description' => t('Executes test suite for validating / formatting France phone number.'),
  12. 'group' => t('Phone')
  13. );
  14. }
  15. function setUp() {
  16. parent::setUp();
  17. include_once('./'. drupal_get_path('module', 'phone') .'/phone.fr.inc');
  18. }
  19. public function testPhoneFRValid() {
  20. // test cleaning phone number
  21. $this->assertTrue(valid_phone_number('fr', ' +33 123 45 - (67) 89'), "' +33 123 45 - (67) 89' should be valid");
  22. $this->assertTrue(valid_phone_number('fr', '+33123456789'), "'+33123456789' should be valid");
  23. $this->assertTrue(valid_phone_number('fr', '0123456789'), "'0123456789' should be valid");
  24. $this->assertTrue(valid_phone_number('fr', '+33223456789'), "'+33223456789' should be valid");
  25. $this->assertTrue(valid_phone_number('fr', '0223456789'), "'0223456789' should be valid");
  26. $this->assertTrue(valid_phone_number('fr', '+33323456789'), "'+33323456789' should be valid");
  27. $this->assertTrue(valid_phone_number('fr', '0323456789'), "'0323456789' should be valid");
  28. $this->assertTrue(valid_phone_number('fr', '+33423456789'), "'+33423456789' should be valid");
  29. $this->assertTrue(valid_phone_number('fr', '0423456789'), "'0423456789' should be valid");
  30. $this->assertTrue(valid_phone_number('fr', '+33523456789'), "'+33523456789' should be valid");
  31. $this->assertTrue(valid_phone_number('fr', '0523456789'), "'0523456789' should be valid");
  32. // 06... mobile
  33. $this->assertTrue(valid_phone_number('fr', '+33623456789'), "'+33623456789' should be valid");
  34. $this->assertTrue(valid_phone_number('fr', '0623456789'), "'0623456789' should be valid");
  35. // 085... virtual private network
  36. $this->assertTrue(valid_phone_number('fr', '+33853456789'), "'+33853456789' should be valid");
  37. $this->assertTrue(valid_phone_number('fr', '0853456789'), "'0853456789' should be valid");
  38. // 087...
  39. // 870... 871... 872... 873... 874... 875... 877... 878... 879... assigned
  40. foreach (array('870', '871', '872', '873', '874', '875', '877', '878', '879') as $za) {
  41. $this->assertTrue(valid_phone_number('fr', '+33'. $za .'123456'), "'+33 $za 1234567' is be valid");
  42. $this->assertTrue(valid_phone_number('fr', '0'. $za .'123456'), "'0 $za 1234567' is be valid");
  43. }
  44. }
  45. public function testPhoneFRInvalid() {
  46. $this->assertFalse(valid_phone_number('fr', '+33 123456789a'), "'+33 123456789a' should not be valid because wrong char");
  47. $this->assertFalse(valid_phone_number('fr', '+33 1234567a89'), "'+33 1234567a89' should not be valid because wrong char");
  48. $this->assertFalse(valid_phone_number('fr', '0 123456789a'), "'0 123456789a' should not be valid because wrong char");
  49. $this->assertFalse(valid_phone_number('fr', '0 1234567a89'), "'0 1234567a89' should not be valid because wrong char");
  50. $this->assertFalse(valid_phone_number('fr', '+33 1234567890'), "'+33 1234567890' should not be valid because too long");
  51. $this->assertFalse(valid_phone_number('fr', '+33 12345678'), "'+33 12345678' should not be valid because too short");
  52. $this->assertFalse(valid_phone_number('fr', '0 1234567890'), "'0 1234567890' should not be valid because too long");
  53. $this->assertFalse(valid_phone_number('fr', '0 12345678'), "'0 12345678' should not be valid because too short");
  54. // 07... not assigned
  55. $this->assertFalse(valid_phone_number('fr', '+33723456789'), "'+33723456789' is unassigned so should not be valid");
  56. $this->assertFalse(valid_phone_number('fr', '0723456789'), "'0723456789' is unassigned so should not be valid");
  57. // except 0876... not assigned
  58. $this->assertFalse(valid_phone_number('fr', '+33876456789'), "'+33873456789' is unassigned so should not be valid");
  59. $this->assertFalse(valid_phone_number('fr', '0876456789'), "'0873456789' is unassigned so should not be valid");
  60. // 80... 81... 82... 83... 84... 86... 88... 89... not assigned
  61. foreach (array('80', '81', '82', '83', '84', '86', '88', '89') as $za) {
  62. $this->assertFalse(valid_phone_number('fr', '+33'. $za .'1234567'), "'+33'. $za .'1234567' is unassigned so should not be valid");
  63. $this->assertFalse(valid_phone_number('fr', '0'. $za .'1234567'), "'0'. $za .'1234567' is unassigned so should not be valid");
  64. }
  65. // 09... not assigned
  66. $this->assertFalse(valid_phone_number('fr', '+33923456789'), "'+33923456789' is unassigned so should not be valid");
  67. $this->assertFalse(valid_phone_number('fr', '0923456789'), "'0923456789' is unassigned so should not be valid");
  68. // 00... not assigned
  69. $this->assertFalse(valid_phone_number('fr', '+33023456789'), "'+33023456789' is unassigned so should not be valid");
  70. $this->assertFalse(valid_phone_number('fr', '0023456789'), "'0023456789' is unassigned so should not be valid");
  71. }
  72. public function testPhoneFRFormatting() {
  73. // test cleaning phone number
  74. $this->assertEqual(format_fr_phone_number('+33 123456789a'), '+33 123456789a', "'+33 123456789a', not valid so just ouptut without formatting");
  75. $this->assertEqual(format_fr_phone_number('01234567a8'), '01234567a8', "'01234567a8', not valid so just ouptut without formatting");
  76. $this->assertEqual(format_fr_phone_number('+33 123456789'), '0123456789', "international --> national");
  77. $this->assertEqual(format_fr_phone_number(' +33 123 45 - (67) 89'), '0123456789', "international --> national");
  78. $add_country_code = array('phone_country_code'=> TRUE);
  79. $this->assertEqual(format_fr_phone_number('+33 123456789', $add_country_code), '+33 123456789', "international --> international");
  80. $this->assertEqual(format_fr_phone_number(' +33 123 45 - (67) 89', $add_country_code), '+33 123456789', "international --> international");
  81. }
  82. }