Mercurial > hg > rc1
comparison vendor/pear/crypt_gpg/tests/UserIdTest.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 * User id 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 UserIdTestCase | |
| 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-2010 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 * User Id class. | |
| 50 */ | |
| 51 require_once 'Crypt/GPG/UserId.php'; | |
| 52 | |
| 53 /** | |
| 54 * User id class tests for Crypt_GPG. | |
| 55 * | |
| 56 * @category Encryption | |
| 57 * @package Crypt_GPG | |
| 58 * @author Michael Gauthier <mike@silverorange.com> | |
| 59 * @copyright 2008-2010 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 UserIdTestCase extends Crypt_GPG_TestCase | |
| 64 { | |
| 65 // construct | |
| 66 // {{{ testConstructFromString() | |
| 67 | |
| 68 /** | |
| 69 * @group construct | |
| 70 */ | |
| 71 public function testConstructFromString() | |
| 72 { | |
| 73 $expectedUserId = new Crypt_GPG_UserId(array( | |
| 74 'name' => 'Example User', | |
| 75 'comment' => 'This is a test comment', | |
| 76 'email' => 'test@example.com' | |
| 77 )); | |
| 78 | |
| 79 $string = 'Example User (This is a test comment) <test@example.com>'; | |
| 80 $userId = new Crypt_GPG_UserId($string); | |
| 81 | |
| 82 $this->assertEquals($expectedUserId, $userId); | |
| 83 } | |
| 84 | |
| 85 // }}} | |
| 86 // {{{ testConstructFromUserId() | |
| 87 | |
| 88 /** | |
| 89 * @group construct | |
| 90 */ | |
| 91 public function testConstructFromUserId() | |
| 92 { | |
| 93 $expectedUserId = new Crypt_GPG_UserId(array( | |
| 94 'name' => 'Example User', | |
| 95 'comment' => 'This is a test comment', | |
| 96 'email' => 'test@example.com', | |
| 97 'revoked' => true, | |
| 98 'valid' => false | |
| 99 )); | |
| 100 | |
| 101 $userId = new Crypt_GPG_UserId($expectedUserId); | |
| 102 | |
| 103 $this->assertEquals($expectedUserId, $userId); | |
| 104 } | |
| 105 | |
| 106 // }}} | |
| 107 // {{{ testConstructFromArray() | |
| 108 | |
| 109 /** | |
| 110 * @group construct | |
| 111 */ | |
| 112 public function testConstructFromArray() | |
| 113 { | |
| 114 $userId = new Crypt_GPG_UserId(array( | |
| 115 'name' => 'Example User', | |
| 116 'comment' => 'This is a test comment', | |
| 117 'email' => 'test@example.com', | |
| 118 'revoked' => true, | |
| 119 'valid' => false | |
| 120 )); | |
| 121 | |
| 122 $this->assertEquals('Example User', $userId->getName()); | |
| 123 $this->assertEquals('This is a test comment', $userId->getComment()); | |
| 124 $this->assertEquals('test@example.com', $userId->getEmail()); | |
| 125 | |
| 126 $this->assertTrue($userId->isRevoked()); | |
| 127 | |
| 128 $this->assertFalse($userId->isValid()); | |
| 129 } | |
| 130 | |
| 131 // }}} | |
| 132 | |
| 133 // parse | |
| 134 // {{{ testParseFull() | |
| 135 | |
| 136 /** | |
| 137 * @group parse | |
| 138 */ | |
| 139 public function testParseFull() | |
| 140 { | |
| 141 $expectedUserId = new Crypt_GPG_UserId(array( | |
| 142 'name' => 'Example User', | |
| 143 'comment' => 'This is a test comment', | |
| 144 'email' => 'test@example.com' | |
| 145 )); | |
| 146 | |
| 147 $string = 'Example User (This is a test comment) <test@example.com>'; | |
| 148 $userId = Crypt_GPG_UserId::parse($string); | |
| 149 | |
| 150 $this->assertEquals($expectedUserId, $userId); | |
| 151 } | |
| 152 | |
| 153 // }}} | |
| 154 // {{{ testParseNameOnly() | |
| 155 | |
| 156 /** | |
| 157 * @group parse | |
| 158 */ | |
| 159 public function testParseNameOnly() | |
| 160 { | |
| 161 $expectedUserId = new Crypt_GPG_UserId(array( | |
| 162 'name' => 'Example User' | |
| 163 )); | |
| 164 | |
| 165 $string = 'Example User'; | |
| 166 $userId = Crypt_GPG_UserId::parse($string); | |
| 167 | |
| 168 $this->assertEquals($expectedUserId, $userId); | |
| 169 } | |
| 170 | |
| 171 // }}} | |
| 172 // {{{ testParseNameComment() | |
| 173 | |
| 174 /** | |
| 175 * @group parse | |
| 176 */ | |
| 177 public function testParseNameComment() | |
| 178 { | |
| 179 $expectedUserId = new Crypt_GPG_UserId(array( | |
| 180 'name' => 'Example User', | |
| 181 'comment' => 'This is a test comment' | |
| 182 )); | |
| 183 | |
| 184 $string = 'Example User (This is a test comment)'; | |
| 185 $userId = Crypt_GPG_UserId::parse($string); | |
| 186 | |
| 187 $this->assertEquals($expectedUserId, $userId); | |
| 188 } | |
| 189 | |
| 190 // }}} | |
| 191 // {{{ testParseNameEmail() | |
| 192 | |
| 193 /** | |
| 194 * @group parse | |
| 195 */ | |
| 196 public function testParseNameEmail() | |
| 197 { | |
| 198 $expectedUserId = new Crypt_GPG_UserId(array( | |
| 199 'name' => 'Example User', | |
| 200 'email' => 'test@example.com' | |
| 201 )); | |
| 202 | |
| 203 $string = 'Example User <test@example.com>'; | |
| 204 $userId = Crypt_GPG_UserId::parse($string); | |
| 205 | |
| 206 $this->assertEquals($expectedUserId, $userId); | |
| 207 } | |
| 208 | |
| 209 // }}} | |
| 210 // {{{ testParseEmailOnly() | |
| 211 | |
| 212 /** | |
| 213 * @group parse | |
| 214 */ | |
| 215 public function testParseEmailOnly() | |
| 216 { | |
| 217 $expectedUserId = new Crypt_GPG_UserId(array( | |
| 218 'name' => '', | |
| 219 'email' => 'test@example.com' | |
| 220 )); | |
| 221 | |
| 222 $string = '<test@example.com>'; | |
| 223 $userId = Crypt_GPG_UserId::parse($string); | |
| 224 | |
| 225 $this->assertEquals($expectedUserId, $userId); | |
| 226 | |
| 227 $string = 'test@example.com'; | |
| 228 $userId = Crypt_GPG_UserId::parse($string); | |
| 229 | |
| 230 $this->assertEquals($expectedUserId, $userId); | |
| 231 } | |
| 232 | |
| 233 // }}} | |
| 234 | |
| 235 // to-string | |
| 236 // {{{ testToStringFull() | |
| 237 | |
| 238 /** | |
| 239 * @group to-string | |
| 240 */ | |
| 241 public function testToStringFull() | |
| 242 { | |
| 243 $expected = 'Example User (This is a test comment) <test@example.com>'; | |
| 244 | |
| 245 $userId = new Crypt_GPG_UserId(array( | |
| 246 'name' => 'Example User', | |
| 247 'comment' => 'This is a test comment', | |
| 248 'email' => 'test@example.com' | |
| 249 )); | |
| 250 | |
| 251 $string = strval($userId); | |
| 252 $this->assertEquals($expected, $string); | |
| 253 } | |
| 254 | |
| 255 // }}} | |
| 256 // {{{ testToStringNameOnly() | |
| 257 | |
| 258 /** | |
| 259 * @group to-string | |
| 260 */ | |
| 261 public function testToStringNameOnly() | |
| 262 { | |
| 263 $expected = 'Example User'; | |
| 264 | |
| 265 $userId = new Crypt_GPG_UserId(array( | |
| 266 'name' => 'Example User', | |
| 267 )); | |
| 268 | |
| 269 $string = strval($userId); | |
| 270 $this->assertEquals($expected, $string); | |
| 271 } | |
| 272 | |
| 273 // }}} | |
| 274 // {{{ testToStringNameComment() | |
| 275 | |
| 276 /** | |
| 277 * @group to-string | |
| 278 */ | |
| 279 public function testToStringNameComment() | |
| 280 { | |
| 281 $expected = 'Example User (This is a test comment)'; | |
| 282 | |
| 283 $userId = new Crypt_GPG_UserId(array( | |
| 284 'name' => 'Example User', | |
| 285 'comment' => 'This is a test comment', | |
| 286 )); | |
| 287 | |
| 288 $string = strval($userId); | |
| 289 $this->assertEquals($expected, $string); | |
| 290 } | |
| 291 | |
| 292 // }}} | |
| 293 // {{{ testToStringNameEmail() | |
| 294 | |
| 295 /** | |
| 296 * @group to-string | |
| 297 */ | |
| 298 public function testToStringNameEmail() | |
| 299 { | |
| 300 $expected = 'Example User <test@example.com>'; | |
| 301 | |
| 302 $userId = new Crypt_GPG_UserId(array( | |
| 303 'name' => 'Example User', | |
| 304 'email' => 'test@example.com' | |
| 305 )); | |
| 306 | |
| 307 $string = strval($userId); | |
| 308 $this->assertEquals($expected, $string); | |
| 309 } | |
| 310 | |
| 311 // }}} | |
| 312 | |
| 313 // accessors | |
| 314 // {{{ testGetName() | |
| 315 | |
| 316 /** | |
| 317 * @group accessors | |
| 318 */ | |
| 319 public function testGetName() | |
| 320 { | |
| 321 $userId = new Crypt_GPG_UserId(array( | |
| 322 'name' => 'Example User' | |
| 323 )); | |
| 324 | |
| 325 $this->assertEquals('Example User', $userId->getName()); | |
| 326 } | |
| 327 | |
| 328 // }}} | |
| 329 // {{{ testGetComment() | |
| 330 | |
| 331 /** | |
| 332 * @group accessors | |
| 333 */ | |
| 334 public function testGetComment() | |
| 335 { | |
| 336 $userId = new Crypt_GPG_UserId(array( | |
| 337 'name' => 'Example User', | |
| 338 'comment' => 'This is a test comment' | |
| 339 )); | |
| 340 | |
| 341 $this->assertEquals('This is a test comment', $userId->getComment()); | |
| 342 } | |
| 343 | |
| 344 // }}} | |
| 345 // {{{ testGetEmail() | |
| 346 | |
| 347 /** | |
| 348 * @group accessors | |
| 349 */ | |
| 350 public function testGetEmail() | |
| 351 { | |
| 352 $userId = new Crypt_GPG_UserId(array( | |
| 353 'name' => 'Example User', | |
| 354 'email' => 'test@example.com' | |
| 355 )); | |
| 356 | |
| 357 $this->assertEquals('test@example.com', $userId->getEmail()); | |
| 358 } | |
| 359 | |
| 360 // }}} | |
| 361 // {{{ testIsRevoked() | |
| 362 | |
| 363 /** | |
| 364 * @group accessors | |
| 365 */ | |
| 366 public function testIsRevoked() | |
| 367 { | |
| 368 $userId = new Crypt_GPG_UserId(array( | |
| 369 'name' => 'Example User', | |
| 370 'revoked' => true, | |
| 371 )); | |
| 372 | |
| 373 $this->assertTrue($userId->isRevoked()); | |
| 374 | |
| 375 $userId = new Crypt_GPG_UserId(array( | |
| 376 'name' => 'Example User', | |
| 377 'revoked' => false, | |
| 378 )); | |
| 379 | |
| 380 $this->assertFalse($userId->isRevoked()); | |
| 381 } | |
| 382 | |
| 383 // }}} | |
| 384 // {{{ testIsValid() | |
| 385 | |
| 386 /** | |
| 387 * @group accessors | |
| 388 */ | |
| 389 public function testIsValid() | |
| 390 { | |
| 391 $userId = new Crypt_GPG_UserId(array( | |
| 392 'name' => 'Example User', | |
| 393 'valid' => true, | |
| 394 )); | |
| 395 | |
| 396 $this->assertTrue($userId->isValid()); | |
| 397 | |
| 398 $userId = new Crypt_GPG_UserId(array( | |
| 399 'name' => 'Example User', | |
| 400 'valid' => false, | |
| 401 )); | |
| 402 | |
| 403 $this->assertFalse($userId->isValid()); | |
| 404 } | |
| 405 | |
| 406 // }}} | |
| 407 | |
| 408 // mutators | |
| 409 // {{{ testSetName() | |
| 410 | |
| 411 /** | |
| 412 * @group mutators | |
| 413 */ | |
| 414 public function testSetName() | |
| 415 { | |
| 416 $expectedUserId = new Crypt_GPG_UserId(array( | |
| 417 'name' => 'Second Name' | |
| 418 )); | |
| 419 | |
| 420 $userId = new Crypt_GPG_UserId(array( | |
| 421 'name' => 'First Name' | |
| 422 )); | |
| 423 | |
| 424 $userId->setName('Second Name'); | |
| 425 | |
| 426 $this->assertEquals($expectedUserId, $userId); | |
| 427 } | |
| 428 | |
| 429 // }}} | |
| 430 // {{{ testSetComment() | |
| 431 | |
| 432 /** | |
| 433 * @group mutators | |
| 434 */ | |
| 435 public function testSetComment() | |
| 436 { | |
| 437 $expectedUserId = new Crypt_GPG_UserId(array( | |
| 438 'name' => 'Example User', | |
| 439 'comment' => 'Second comment text' | |
| 440 )); | |
| 441 | |
| 442 $userId = new Crypt_GPG_UserId(array( | |
| 443 'name' => 'Example User', | |
| 444 'comment' => 'First comment text' | |
| 445 )); | |
| 446 | |
| 447 $userId->setComment('Second comment text'); | |
| 448 | |
| 449 $this->assertEquals($expectedUserId, $userId); | |
| 450 } | |
| 451 | |
| 452 // }}} | |
| 453 // {{{ testSetEmail() | |
| 454 | |
| 455 /** | |
| 456 * @group mutators | |
| 457 */ | |
| 458 public function testSetEmail() | |
| 459 { | |
| 460 $expectedUserId = new Crypt_GPG_UserId(array( | |
| 461 'name' => 'Example User', | |
| 462 'email' => 'second@example.com' | |
| 463 )); | |
| 464 | |
| 465 $userId = new Crypt_GPG_UserId(array( | |
| 466 'name' => 'Example User', | |
| 467 'email' => 'first@example.com' | |
| 468 )); | |
| 469 | |
| 470 $userId->setEmail('second@example.com'); | |
| 471 | |
| 472 $this->assertEquals($expectedUserId, $userId); | |
| 473 } | |
| 474 | |
| 475 // }}} | |
| 476 // {{{ testSetRevoked() | |
| 477 | |
| 478 /** | |
| 479 * @group mutators | |
| 480 */ | |
| 481 public function testSetRevoked() | |
| 482 { | |
| 483 $expectedUserId = new Crypt_GPG_UserId(array( | |
| 484 'name' => 'Example User', | |
| 485 'revoked' => true, | |
| 486 )); | |
| 487 | |
| 488 $userId = new Crypt_GPG_UserId(array( | |
| 489 'name' => 'Example User', | |
| 490 'revoked' => false, | |
| 491 )); | |
| 492 | |
| 493 $userId->setRevoked(true); | |
| 494 | |
| 495 $this->assertEquals($expectedUserId, $userId); | |
| 496 } | |
| 497 | |
| 498 // }}} | |
| 499 // {{{ testSetValid() | |
| 500 | |
| 501 /** | |
| 502 * @group mutators | |
| 503 */ | |
| 504 public function testSetValid() | |
| 505 { | |
| 506 $expectedUserId = new Crypt_GPG_UserId(array( | |
| 507 'name' => 'Example User', | |
| 508 'valid' => true, | |
| 509 )); | |
| 510 | |
| 511 $userId = new Crypt_GPG_UserId(array( | |
| 512 'name' => 'Example User', | |
| 513 'valid' => false, | |
| 514 )); | |
| 515 | |
| 516 $userId->setValid(true); | |
| 517 | |
| 518 $this->assertEquals($expectedUserId, $userId); | |
| 519 } | |
| 520 | |
| 521 // }}} | |
| 522 | |
| 523 // fluent interface | |
| 524 // {{{ testFluentInterface | |
| 525 | |
| 526 /** | |
| 527 * @group fluent | |
| 528 */ | |
| 529 public function testFluentInterface() | |
| 530 { | |
| 531 $userId = new Crypt_GPG_UserId(); | |
| 532 $returnedUserId = $userId->setName('Alice'); | |
| 533 $this->assertEquals( | |
| 534 $userId, | |
| 535 $returnedUserId, | |
| 536 'Failed asserting fluent interface works for setName() method.' | |
| 537 ); | |
| 538 | |
| 539 $userId = new Crypt_GPG_UserId(); | |
| 540 $returnedUserId = $userId->setComment('encryption is fun'); | |
| 541 $this->assertEquals( | |
| 542 $userId, | |
| 543 $returnedUserId, | |
| 544 'Failed asserting fluent interface works for setComment() method.' | |
| 545 ); | |
| 546 | |
| 547 $userId = new Crypt_GPG_UserId(); | |
| 548 $returnedUserId = $userId->setEmail('test@example.com'); | |
| 549 $this->assertEquals( | |
| 550 $userId, | |
| 551 $returnedUserId, | |
| 552 'Failed asserting fluent interface works for setEmail() method.' | |
| 553 ); | |
| 554 | |
| 555 $userId = new Crypt_GPG_UserId(); | |
| 556 $returnedUserId = $userId->setRevoked(true); | |
| 557 $this->assertEquals( | |
| 558 $userId, | |
| 559 $returnedUserId, | |
| 560 'Failed asserting fluent interface works for setRevoked() method.' | |
| 561 ); | |
| 562 | |
| 563 $userId = new Crypt_GPG_UserId(); | |
| 564 $returnedUserId = $userId->setValid(true); | |
| 565 $this->assertEquals( | |
| 566 $userId, | |
| 567 $returnedUserId, | |
| 568 'Failed asserting fluent interface works for setValid() method.' | |
| 569 ); | |
| 570 } | |
| 571 | |
| 572 // }}} | |
| 573 } | |
| 574 | |
| 575 ?> |
