| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
//////////////////////////////////////////////////////////////////////////////
|
| 5 |
// Unit tests (compatible with Simpletest 2.x)
|
| 6 |
|
| 7 |
class GnupgTestCase extends DrupalWebTestCase {
|
| 8 |
const DATA = 'GnuPG for Drupal';
|
| 9 |
|
| 10 |
public function getInfo() {
|
| 11 |
return array(
|
| 12 |
'name' => t('Operations'),
|
| 13 |
'description' => t('Exercises the GnuPG API encryption/decryption operations.'),
|
| 14 |
'group' => t('GnuPG'),
|
| 15 |
);
|
| 16 |
}
|
| 17 |
|
| 18 |
public function test_configuration() {
|
| 19 |
$gnupg_exec = variable_get('gnupg_exec', gnupg_guess_binpath());
|
| 20 |
$this->assertTrue(file_exists($gnupg_exec), t('The GnuPG binary exists.'), t('Configuration'));
|
| 21 |
$this->assertTrue(is_executable($gnupg_exec), t('The GnuPG binary is executable.'), t('Configuration'));
|
| 22 |
$this->assertTrue(is_dir(GNUPG_HOMEDIR), t('The GnuPG home directory exists.'), t('Configuration'));
|
| 23 |
$this->assertTrue(is_readable(GNUPG_HOMEDIR), t('The GnuPG home directory is readable.'), t('Configuration'));
|
| 24 |
$this->assertTrue(GNUPG_KEYID != '', t('A GnuPG default key ID has been configured.'), t('Configuration')); // needed for later
|
| 25 |
}
|
| 26 |
|
| 27 |
public function test_version() {
|
| 28 |
$this->assertNotNull(gnupg_version(), t('GnuPG is installed.'), t('Version'));
|
| 29 |
$this->assertTrue(preg_match('!^\d+\.\d+\.\d+$!', gnupg_version()) > 0, t('The GnuPG version number is valid.'), t('Version'));
|
| 30 |
}
|
| 31 |
|
| 32 |
public function test_encrypt() {
|
| 33 |
$this->assertTrue(is_string(gnupg_encrypt(self::DATA)), t('Encryption succeeds.'), t('Encryption'));
|
| 34 |
$this->assertTrue(preg_match('!^-----BEGIN PGP MESSAGE-----!', gnupg_encrypt(self::DATA)), t('Encryption returns ciphertext.'), t('Encryption'));
|
| 35 |
}
|
| 36 |
|
| 37 |
public function test_decrypt() { /* TODO */ }
|
| 38 |
}
|