public function MobileNumberClassTest::testFunctions in Mobile Number 2.0.x
Same name and namespace in other branches
- 8 src/Tests/MobileNumberClassTest.php \Drupal\mobile_number\Tests\MobileNumberClassTest::testFunctions()
Test functions.
File
- src/
Tests/ MobileNumberClassTest.php, line 96
Class
- MobileNumberClassTest
- Mobile number class functionality.
Namespace
Drupal\mobile_number\TestsCode
public function testFunctions() {
$int = '+972502345678';
$mobile_number = $this->util
->getMobileNumber($int);
$this
->assertTrue($this->util
->getCountryCode('IL') == 972, "getCountryCode()");
$this
->assertGreaterThan(0, count($this->util
->getCountryOptions()), "getCountryOptions()");
$this
->assertTrue(count($this->util
->getCountryOptions([
'IL' => 'IL',
])) == 1, "getCountryOptions() filtered");
$this
->assertTrue($this->util
->getCountryName('IL') == 'Israel', "getCountryName()");
$code = $this->util
->generateVerificationCode(6);
$this
->assertTrue(strlen($code) == 6, "generateVerificationCode()");
$token = $this->util
->registerVerificationCode($mobile_number, $code);
$this
->assertTrue(strlen($token) == 43, "registerVerificationCode()");
$this
->assertTrue($this->util
->checkFlood($mobile_number), "checkFlood() success");
$token2 = $this->util
->sendVerification($mobile_number, 'test', $code);
$this
->assertTrue(strlen($token2) == 43 && $token2 != $token, "sendVerification()");
$this
->assertTrue($this->util
->getToken($mobile_number) == $token2, "getToken()");
$this
->assertFalse($this->util
->verifyCode($mobile_number, '000', $token), "verifyCode() failure");
for ($i = 0; $i < MobileNumberUtilInterface::VERIFY_ATTEMPTS_COUNT; $i++) {
$this->util
->verifyCode($mobile_number, '000', $token);
}
$this
->assertFalse($this->util
->checkFlood($mobile_number), "checkFlood() failure");
$this->flood
->clear('mobile_number_verification', $int);
$this
->assertFalse($this->util
->isVerified($mobile_number), "isVerified() failure");
$this
->assertTrue($this->util
->verifyCode($mobile_number, $code, $token), "verifyCode() success");
$this
->assertTrue($this->util
->isVerified($mobile_number), "isVerified() success");
$this
->assertTrue(strlen($this->util
->codeHash($mobile_number, $token, $code)) == 40, "codeHash()");
}