isSupported() public static method

Is AES encryption supported by this PHP installation?
public static isSupported ( Phpfunc $phpfunc = null ) : boolean
$phpfunc FOF30\Utils\Phpfunc
return boolean
示例#1
0
文件: AesTest.php 项目: Joal01/fof
 /**
  * @covers FOF30\Encrypt\Aes::IsSupported
  *
  * @return  void
  */
 public function testIsSupported()
 {
     $functions_enabled = array('mcrypt_get_key_size', 'mcrypt_get_iv_size', 'mcrypt_create_iv', 'mcrypt_encrypt', 'mcrypt_decrypt', 'mcrypt_list_algorithms', 'hash', 'hash_algos', 'base64_encode', 'base64_decode');
     $algorithms = array('rijndael-128', 'rijndael-192', 'rijndael-256');
     $hashAlgos = array('sha256');
     // Create a mock php function with all prerequisites met
     $phpfunc = new MockPhpfunc();
     $phpfunc->setFunctions($functions_enabled);
     $phpfunc->setMcryptAlgorithms($algorithms);
     $phpfunc->setHashAlgorithms($hashAlgos);
     // Just for code coverage
     $this->assertNotNull(Aes::isSupported());
     // All prerequisites met = supported
     $this->assertTrue(Aes::isSupported($phpfunc));
     // No hash algorithms = not supported
     $phpfunc->setHashAlgorithms(array());
     $this->assertFalse(Aes::isSupported($phpfunc));
     $phpfunc->setHashAlgorithms($hashAlgos);
     // No mcrypt algorithms = not supported
     $phpfunc->setMcryptAlgorithms(array());
     $this->assertFalse(Aes::isSupported($phpfunc));
     $phpfunc->setMcryptAlgorithms($algorithms);
     // No required functions available = not supported
     $phpfunc->setFunctions(array());
     $this->assertFalse(Aes::isSupported($phpfunc));
     $phpfunc->setFunctions($functions_enabled);
     // Test with diminishing amounts of supported mcrypt algos (=not supported) – for code coverage
     $temp = $algorithms;
     while (!empty($temp)) {
         array_pop($temp);
         $phpfunc->setMcryptAlgorithms($temp);
         $this->assertFalse(Aes::isSupported($phpfunc));
     }
     $phpfunc->setMcryptAlgorithms($algorithms);
     // Test with diminishing amounts of supported functions (=not supported) – for code coverage
     $temp = $functions_enabled;
     while (!empty($temp)) {
         array_pop($temp);
         $phpfunc->setFunctions($temp);
         $this->assertFalse(Aes::isSupported($phpfunc));
     }
 }