From 3d298a4f38c84cc9b096dcffd3b4945c8f3b0dbe Mon Sep 17 00:00:00 2001 From: Jakub Zelenka Date: Sun, 11 Dec 2016 19:36:15 +0000 Subject: [PATCH] Improve tests and make them independent --- .gitignore | 2 ++ tests/gnupg_oo_0001_import.phpt | 9 +++--- tests/gnupg_oo_encrypt.phpt | 14 +++++---- tests/gnupg_oo_encryptsign.phpt | 16 ++++++----- tests/gnupg_oo_export.phpt | 8 ++++-- tests/gnupg_oo_keyinfo.phpt | 8 ++++-- tests/gnupg_oo_listsignatures.phpt | 8 ++++-- tests/gnupg_oo_sign_clear.phpt | 14 +++++---- tests/gnupg_oo_sign_detach.phpt | 14 +++++---- tests/gnupg_oo_sign_detach_nonarmor.phpt | 16 ++++++----- tests/gnupg_oo_sign_normal.phpt | 14 +++++---- tests/gnupg_oo_sign_normal_noarmor.phpt | 18 ++++++------ tests/gnupg_oo_zzz_deletekey.phpt | 8 ++++-- tests/gnupg_res_0001_import.phpt | 6 ++-- tests/gnupg_res_encrypt.phpt | 4 ++- tests/gnupg_res_encryptsign.phpt | 4 ++- tests/gnupg_res_export.phpt | 4 ++- tests/gnupg_res_keyinfo.phpt | 4 ++- tests/gnupg_res_listsignatures.phpt | 4 ++- tests/gnupg_res_sign_clear.phpt | 4 ++- tests/gnupg_res_sign_detach.phpt | 4 ++- tests/gnupg_res_sign_detach_nonarmor.phpt | 4 ++- tests/gnupg_res_sign_normal.phpt | 4 ++- tests/gnupg_res_sign_normal_noarmor.phpt | 4 ++- tests/gnupg_res_zzz_deletekey.phpt | 4 ++- tests/vars.inc | 35 +++++++++++++++++++---- 26 files changed, 152 insertions(+), 82 deletions(-) diff --git a/.gitignore b/.gitignore index 6fa69f9..5a706e0 100644 --- a/.gitignore +++ b/.gitignore @@ -63,8 +63,10 @@ tests/*.log tests/*.out tests/*.php tests/*.sh +tests/pubring.gpg tests/pubring.kbx tests/random_seed +tests/secring.gpg tests/sshcontrol tests/trustdb.gpg diff --git a/tests/gnupg_oo_0001_import.phpt b/tests/gnupg_oo_0001_import.phpt index 2c866d0..d524ed9 100644 --- a/tests/gnupg_oo_0001_import.phpt +++ b/tests/gnupg_oo_0001_import.phpt @@ -4,12 +4,11 @@ import a new key into the keyring --FILE-- seterrormode(gnupg::ERROR_WARNING); -$ret = $gpg -> import($testkey); +$gpg->seterrormode(gnupg::ERROR_WARNING); +$ret = $gpg->import($testkey); var_dump($ret); ?> --EXPECT-- diff --git a/tests/gnupg_oo_encrypt.phpt b/tests/gnupg_oo_encrypt.phpt index be415af..c9626db 100644 --- a/tests/gnupg_oo_encrypt.phpt +++ b/tests/gnupg_oo_encrypt.phpt @@ -4,16 +4,18 @@ encrypt and decrypt a text --FILE-- seterrormode(gnupg::ERROR_WARNING); -$gpg -> addencryptkey($fingerprint); -$enc = $gpg -> encrypt($plaintext); +$gpg->seterrormode(gnupg::ERROR_WARNING); +$gpg->addencryptkey($fingerprint); +$enc = $gpg->encrypt($plaintext); $gpg = NULL; $gpg = new gnupg(); -$gpg -> adddecryptkey($fingerprint, $passphrase); -$ret = $gpg -> decrypt ($enc); +$gpg->adddecryptkey($fingerprint, $passphrase); +$ret = $gpg->decrypt($enc); var_dump($ret); ?> diff --git a/tests/gnupg_oo_encryptsign.phpt b/tests/gnupg_oo_encryptsign.phpt index 801697b..b27d678 100644 --- a/tests/gnupg_oo_encryptsign.phpt +++ b/tests/gnupg_oo_encryptsign.phpt @@ -4,19 +4,21 @@ encryptsign and decryptverify a text --FILE-- seterrormode(gnupg::ERROR_WARNING); -$gpg -> addencryptkey($fingerprint); -$gpg -> addsignkey($fingerprint, $passphrase); -$enc = $gpg -> encryptsign($plaintext); +$gpg->seterrormode(gnupg::ERROR_WARNING); +$gpg->addencryptkey($fingerprint); +$gpg->addsignkey($fingerprint, $passphrase); +$enc = $gpg->encryptsign($plaintext); $gpg = NULL; $plaintext = false; $gpg = new gnupg(); -$gpg -> adddecryptkey($fingerprint, $passphrase); -$ret = $gpg -> decryptverify ($enc, $plaintext); +$gpg->adddecryptkey($fingerprint, $passphrase); +$ret = $gpg->decryptverify ($enc, $plaintext); var_dump($ret); var_dump($plaintext); diff --git a/tests/gnupg_oo_export.phpt b/tests/gnupg_oo_export.phpt index d94117f..6638501 100644 --- a/tests/gnupg_oo_export.phpt +++ b/tests/gnupg_oo_export.phpt @@ -4,10 +4,12 @@ export a key --FILE-- seterrormode(gnupg::ERROR_WARNING); -$ret = $gpg -> export($fingerprint); +$gpg->seterrormode(gnupg::ERROR_WARNING); +$ret = $gpg->export($fingerprint); var_dump($ret); ?> --EXPECTF-- diff --git a/tests/gnupg_oo_keyinfo.phpt b/tests/gnupg_oo_keyinfo.phpt index 9beb553..52c49a9 100644 --- a/tests/gnupg_oo_keyinfo.phpt +++ b/tests/gnupg_oo_keyinfo.phpt @@ -4,10 +4,12 @@ get keyinfo --FILE-- seterrormode(gnupg::ERROR_WARNING); -$ret = $gpg -> keyinfo($fingerprint); +$gpg->seterrormode(gnupg::ERROR_WARNING); +$ret = $gpg->keyinfo($fingerprint); var_dump($ret); ?> --EXPECT-- diff --git a/tests/gnupg_oo_listsignatures.phpt b/tests/gnupg_oo_listsignatures.phpt index e8ea9ca..8fdd9bc 100644 --- a/tests/gnupg_oo_listsignatures.phpt +++ b/tests/gnupg_oo_listsignatures.phpt @@ -4,10 +4,12 @@ list signatures --FILE-- seterrormode(gnupg::ERROR_WARNING); -$ret = $gpg -> listsignatures($fingerprint); +$gpg->seterrormode(gnupg::ERROR_WARNING); +$ret = $gpg->listsignatures($fingerprint); var_dump($ret); ?> --EXPECT-- diff --git a/tests/gnupg_oo_sign_clear.phpt b/tests/gnupg_oo_sign_clear.phpt index 2caefc9..7e45f94 100644 --- a/tests/gnupg_oo_sign_clear.phpt +++ b/tests/gnupg_oo_sign_clear.phpt @@ -4,18 +4,20 @@ sign a text with sigmode SIG_MODE_CLEAR --FILE-- seterrormode(gnupg::ERROR_WARNING); -$gpg -> setsignmode(gnupg::SIG_MODE_CLEAR); -$gpg -> addsignkey($fingerprint, $passphrase); -$ret = $gpg -> sign($plaintext); +$gpg->seterrormode(gnupg::ERROR_WARNING); +$gpg->setsignmode(gnupg::SIG_MODE_CLEAR); +$gpg->addsignkey($fingerprint, $passphrase); +$ret = $gpg->sign($plaintext); $gpg = NULL; $gpg = new gnupg(); $tmp = false; -$ret = $gpg -> verify($ret, false, $tmp); +$ret = $gpg->verify($ret, false, $tmp); var_dump($ret); var_dump($tmp); diff --git a/tests/gnupg_oo_sign_detach.phpt b/tests/gnupg_oo_sign_detach.phpt index 79f81f2..b510c0a 100644 --- a/tests/gnupg_oo_sign_detach.phpt +++ b/tests/gnupg_oo_sign_detach.phpt @@ -4,18 +4,20 @@ sign a text with mode SIG_MODE_DETACH --FILE-- seterrormode(gnupg::ERROR_WARNING); -$gpg -> setsignmode(gnupg::SIG_MODE_DETACH); -$gpg -> addsignkey($fingerprint, $passphrase); -$ret = $gpg -> sign($plaintext); +$gpg->seterrormode(gnupg::ERROR_WARNING); +$gpg->setsignmode(gnupg::SIG_MODE_DETACH); +$gpg->addsignkey($fingerprint, $passphrase); +$ret = $gpg->sign($plaintext); $gpg = NULL; $gpg = new gnupg(); $tmp = false; -$ret = $gpg -> verify($plaintext, $ret); +$ret = $gpg->verify($plaintext, $ret); var_dump($ret); var_dump($plaintext); diff --git a/tests/gnupg_oo_sign_detach_nonarmor.phpt b/tests/gnupg_oo_sign_detach_nonarmor.phpt index 60f4e00..ab70bc1 100644 --- a/tests/gnupg_oo_sign_detach_nonarmor.phpt +++ b/tests/gnupg_oo_sign_detach_nonarmor.phpt @@ -4,19 +4,21 @@ sign a text with mode SIG_MODE_DETACH and without armored output --FILE-- seterrormode(gnupg::ERROR_WARNING); -$gpg -> setarmor(0); -$gpg -> setsignmode(gnupg::SIG_MODE_DETACH); -$gpg -> addsignkey($fingerprint, $passphrase); -$ret = $gpg -> sign($plaintext); +$gpg->seterrormode(gnupg::ERROR_WARNING); +$gpg->setarmor(0); +$gpg->setsignmode(gnupg::SIG_MODE_DETACH); +$gpg->addsignkey($fingerprint, $passphrase); +$ret = $gpg->sign($plaintext); $gpg = NULL; $gpg = new gnupg(); $tmp = false; -$ret = $gpg -> verify($plaintext, $ret); +$ret = $gpg->verify($plaintext, $ret); var_dump($ret); var_dump($plaintext); diff --git a/tests/gnupg_oo_sign_normal.phpt b/tests/gnupg_oo_sign_normal.phpt index 4faf400..754a138 100644 --- a/tests/gnupg_oo_sign_normal.phpt +++ b/tests/gnupg_oo_sign_normal.phpt @@ -4,19 +4,21 @@ sign a text with mode SIG_MODE_NORMAL --FILE-- seterrormode(gnupg::ERROR_WARNING); -$gpg -> setsignmode(gnupg::SIG_MODE_NORMAL); -$gpg -> addsignkey($fingerprint, $passphrase); -$ret = $gpg -> sign($plaintext); +$gpg->seterrormode(gnupg::ERROR_WARNING); +$gpg->setsignmode(gnupg::SIG_MODE_NORMAL); +$gpg->addsignkey($fingerprint, $passphrase); +$ret = $gpg->sign($plaintext); $gpg = NULL; $gpg = new gnupg(); $tmp = false; $plaintext = false; -$ret = $gpg -> verify($ret, false, $plaintext); +$ret = $gpg->verify($ret, false, $plaintext); var_dump($ret); var_dump($plaintext); diff --git a/tests/gnupg_oo_sign_normal_noarmor.phpt b/tests/gnupg_oo_sign_normal_noarmor.phpt index 0651ce8..d9cd6df 100644 --- a/tests/gnupg_oo_sign_normal_noarmor.phpt +++ b/tests/gnupg_oo_sign_normal_noarmor.phpt @@ -4,20 +4,22 @@ sign a text with mode SIG_MODE_NORMAL and without armored output --FILE-- seterrormode(gnupg::ERROR_WARNING); -$gpg -> setarmor(0); -$gpg -> setsignmode(gnupg::SIG_MODE_NORMAL); -$gpg -> addsignkey($fingerprint, $passphrase); -$ret = $gpg -> sign($plaintext); +$gpg->seterrormode(gnupg::ERROR_WARNING); +$gpg->setarmor(0); +$gpg->setsignmode(gnupg::SIG_MODE_NORMAL); +$gpg->addsignkey($fingerprint, $passphrase); +$ret = $gpg->sign($plaintext); $gpg = NULL; $gpg = new gnupg(); -//$ret = $gpg -> verify($plaintext, $ret); +//$ret = $gpg->verify($plaintext, $ret); $plaintext = false; -$ret = $gpg -> verify($ret, false, $plaintext); +$ret = $gpg->verify($ret, false, $plaintext); var_dump($ret); var_dump($plaintext); diff --git a/tests/gnupg_oo_zzz_deletekey.phpt b/tests/gnupg_oo_zzz_deletekey.phpt index 46f6da0..7e5fcd6 100644 --- a/tests/gnupg_oo_zzz_deletekey.phpt +++ b/tests/gnupg_oo_zzz_deletekey.phpt @@ -4,10 +4,12 @@ delete a key from the keyring --FILE-- seterrormode(gnupg::ERROR_WARNING); -$ret = $gpg -> deletekey($fingerprint,true); +$gpg->seterrormode(gnupg::ERROR_WARNING); +$ret = $gpg->deletekey($fingerprint,true); var_dump($ret); ?> --EXPECT-- diff --git a/tests/gnupg_res_0001_import.phpt b/tests/gnupg_res_0001_import.phpt index 7eb5160..291f323 100644 --- a/tests/gnupg_res_0001_import.phpt +++ b/tests/gnupg_res_0001_import.phpt @@ -2,9 +2,9 @@ import a new key into the keyring --FILE-- import($testkey); + } + + return true; +} + ?> +