public function MobileNumberClassTestCase::testFunctions in Mobile Number 7
Test functions.
File
- tests/
mobile_number.class.test, line 89
Class
- MobileNumberClassTestCase
- Class for testing mobile_number class.
Code
public function testFunctions() {
$int = '+972502345678';
$mobile_number = new MobileNumber($int);
$this
->assertTrue(MobileNumber::getCountryCode('IL') == 972, "getCountryCode()", 'Functions');
$this
->assertTrue(count(MobileNumber::getCountryOptions()), "getCountryOptions()", 'Functions');
$this
->assertTrue(count(MobileNumber::getCountryOptions(array(
'IL' => 'IL',
))) == 1, "getCountryOptions() filtered", 'Functions');
$this
->assertTrue(MobileNumber::getCountryName('IL') == 'Israel', "getCountryName()", 'Functions');
$code = MobileNumber::generateVerificationCode(6);
$this
->assertTrue(strlen($code) == 6, "generateVerificationCode()", 'Functions');
$token = MobileNumber::registerVerificationCode($code, $int);
$this
->assertTrue(strlen($token) == 43, "registerVerificationCode()", 'Functions');
$this
->assertTrue($mobile_number
->checkFlood(), "checkFlood() success", 'Functions');
$token2 = $mobile_number
->sendVerification('test', $code);
$this
->assertTrue(strlen($token2) == 43 && $token2 != $token, "sendVerification()", 'Functions');
$this
->assertTrue($mobile_number
->getToken() == $token2, "getToken()", 'Functions');
$this
->assertFalse($mobile_number
->verifyCode('000', $token), "verifyCode() failure", 'Functions');
for ($i = 0; $i < MobileNumber::VERIFY_TOO_MANY_ATTEMPTS; $i++) {
$mobile_number
->verifyCode('000', $token);
}
$this
->assertFalse($mobile_number
->checkFlood(), "checkFlood() failure", 'Functions');
flood_clear_event('mobile_number_verification', $int);
$this
->assertFalse($mobile_number
->isVerified(), "isVerified() failure", 'Functions');
$this
->assertTrue($mobile_number
->verifyCode($code, $token), "verifyCode() success", 'Functions');
$this
->assertTrue($mobile_number
->isVerified(), "isVerified() success", 'Functions');
$this
->assertTrue(strlen(MobileNumber::codeHash($token, $code, $int)) == 40, "codeHash()", 'Functions');
}