comparison vendor/pear/crypt_gpg/tests/ExceptionsTest.php @ 0:1e000243b222

vanilla 1.3.3 distro, I hope
author Charlie Root
date Thu, 04 Jan 2018 15:50:29 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:1e000243b222
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * Exception class test cases 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 ExceptionsTestCase
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 2008-2011 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 */
46 require_once 'TestCase.php';
47
48 /**
49 * Exception classes.
50 */
51 require_once 'Crypt/GPG/Exceptions.php';
52
53 /**
54 * Exception classes tests for Crypt_GPG.
55 *
56 * @category Encryption
57 * @package Crypt_GPG
58 * @author Michael Gauthier <mike@silverorange.com>
59 * @copyright 2008-2011 silverorange
60 * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
61 * @link http://pear.php.net/package/Crypt_GPG
62 */
63 class ExceptionsTestCase extends Crypt_GPG_TestCase
64 {
65 // exception
66 // {{{ testException
67
68 /**
69 * @group exception
70 * @expectedException Crypt_GPG_Exception
71 * @expectedExceptionMessage test exception
72 */
73 public function testException()
74 {
75 throw new Crypt_GPG_Exception('test exception');
76 }
77
78 // }}}
79
80 // file exception
81 // {{{ testFileException
82
83 /**
84 * @group file-exception
85 * @expectedException Crypt_GPG_FileException
86 * @expectedExceptionMessage test exception
87 */
88 public function testFileException()
89 {
90 throw new Crypt_GPG_FileException('test exception');
91 }
92
93 // }}}
94 // {{{ testFileException_getFilename()
95
96 /**
97 * @group file-exception
98 */
99 public function testFileException_getFilename()
100 {
101 $e = new Crypt_GPG_FileException('test exception', 0,
102 'test-filename.php');
103
104 $this->assertEquals('test-filename.php', $e->getFilename());
105 }
106
107 // }}}
108
109 // open subprocess exception
110 // {{{ testOpenSubprocessException
111
112 /**
113 * @group open-subprocess-exception
114 * @expectedException Crypt_GPG_OpenSubprocessException
115 * @expectedExceptionMessage test exception
116 */
117 public function testOpenSubprocessException()
118 {
119 throw new Crypt_GPG_OpenSubprocessException('test exception');
120 }
121
122 // }}}
123 // {{{ testOpenSubprocessException_getCommand()
124
125 /**
126 * @group open-subprocess-exception
127 */
128 public function testOpenSubprocessException_getCommand()
129 {
130 $e = new Crypt_GPG_OpenSubprocessException('test exception', 0,
131 'gpg --verify');
132
133 $this->assertEquals('gpg --verify', $e->getCommand());
134 }
135
136 // }}}
137
138 // invalid operation exception
139 // {{{ testInvalidOperationException
140
141 /**
142 * @group invalid-operation-exception
143 * @expectedException Crypt_GPG_InvalidOperationException
144 * @expectedExceptionMessage test exception
145 */
146 public function testInvalidOperationException()
147 {
148 throw new Crypt_GPG_InvalidOperationException('test exception');
149 }
150
151 // }}}
152 // {{{ testInvalidOperationException_getOperation()
153
154 /**
155 * @group invalid-operation-exception
156 */
157 public function testInvalidOperationException_getOperation()
158 {
159 $e = new Crypt_GPG_InvalidOperationException('test exception', 0,
160 '--verify');
161
162 $this->assertEquals('--verify', $e->getOperation());
163 }
164
165 // }}}
166
167 // key not found exception
168 // {{{ testKeyNotFoundException
169
170 /**
171 * @group key-not-found-exception
172 * @expectedException Crypt_GPG_KeyNotFoundException
173 * @expectedExceptionMessage test exception
174 */
175 public function testKeyNotFoundException()
176 {
177 throw new Crypt_GPG_KeyNotFoundException('test exception');
178 }
179
180 // }}}
181 // {{{ testKeyNotFoundException_getKeyId()
182
183 /**
184 * @group key-not-found-exception
185 */
186 public function testKeyNotFoundException_getKeyId()
187 {
188 $e = new Crypt_GPG_KeyNotFoundException('test exception', 0,
189 '9F93F9116728EF12');
190
191 $this->assertEquals('9F93F9116728EF12', $e->getKeyId());
192 }
193
194 // }}}
195
196 // no data exception
197 // {{{ testNoDataException
198
199 /**
200 * @group no-data-exception
201 * @expectedException Crypt_GPG_NoDataException
202 * @expectedExceptionMessage test exception
203 */
204 public function testNoDataException()
205 {
206 throw new Crypt_GPG_NoDataException('test exception');
207 }
208
209 // }}}
210
211 // bad passphrase exception
212 // {{{ testBadPassphraseException
213
214 /**
215 * @group bad-passphrase-exception
216 * @expectedException Crypt_GPG_BadPassphraseException
217 * @expectedExceptionMessage test exception
218 */
219 public function testBadPassphraseException()
220 {
221 throw new Crypt_GPG_BadPassphraseException('test exception');
222 }
223
224 // }}}
225 // {{{ testBadPassphraseException_getBadPassphrases()
226
227 /**
228 * @group bad-passphrase-exception
229 */
230 public function testBadPassphraseException_getBadPassphrases()
231 {
232 $e = new Crypt_GPG_BadPassphraseException('test exception', 0,
233 array('C097D9EC94C06363', '9F93F9116728EF12'));
234
235 $keyIds = $e->getBadPassphrases();
236 $this->assertTrue(is_array($keyIds), 'Failed to assert returned ' .
237 'key ids for bad passphrases is an array.');
238
239 $this->assertContains('C097D9EC94C06363', $keyIds);
240 $this->assertContains('9F93F9116728EF12', $keyIds);
241 }
242
243 // }}}
244 // {{{ testBadPassphraseException_getMissingPassphrase()
245
246 /**
247 * @group bad-passphrase-exception
248 */
249 public function testBadPassphraseException_getMissingPassphrase()
250 {
251 $e = new Crypt_GPG_BadPassphraseException('test exception', 0, array(),
252 array('C097D9EC94C06363', '9F93F9116728EF12'));
253
254 $keyIds = $e->getMissingPassphrases();
255 $this->assertTrue(is_array($keyIds), 'Failed to assert returned ' .
256 'key ids for missing passphrases is an array.');
257
258 $this->assertContains('C097D9EC94C06363', $keyIds);
259 $this->assertContains('9F93F9116728EF12', $keyIds);
260 }
261
262 // }}}
263
264 // delete private key exception
265 // {{{ testDeletePrivateKeyException
266
267 /**
268 * @group delete-private-key-exception
269 * @expectedException Crypt_GPG_DeletePrivateKeyException
270 * @expectedExceptionMessage test exception
271 */
272 public function testDeletePrivateKeyException()
273 {
274 throw new Crypt_GPG_DeletePrivateKeyException('test exception');
275 }
276
277 // }}}
278 // {{{ testDeletePrivateKeyException_getKeyId()
279
280 /**
281 * @group delete-private-key-exception
282 */
283 public function testDeletePrivateKeyException_getKeyId()
284 {
285 $e = new Crypt_GPG_DeletePrivateKeyException('test exception', 0,
286 '9F93F9116728EF12');
287
288 $this->assertEquals('9F93F9116728EF12', $e->getKeyId());
289 }
290
291 // }}}
292 }
293
294 ?>