1<?php 2 3/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 4 5/** 6 * Public key deletion tests for the Crypt_GPG package. 7 * 8 * These tests require the PHPUnit 3.6 or greater package to be installed. 9 * PHPUnit is installable using PEAR. See the 10 * {@link http://www.phpunit.de/manual/3.6/en/installation.html manual} 11 * for detailed installation instructions. 12 * 13 * To run these tests, use: 14 * <code> 15 * $ phpunit DeletePublicKeyTestCase 16 * </code> 17 * 18 * LICENSE: 19 * 20 * This library is free software; you can redistribute it and/or modify 21 * it under the terms of the GNU Lesser General Public License as 22 * published by the Free Software Foundation; either version 2.1 of the 23 * License, or (at your option) any later version. 24 * 25 * This library is distributed in the hope that it will be useful, 26 * but WITHOUT ANY WARRANTY; without even the implied warranty of 27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 28 * Lesser General Public License for more details. 29 * 30 * You should have received a copy of the GNU Lesser General Public 31 * License along with this library; if not, see 32 * <http://www.gnu.org/licenses/> 33 * 34 * @category Encryption 35 * @package Crypt_GPG 36 * @author Michael Gauthier <mike@silverorange.com> 37 * @copyright 2005-2008 silverorange 38 * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 39 * @version CVS: $Id$ 40 * @link http://pear.php.net/package/Crypt_GPG 41 */ 42 43/** 44 * Base test case. 45 */ 46require_once 'TestCase.php'; 47 48/** 49 * Tests public key deletion abilities of Crypt_GPG. 50 * 51 * @category Encryption 52 * @package Crypt_GPG 53 * @author Michael Gauthier <mike@silverorange.com> 54 * @copyright 2005-2008 silverorange 55 * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 56 * @link http://pear.php.net/package/Crypt_GPG 57 */ 58class DeletePublicKeyTest extends Crypt_GPG_TestCase 59{ 60 /** 61 * @group delete-public 62 */ 63 public function testDeletePublicKey() 64 { 65 $keyId = 'public-only@example.com'; 66 $this->gpg->deletePublicKey($keyId); 67 68 $expectedKeys = array(); 69 $keys = $this->gpg->getKeys($keyId); 70 $this->assertEquals($expectedKeys, $keys); 71 } 72 73 /** 74 * @group delete-public 75 */ 76 public function testDeletePublicKeyDeletePrivateKeyException() 77 { 78 $this->expectException('Crypt_GPG_DeletePrivateKeyException'); 79 80 // GnuPG 2.1(.11) allows public key deletion in this case 81 if (version_compare($this->gpg->getVersion(), '2.1.0', 'ge')) { 82 $this->markTestSkipped('GnuPG >= 2.1 allows public key deletion if private key exists.'); 83 } 84 85 $keyId = 'first-keypair@example.com'; 86 $this->gpg->deletePublicKey($keyId); 87 } 88 89 /** 90 * @group delete-public 91 */ 92 public function testDeletePublicKey_privExists() 93 { 94 // GnuPG 2.1(.11) allows public key deletion in this case 95 if (version_compare($this->gpg->getVersion(), '2.1.0', 'lt')) { 96 $this->markTestSkipped('GnuPG >= 2.1 allows public key deletion if private key exists.'); 97 } 98 99 $keyId = 'first-keypair@example.com'; 100 $this->gpg->deletePublicKey($keyId); 101 102 $this->assertTrue(true); 103 } 104 105 /** 106 * @group delete-public 107 */ 108 public function testDeletePublicKeyNotFoundException() 109 { 110 $this->expectException('Crypt_GPG_KeyNotFoundException'); 111 112 $keyId = 'non-existent-key@example.com'; 113 $this->gpg->deletePublicKey($keyId); 114 } 115} 116