<?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
 * Key export tests for the Crypt_GPG package.
 *
 * These tests require the PHPUnit 3.2 package to be installed. PHPUnit is
 * installable using PEAR. See the
 * {@link http://www.phpunit.de/pocket_guide/3.2/en/installation.html manual}
 * for detailed installation instructions.
 *
 * To run these tests, use:
 * <code>
 * $ phpunit ExportPublicKeyTestCase
 * </code>
 *
 * LICENSE:
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of the
 * License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * @category  Encryption
 * @package   Crypt_GPG
 * @author    Michael Gauthier <mike@silverorange.com>
 * @copyright 2005-2008 silverorange
 * @license   http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
 * @version   CVS: $Id: ExportPublicKeyTestCase.php 302798 2010-08-26 13:19:11Z gauthierm $
 * @link      http://pear.php.net/package/Crypt_GPG
 */

/**
 * Base test case.
 */
require_once 'TestCase.php';

/**
 * Tests key export abilities of Crypt_GPG.
 *
 * @category  Encryption
 * @package   Crypt_GPG
 * @author    Michael Gauthier <mike@silverorange.com>
 * @copyright 2005-2008 silverorange
 * @license   http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
 * @link      http://pear.php.net/package/Crypt_GPG
 */
class ExportPublicKeyTestCase extends Crypt_GPG_TestCase
{
    // {{{ testExportPublicKey()

    /**
     * @group export
     */
    public function testExportPublicKey()
    {
        $keyId = 'public-only@example.com';

        // {{{ expected key data
        // Key block identifier and version identifier intentionally omitted
        // because they contain system-specific information, and causes tests
        // to fail on other systems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7eT608LFksytBHeOfNf5m7CC4wAE3RAz+ZkJvWRbE2
G5pUalZktq8uKMT5WQgvuFP3hnvku5yilpo2ELTnYkO3ltc3NHCc9v+jhikayPr7
RvUdVPbaITT80yYKBPygCwADBggApzR1vW/fvzmrO5pWzAvd4umVh/Yp34n3vWyX
Mu+JIHA7s08rkTzlMXzamICQmkjwAuCwJt0t7BA28Lnygoh2joxo8tE/OowFk+Iz
beA2Vrz71d/T5SMDtC2mePE0m3bmCOLBscu5aJIfgi1X/fzr44f4i+6hqVDCuOOm
nVtbL4xBBnS6KXdcWP7QbVhxG3SpH9Agd/QXvSQm0Obz9iKZ11FEXzgnVZGXaCM0
GBsFE9JuNY5+hi6A72rccjhC0V1Cy43veeIhOE+v3pK0a/BGUlgDSdgVopE9zUSQ
wzuo87UbY3EoDWBqDRSRCRMfmv8S2b9VJIRPdCOHZGCIR49/0YhJBBgRAgAJBQJI
0vjoAhsMAAoJEKuoHvVOjA3rNsAAoJU2elOyfOy9SCds+dBGjwH1H8+ZAKDCLYlj
KsfZIC+ySVrE2gkwQS9gkg==
=hSJS
-----END PGP PUBLIC KEY BLOCK-----

TEXT;
        // }}}

        $keyData = $this->gpg->exportPublicKey($keyId);

        // Check for containment rather than equality since the OpenPGP header
        // varies from system to system.
        $this->assertContains($expectedKeyData, $keyData);
    }

    // }}}
    // {{{ testExportPublicKeyNotFoundException()

    /**
     * @expectedException Crypt_GPG_KeyNotFoundException
     *
     * @group export
     */
    public function testExportPublicKeyNotFoundException()
    {
        $keyId = 'non-existent-key@example.com';
        $this->gpg->exportPublicKey($keyId);
    }

    // }}}
}

?>
