public function MobileNumberClassTestCase::testNumberValidity in Mobile Number 7
Test number validation.
File
- tests/
mobile_number.class.test, line 41
Class
- MobileNumberClassTestCase
- Class for testing mobile_number class.
Code
public function testNumberValidity() {
$local_numbers = array(
'+972502345678' => 'International IL',
'091234567' => 'None mobile IL',
'0502345678' => 'Valid IL',
'111' => 'Invalid IL',
NULL => 'Empty',
);
$countries = array(
'IL' => 'IL',
'US' => 'US',
NULL => 'Empty',
);
foreach ($countries as $country => $country_text) {
foreach ($local_numbers as $number => $number_text) {
$valid = TRUE;
try {
new MobileNumber($number, $country);
} catch (\Exception $e) {
$valid = FALSE;
}
$supposed_valid = FALSE;
switch ($country) {
case 'IL':
$supposed_valid = $number == '+972502345678' || $number == '0502345678';
break;
case NULL:
$supposed_valid = $number == '+972502345678';
break;
}
$success_text = $supposed_valid ? 'valid' : 'invalid';
$this
->assertTrue($valid == $supposed_valid, "{$country_text} country, {$number_text} number, is {$success_text}.", 'Number Validity');
}
}
}