protected function assertKeyEquals(Crypt_GPG_Key $key1, Crypt_GPG_Key $key2) { $userIds1 = $key1->getUserIds(); $userIds2 = $key2->getUserIds(); $userId1 = $userIds1[0]; $userId2 = $userIds2[0]; $subKeys1 = $key1->getSubKeys(); $subKeys2 = $key2->getSubKeys(); $subKeyA1 = $subKeys1[0]; $subKeyB1 = $subKeys1[1]; $subKeyA2 = $subKeys2[0]; $subKeyB2 = $subKeys2[1]; $this->assertEquals($userId1->getName(), $userId2->getName(), 'User id names do not match.'); $this->assertEquals($userId1->getEmail(), $userId2->getEmail(), 'User id email addresses do not match.'); $this->assertEquals($userId1->getComment(), $userId2->getComment(), 'User id comments do not match.'); $this->assertEquals($subKeyA1->getAlgorithm(), $subKeyA2->getAlgorithm(), 'Primary key algorithms do not match.'); $this->assertEquals($subKeyA1->getLength(), $subKeyA2->getLength(), 'Primary key lengths do not match.'); $this->assertEquals($subKeyA1->getExpirationDate(), $subKeyA2->getExpirationDate(), 'Primary key expiration dates do not match.'); $this->assertEquals($subKeyA1->canSign(), $subKeyA2->canSign(), 'Primary key signing abilities do not match.'); $this->assertEquals($subKeyA1->canEncrypt(), $subKeyA2->canEncrypt(), 'Primary key encrypting abilities do not match.'); $this->assertEquals($subKeyA1->hasPrivate(), $subKeyA2->hasPrivate(), 'Primary key private keys do not match.'); $this->assertEquals($subKeyB1->getAlgorithm(), $subKeyB2->getAlgorithm(), 'Secondary key algorithms do not match.'); $this->assertEquals($subKeyB1->getLength(), $subKeyB2->getLength(), 'Secondary key lengths do not match.'); $this->assertEquals($subKeyB1->getExpirationDate(), $subKeyB2->getExpirationDate(), 'Secondary key expiration dates do not match.'); $this->assertEquals($subKeyB1->canSign(), $subKeyB2->canSign(), 'Secondary key signing abilities do not match.'); $this->assertEquals($subKeyB1->canEncrypt(), $subKeyB2->canEncrypt(), 'Secondary key encrypting abilities do not match.'); $this->assertEquals($subKeyB1->hasPrivate(), $subKeyB2->hasPrivate(), 'Secondary key private keys do not match.'); }
/** * @group mutators */ public function testAddUserId() { $key = new Crypt_GPG_Key(); $userIds = $key->getUserIds(); $this->assertTrue(is_array($userIds), 'Failed to assert returned user ids is an array.'); $this->assertEquals(0, count($userIds), 'Failed to assert there are no user ids.'); // add first user id $firstUserId = new Crypt_GPG_UserId(array('name' => 'Alice', 'comment' => 'shipping', 'email' => '*****@*****.**')); $key->addUserId($firstUserId); $userIds = $key->getUserIds(); $this->assertTrue(is_array($userIds), 'Failed to assert returned user ids is an array.'); $this->assertEquals(1, count($userIds), 'Failed to assert number of returned user ids is the same as ' . 'the number of user ids added.'); $this->assertContainsOnly('Crypt_GPG_UserId', $userIds, false, 'Failed to assert all returned user ids are Crypt_GPG_UserId ' . 'objects.'); $this->assertArrayHasKey(0, $userIds); $this->assertEquals($userIds[0], $firstUserId, 'Failed to assert the first user id is the same as the first ' . 'added user id.'); // add second user id $secondUserId = new Crypt_GPG_UserId(array('name' => 'Bob', 'comment' => 'receiving', 'email' => '*****@*****.**')); $key->addUserId($secondUserId); $userIds = $key->getUserIds(); $this->assertTrue(is_array($userIds), 'Failed to assert returned user ids is an array.'); $this->assertEquals(2, count($userIds), 'Failed to assert number of returned user ids is the same as ' . 'the number of user ids added.'); $this->assertContainsOnly('Crypt_GPG_UserId', $userIds, false, 'Failed to assert all returned user ids are Crypt_GPG_UserId ' . 'objects.'); $this->assertArrayHasKey(0, $userIds); $this->assertEquals($userIds[0], $firstUserId, 'Failed to assert the first user id is the same as the first ' . 'added user id.'); $this->assertArrayHasKey(1, $userIds); $this->assertEquals($userIds[1], $secondUserId, 'Failed to assert the second user id is the same as the second ' . 'added user id.'); }